I have been trying to write this converter. I have already
written one for 16 bit values in a distant past. But now I
am having trouble writing one for 32 bit values. I use
MASM 6.11 in a DOSbox under Win95.
At the end of the program I expect the return value in
dx:ax to be FFFF:FFFF. But the code returns FFFF:FFFD.
What happened to those two bytes? The Art of Assembly book
did not answer my question either. Any help would be
great.
I know this ain't the fastest code on earth, so any
optimization suggestions would also be more than welcome!
thx.
written one for 16 bit values in a distant past. But now I
am having trouble writing one for 32 bit values. I use
MASM 6.11 in a DOSbox under Win95.
At the end of the program I expect the return value in
dx:ax to be FFFF:FFFF. But the code returns FFFF:FFFD.
What happened to those two bytes? The Art of Assembly book
did not answer my question either. Any help would be
great.
I know this ain't the fastest code on earth, so any
optimization suggestions would also be more than welcome!
thx.
Code:
org 100h ;.com format.
main proc near
lea si,long+9
call convert
int 20h
main endp
long byte '4294967295' ;0FFFFFFFFh
power10 dword 1,10,100,1000,10000,100000,1000000, \
10000000,100000000,1000000000
; Convert assumes end of buffer in si.
; It outputs the numeric value in dx:ax and si points at
; si - length(ASCIInumber) - 1.
convert proc near
push bx
push cx
std
xor bx,bx
push bx
push bx
mov bp,sp ;use this dword for temporary storage.
lp0:
xor ax,ax
lodsb
cmp al,30h
jb endproc
cmp al,39h
ja endproc
sub al,30h ;character is numeric ASCII.
mov cx,ax ;save value.
mul word ptr power10[bx]
add [bp],ax
mov ax,cx ;restore value.
mov cx,dx ;save H.O. word.
mul word ptr power10[bx+2]
add ax,cx ;add in saved H.O. word.
add [bp+2],ax
add bx,4 ;increment power10 offset.
cmp bx,sizeof power10
jnz lp0
dec si ;si = offset(ASCIInum) - 2
endproc:
pop dx
pop ax
pop cx
pop bx
ret
convert endp
cseg ends
end main