Re: itoa assembly version




Frank Kotler 写道:

"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!
I have set the dx to zero before divide operation. So "div bx" turn out
to be divide 0000:ax by bx. And I figure that will not cause any
"divide overflow"

And the code changed to:

assume cs:code,ds:data

data segment
dw 12, 23, 34, 45, 56, 12666
data ends
display segment
db '000000000000000', 0
display ends

stack segment
db '0000000000'
stack ends

code segment

start:

mov ax, data
mov es, ax
mov ax, display
mov ds, ax
call dtoc

mov si, 0
mov dh, 8
mov dl, 3
mov cl, 2
call show_str

mov ax,4c00h
int 21h
dtoc:
mov di, 0
mov cx, 6
s:
push cx
mov ax, es:[di]
mov bx, 0AH
s0: div bx
mov cx, ax
jcxz ok
add dl, 30h
mov byte ptr ds:[si], dl
mov dx, 0
inc si
jmp short s0

ok:add dl, 30h
mov byte ptr ds:[si], dl
inc si
add di, 2
mov dx, 0
pop cx
loop s
ret

I have debugged it in protected mode and found that
ds:0 contains 213243546566621 which is quite what I want, though in
reverse order, I could use stack to implement that. But the question is
when I run this program in real mode(because I want it to displayon
screen), I still experience "divide overflow", how this could be?

.



Relevant Pages

  • 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: Floating point exception
    ... mov eax,3 ... You need to convert this string og ascii characters to a number before you can do arithmetic on it (with the exception of the divide by ten "cheat" I mentioned). ... Get first/next character. ... Convert from ascii digit to number. ...
    (comp.lang.asm.x86)
  • Re: [PATCH] SLAB : use a multiply instead of a divide in obj_to_index()
    ... When some objects are allocated by one CPU but freed by another CPU we can ... divide took 1.20 % of CPU_CLK_UNHALTED events in kernel. ... mov %eax,// could be avoided ... if (flags & SLAB_CACHE_DMA) ...
    (Linux-Kernel)
  • Re: itoa assembly version
    ... mov byte ptr ds:, dl ... cmp ax, 0; or "test ax, ax" ... the cause of "Divide Overflow" ... zero at startup in an .exe, ...
    (alt.lang.asm)
  • Re: Floating point exception
    ... >mov edx,leninput;2;leninput ... This reads two characters from stdin and stores them at varinput, in ASCII. ... Now you take 12,337 and try to divide by 10. ... Now you can store ax into a string for printing. ...
    (comp.lang.asm.x86)