unsigned long -> ascii conversion
From: alex (me_at_me.com)
Date: 09/18/04
- Next message: Rong: "A basic question on asm"
- Previous message: Bad Maniac: "Packed mul of floating point values in 8087?"
- Next in thread: Chewy509: "Re: unsigned long -> ascii conversion"
- Reply: Chewy509: "Re: unsigned long -> ascii conversion"
- Reply: Matt: "Re: unsigned long -> ascii conversion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 18 Sep 2004 05:47:38 +0000 (UTC)
Hi Guys,
I have written a function that will convert a number in the EAX register
into a hex value in ascii, I found this very easy.. by and'ing (and eax,0fh)
each bit and using
it as an offset into a table containing '0123456789abcdef'.. this code seems
to work fine.
but the same trick wont work if i want to convert an unsigned number in EAX
to
its decimal form in ascii, obviously because hex and decimal are differently
based numbering systems..
whats the approach for unsigned number -> ascii?
below is some quick code i whacked together in about 5 mins under DOS
(i know its disorganised), perhaps someone
could see where I need to modify the code to get it to work
this is the hexadecimal -> ascii code
org 0x0100
[bits 16]
start:
mov edi,padspace
mov eax,7830h ;ASCII char for '0x'
stosw
mov eax,0x200000 ;the actual number we're going to convert
ror eax,28 ;start from the msb of 32 bit number (will
end up in al)
mov ecx,0008h ;processing 4 bits at a time, so 8 loops for the
full 32bit
cvl: push eax
mov esi,numset
and eax,000fh
add esi,eax
lodsb
stosb
pop eax
rol eax,0004h
loopnz cvl
mov esi,padspace
call writestring
mov eax,4c00h ;bail
int 21h
writestring:
mov ax,0e00h
mov bx,0007h
sloop:
lodsb
cmp al,0000h
je finished
int 10h
jmp sloop
finished:
ret
numset db '0123456789ABCDEF000'
padspace times 0x200 db 0
- Next message: Rong: "A basic question on asm"
- Previous message: Bad Maniac: "Packed mul of floating point values in 8087?"
- Next in thread: Chewy509: "Re: unsigned long -> ascii conversion"
- Reply: Chewy509: "Re: unsigned long -> ascii conversion"
- Reply: Matt: "Re: unsigned long -> ascii conversion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|