Re: itoa assembly version



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
.



Relevant Pages

  • Time,Date,and Chime TSR
    ... Clock display can be toggled on and off by repeating 'chime'. ... Turning the chime off and on ... mov CS:count500,TICKS; Reset Count500 ...
    (alt.lang.asm)
  • Re: Time,Date,and Chime TSR
    ... Clock display can be toggled on and off by repeating 'chime'. ... Turning the chime off and on ... mov CS:count500,TICKS; Reset Count500 ...
    (alt.lang.asm)
  • Re: VESA Modes
    ... able to view more of my code on the display. ... loader sets ds and es to your "PSP segment", ... At the beginning of vmode.asm, instead of "mov ax, cs", try "mov ax, data". ... I think you'll find this works without all the "+ OFFSET" cruft. ...
    (comp.lang.asm.x86)
  • Re: Display file name
    ... You appear to be trying to display the first FCB. ... mov bl,16h; for offset of T1 ... If you just type "myprog", you wn't have anything in the first FCB, so you won't see anything. ...
    (comp.lang.asm.x86)
  • Re: Popping Stack and then Displaying value
    ... How can I display what is in AX, after the instruction "add ax,bx"? ... You can use Int 10h AH.9 to write an ascii character and its attribute ... mov ax,cx ... ;;outer loop for 16 lines. ...
    (comp.lang.asm.x86)