Re: itoa assembly version




Frank Kotler wrote:
leon800219@xxxxxxxxx wrote:
Frank Kotler wrote:

The only thing I see (without testing it) is that you zero dx at the
*end* of your loop. What's dx on the *first* iteration? Possibly
different in "protected mode" - I assume you mean v86 mode - and real
mode? That's what first comes to mind... try moving it and see if it helps.

By *end* of your loop do you mean:
mov byte ptr ds:[si], dl
mov dx, 0

Yep. Try it like:

s0: mov dx, 0 ; or "xor dx, dx"
div bx
mov cx, ax
cmp ax, 0 ; or "test ax, ax"
jz ok
add dl, 30h
mov byte ptr ds:[si], dl
inc si
jmp short s0
...

Actually, you probably want to check for "done" after you process the
last digit instead of before:

s0: mov dx, 0 ; or "xor dx, dx"
div bx
mov cx, ax
add dl, 30h
mov byte ptr ds:[si], dl
cmp ax, 0 ; or "test ax, ax"
jz ok
inc si
jmp short s0
...

Even better, if you do it "dead last"...

...
mov byte ptr ds:[si], dl
inc si
cmp ax, 0 ; or "test ax, ax"
jnz s0
ok: add di, 2
loop s

(since we no longer trash cx, we can eliminate the push/pop - both
please! - of cx)

That way, you won't have to duplicate the "add dl, 30h", etc. at the
"ok:" label to catch the last digit...

At the *first* iteration the dl holds the remainders.

Yeah, *after* the "div". What's dx *before* the div?

If that was
removed the divide operation will be dx:ax/bx again, I believe that's
the cause of "Divide Overflow"
If that's what you mean. But I really curious what make the program
"Divide Overflow" again?

The "div" operation is always dx:ax - the number we *want* to divide is
in ax - we need to make sure dx is zero, or we'll get false results even
if it doesn't overflow.

By rmode I mean the real DOS, and by pmode I mean WinXP

Okay. Even real dos is in v86 mode if you've got "emm386.sys" or
something similar running. That really isn't the issue. I forget what
the "usual" state of dx is on program startup. (hell, this'll only take
a minute - be right back)

Mmmm, didn't really find anything definite - according to DEBUG, dx is
zero at startup in an .exe, but not in a .com... I haven't got XP to
check it. That's the only thing I can think of that would cause a divide
overflow exception - except actually dividing by zero, which you're not
doing...

What's the advantage of moving ax to cx and then testing cx for zero,
compared to just testing ax for zero?

" jcxz ok" was also a guard against the last bit of a digit, I wish I
could compare ax against zero but I haven't learn it yet.

Ah. Very complicated:

cmp ax, 0
jz ok ; "je" is the same instruction

That's not how I'd actually do it - "cmp ax, 0" takes two bytes to store
the zero - "test ax, ax" performs a "notional and" - sets flags as if
"and" had been executed, but doesn't store the result anywhere. ("cmp"
is a "notional subtract" - sets flags, but doesn't store the result).
Either of them will set the zero-flag if ax is zero (indicating we're done).

Well, you're closing in on it. As Betov says - one time I do agree with
him - "Courage!"

Well, Thanks a lot, encouragement is really what I needed.

Yeah, there are some really frustrating issues - even worse is when you
can't get the damn thing to assemble at all! But after a while, it gets
better... or you get used to it...

Best,
Frank


So the whole point is that I have to set the dx to zero before divide
operation. dx might have some initial value after 's0', that might
cause some problem? But what about the next execution, it also set by
initial value? In my original implementation the dx just set to zero in
each loop before program reaches to 's0'. isn't it right?


Ah. Very complicated:
Sorry about that.

.



Relevant Pages

  • Re: which book to start with...?
    ... mov eax, 4 ... just installed nasm 16 bit and 32 bit bins under dosemu. ... .bss wont accept initialisations while .data will but no garantee for modification at runtime. ... Section .bss is nominally "uninitialized" data, but is in fact cleard to zero. ...
    (alt.lang.asm)
  • Re: which book to start with...?
    ... mov eax, 4 ... buffer resb 1000h ... Section .bss is nominally "uninitialized" data, but is in fact cleard to zero. ... i used nasm's one because intel's manuals are too big and detailed for me yet:) also i hate pdf files... ...
    (alt.lang.asm)
  • Re: which way is more efficient to check bit value
    ... and 128 (the offset zero is if the original number was zero). ... low order 4 bits of the 8-bit value; if it's the high order you ... xor eax, eax ... mov bl, ...
    (microsoft.public.vc.language)
  • Re: itoa assembly version
    ... mov byte ptr ds:, dl ... cmp ax, 0; or "test ax, ax" ... Mmmm, didn't really find anything definite - according to DEBUG, dx is zero at startup in an .exe, but not in a .com... ...
    (alt.lang.asm)
  • Re: Newbie to Forums, SIMD question
    ... Both of these converse most rapidly when x is near zero. ... mov ebx,ecx ... So far we've ignored zeros, denormals, infinities and NaNs. ... infinity or NaN, nor will it work for a negative x. ...
    (comp.lang.asm.x86)