cpmajai
November 11th, 2008, 04:09 AM
Hi everyone!
gonna be honest and say that this is a homework assignment. I am trying to convert a 4 byte packed decimal integer into a string of ASCII decimal digits.
in my code below, i am trying to convert "1999" to ASCII decimals which would be 31393939. so far my output only displays 3939. maybe there is something up with my loop count or....i don't know...i'm stuck
please make any comments or suggestions, but keep the flaming and criticism to yourselves....or sensored.
.data
decimal_one BYTE "1999" ;
decimal_two BYTE "9004" ;
ascii_conv BYTE ?
.code
main PROC
; Starting at the last digit position.
mov esi,SIZEOF decimal_one - 1
mov edi,SIZEOF decimal_one
mov ecx,SIZEOF decimal_one
L1: mov al,0 ;
mov al,[decimal_one+edi] ;
mov ah,al ;
and al,0fh ;
or al, 30h ;
mov [ascii_conv+esi],al ;
dec esi
mov al,ah ;
shr al,4
or al,30h ;
mov [ascii_conv+esi],al
dec esi
dec edi
loop L1
mov edx,OFFSET ascii_conv
call WriteString
call Crlf
exit
main ENDP
gonna be honest and say that this is a homework assignment. I am trying to convert a 4 byte packed decimal integer into a string of ASCII decimal digits.
in my code below, i am trying to convert "1999" to ASCII decimals which would be 31393939. so far my output only displays 3939. maybe there is something up with my loop count or....i don't know...i'm stuck
please make any comments or suggestions, but keep the flaming and criticism to yourselves....or sensored.
.data
decimal_one BYTE "1999" ;
decimal_two BYTE "9004" ;
ascii_conv BYTE ?
.code
main PROC
; Starting at the last digit position.
mov esi,SIZEOF decimal_one - 1
mov edi,SIZEOF decimal_one
mov ecx,SIZEOF decimal_one
L1: mov al,0 ;
mov al,[decimal_one+edi] ;
mov ah,al ;
and al,0fh ;
or al, 30h ;
mov [ascii_conv+esi],al ;
dec esi
mov al,ah ;
shr al,4
or al,30h ;
mov [ascii_conv+esi],al
dec esi
dec edi
loop L1
mov edx,OFFSET ascii_conv
call WriteString
call Crlf
exit
main ENDP