[Code-Crunchers] Unsigned Integer Printing (16bit)
Arkon
arkon at ragestorm.net
Thu Nov 2 14:30:56 CST 2006
Hey people,
I was playing with DOS.don't ask my why. :-)
Anyways, I thought it might interest some of you to see this recursion for
converting AX into decimal number and print it.
It's 16 bits, but it can easily be ported into 32bits (and then to dump it
into a buffer).
And as a matter of fact, it even handles AX=0 as an input easily.
mov ax, 1234
call print_int
ret
print_int:
mov bx, 10
xor dx, dx
div bx
push dx
test ax, ax
jz .con
call print_int
.con:
pop ax
add al, '0'
int 0x29
ret
Oh BTW - making it printing signed integers is a matter of flags test of AX
and JNS-NEG combination... though you have to print minus char.
Gil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://whitestar.linuxbox.org/pipermail/code-crunchers/attachments/20061102/3bbec5ab/attachment.htm
More information about the Code-Crunchers
mailing list