How do I print an integer in Assembly Level Programming without printf from the c library?

后端 未结 5 1426
予麋鹿
予麋鹿 2020-11-22 00:07

Can anyone tell me the purely assembly code for displaying the value in a register in decimal format? Please don\'t suggest using the printf hack and then compile w

5条回答
  •  遥遥无期
    2020-11-22 00:38

    Can't comment so I post reply this way. @Ira Baxter, perfect answer I just want to add that you don't need to divide 10 times as you posted that you set register cx to value 10. Just divide number in ax until "ax==0"

    loop1: call dividebyten
           ...
           cmp ax,0
           jnz loop1
    

    You also have to store how many digits was there in original number.

           mov cx,0
    loop1: call dividebyten
           inc cx
    

    Anyway you Ira Baxter helped me there is just few ways how to optimize code :)

    This is not only about optimization but also formatting. When you want to print number 54 you want print 54 not 0000000054 :)

提交回复
热议问题