32 bit binary to ASCII 8086 assembly
I need to convert 32-bit number to ASCII. I don't know how I can do it ....
This is the code what I wrote : The biggest number that could convert is 0001FFFF , if I set Dx to 000F and Ax to FFFF the assembler will give me a divide overflow error !!!
data segment
save db 10 d开发者_开发技巧up(' ') , '$' ; the ASCII will save here
data ends
stack segment
dw 128 dup(0)
stack ends
code segment
assume cs:code , ds:data , ss:stack
main proc far
mov ax, data
mov ds, ax
mov es, ax
mov di,offset save
add di , 9
mov ax,0ffffh
mov dx,0001h
mov cx,10 ; dx ax will divide by cx
convert:
div cx
add dl,'0'
mov [di],dl
dec di
mov dx,0
cmp ax,cx
jge convert
add al,'0'
mov [di] , al
;show the number
mov ah,09h
mov dx,offset save
int 21h
; wait for any key....
mov ah, 1
int 21h
mov ax, 4c00h ; exit to operating system.
int 21h
main endp
code ends
end main
what should i do?
thanks in advance
Hehe that's an easy one :P
I believe you might be getting a 'Divide Error' but not specifically a 'Devide by ZERO error'
You say that you get an error when DX=0xF right?
Well 0x000FFFFF = 1048575 ... divide this by 10 you get >65535 ... The answer: you simply get a divide overflow. The result needs to fit within AX.
I'd say you'd put out a CR (015), an LF (012) and take the exit to BIOS.
Who'da thunk we'd ever see int 21 again?
精彩评论