Re: itoa assembly version
- From: Frank Kotler <fbkotler@xxxxxxxxxxx>
- Date: Mon, 29 May 2006 12:01:13 -0400
Liys wrote:
....
.... But the problem that I experience is that I got a "Divide overflow" with 12 / 10(ax/bx).
"div bx" divides dx:ax by bx, not just ax. If the result won't fit in ax, which it won't if dx>=bx, it causes an exception.
Most common newbie error in existance!
// convert the data in 'data' seg into ASCII and store it in 'display' seg.
assume cs:code,ds:data
data segment
dw 123, 12666, 1, 8, 3, 38
data ends
display segment
db '0000000000000', 0
display ends
code segment
start:
mov ax, data
mov es, ax
mov ax, display
mov ds, ax
call itoa
mov ax,4c00h
int 21h
itoa:
mov cx, 6
s:
mov si, 0
mov di, 0
mov ax, es:[di]
mov bx, 0AH
s0:
xor dx, dx
div bx // cause 'Divide overflow' with 0c/0a
mov cx, ax
jcxz ok
Isn't this going to interfere with your "loop"?
add dl, 30h
mov byte ptr ds:[si], dl
inc si
Since the remainders are your digits, but in the "wrong" order, you might want to start with si at the "end" of the buffer and "dec" it here.
jmp short s0
add di, 2
When does this get executed?
ok:add dl, 30h
mov byte ptr ds:[si], dl
loop s
ret
code ends
end start
This doesn't quite implement any "itoa" that I've ever seen, but you're on the right track. You probably want to process *one* number per call to "itoa", and loop through the six numbers (and probably display each one) in your main routine, no?
Best,
Frank
.
- Follow-Ups:
- Re: itoa assembly version
- From: leon800219
- Re: itoa assembly version
- Prev by Date: Re: questions from a newbie
- Next by Date: Re: questions from a newbie
- Previous by thread: NASM
- Next by thread: Re: itoa assembly version
- Index(es):
Relevant Pages
|