I am looking for some code to print what's in EAX to a decimal number. Thanks.

**e**ax and 16-bit? Doesn't seem a logical combination :) You could convert a 32-bit proc yourself or search the web, there are many tutorials for 16-bit assembler so you can probably find an word2ascii too.

Thomas

Andrew,

What you need is the dwtoa function from the masm32 library.

You can check the example:

http://www.asmcommunity.net/board/showthread.php?s=&postid=84313&highlight=dwtoa.msg84313

Regards,

Vortex

What you need is the dwtoa function from the masm32 library.

You can check the example:

http://www.asmcommunity.net/board/showthread.php?s=&postid=84313&highlight=dwtoa.msg84313

Regards,

Vortex

**e**ax and 16-bit? Doesn't seem a logical combination :) You could convert a 32-bit proc yourself or search the web, there are many tutorials for 16-bit assembler so you can probably find an word2ascii too.

Thomas

Here is the code I found, it will convert any number into it's decimal, hex, or binary equivalent.

; eax2dec.asm Convert the value in eax into decimal, hexadecimal, and binary

; values

.model tiny

.386

.code

org 100h

begin:

mov eax, 1234567890 ; 1,234,567,890

call eax2dec

call newline

call eax2hex

call newline

call eax2bin

mov ah, 4Ch

int 21h

eax2dec:

push eax

push ebx

push cx

push edx

mov ebx, 10 ; divide by ten

xor cx, cx ; zero our counter

push_digit:

xor edx, edx ; clear dx for the div - use cwd and

div ebx ; idiv for signed numbers

push dx ; save remainder

inc cx ; bump digit counter

or eax, eax ; is quotient zero?

jnz push_digit ; no, do more

mov ah, 2 ; print character subfunction

pop_digit:

pop dx ; get remainder back

add dl, '0' ; convert to ascii character

int 21h ; print it

loop pop_digit ; cx times

pop edx

pop cx

pop ebx

pop eax

ret

eax2hex:

push cx

push dx

mov cx, 8 ; eight digits to show

top:

rol eax, 4 ; rotate one digit into position

mov dl, al ; make a copy to process

and dl, 0Fh ; mask off a single (hex) digit

cmp dl, 9 ; is it in the 'A' to 'F' range?

jbe dec_dig ; no, skip it

add dl, 7 ; adjust

dec_dig:

add dl, 30h ; convert to character

push ax

mov ah, 2 ; print the character

int 21h

pop ax

loop top

pop dx

pop cx

ret

eax2bin:

push cx

push dx

mov cx, 32 ; 32 binary digits

top1:

rcl eax, 1 ; rotate and set/clear carry

mov dl, '0'

adc dl, 0 ; make it '1' if carry set

push ax

mov ah, 2 ; print it

int 21h

pop ax

loop top1

pop dx

pop cx

ret

newline:

push ax

push dx

mov ah, 2 ; print character in dl

mov dl, 13 ; carriage return

int 21h

mov dl, 10 ; and linefeed

int 21h

pop dx

pop ax

ret

end begin