cppbert3 schrieb:> this couldn't be in the result, in any way> 0x21436587 / 0x10 = quot=ax=0x2 rem=dx=1
Typo, thanks.
1
0x21436587 / 0x10 = quot=ah=0x2 rem=dx=1
cppbert3 schrieb:> its absolutely not clear "what" doesn't work, the div and mul operationa> are working as documented
It just stops working (no output at all).
And what's the use of that stuff when I have to multiply first with the
number I divide with right after? Confusion -> Inf
Btw: dosbox got an builtin debugger (not in the default release) so you
dont need to print your results, just watch the registers change, step
by step
https://www.vogons.org/viewtopic.php?f=32&t=7323
Booter schrieb:> Typo, thanks.0x21436587 / 0x10 = quot=ah=0x2 rem=dx=1
What do you think is the correct result? Tip: its much much larger than
0x2 :)
Booter schrieb:> It just stops working (no output at all).
Because your registers are absolutely not in the value range you expect
Booter schrieb:> And what's the use of that stuff when I have to multiply first with the> number I divide with right after? Confusion -> Inf
Its just an small example how mul,div works - nothing more
Your dx:ax understanding is not correct, you whole "algorithm" seems to
be crippled, partly in code and your comments, also your al,ah usage
before int 0x10
Beside assembler code, what are you try to archive with this code block?
cppbert3 schrieb:> Beside assembler code, what are you try to archive with this code block?
Actually it's a bug in my version of U/ ( ud u1 --- rem quot ) from the
fig-FORTH Model
s is data stack, pop adds two to s and jumps to next
The nice thing about assembler is that you can easily work around such
incapabilities by using various methods. A division by 10h is nothing
more than a 4-bit shift to the right (even if it might be slower on
modern CPUs when you need to use more instructions), a division by 100h
can easily be done by splitting registers (AX into AH and AL as AH
contais already the result and AL the reminder without actually
executing the division).
And if your processor is 32 bit (not 16 only) use it.
Booter schrieb:> What got I wrong about unsigned division in 8086 assembler?> Why it work only for dividend high part equal zero?
Nothing. This is just the way to do it. For some "deeper" look of view
you have to ask Intel-Developers why you have to set dx explicitly to
0.
You don't have to set DX to zero, you have to set it low enough, that
the result of the division (by 16) fits in AX.
That's why I suggested to execute this DIV operation by bitshifting or
as 32 bit operation if the processor is able to.
Ben B. schrieb:> You don't have to set DX to zero, you have to set it low enough, that> the result of the division (by 16) fits in AX.
Are you Intel-Developer? But you are right. It could be sufficient, to
set dh to 0 - but some more testing and gaming with numbers will give
some more safety about this case ;)
rbx schrieb:> Ben B. schrieb:> You don't have to set DX to zero, you have to set it low enough, that> the result of the division (by 16) fits in AX.>> Are you Intel-Developer? But you are right. It could be sufficient, to> set dh to 0 - but some more testing and gaming with numbers will give> some more safety about this case ;)
Its fully and overly well documented for at least 40 years now,
absolutely no need to talk to intel developers or gaming with numbers
There is no gaming. As a DIV by 10h is nothing more than a 4-bit shift
and the maximum result to fit in AX is 0xFFFFh, the maximum number you
can divide is 0xFFFFF, or DX:AX 0x000F:0xFFFF - will give you AX 0xFFFF
as result and DX 0x000F as reminder. DX bigger than 0x000F will result
in the error described.
If you need more you can perform this operation as 32-bit operation or
you need to work around the problem as I described before.
> mov ax, 0x2143 ; dividend low> mov dx, 0x6587 ; dividend high> mov cx, 0x10 ; divisior> div cx
MOV EAX,0x65872143
XOR EDX,EDX
MOV ECX,0x10
DIV ECX ; result in EAX, reminder in EDX