flat assembler
Message board for the users of flat assembler.
Index
> Main > how DIV works? Goto page 1, 2 Next |
Author |
|
revolution 19 Feb 2010, 17:57
Do the division twice:
Code: ;edi=high 32 bits ;esi=low 32 bits ;ecx=divisor mov edx,0 mov eax,edi div ecx mov edi,eax ;update high order quotient mov eax,esi div ecx mov esi,eax ;update low order quotient ;edx=remainder |
|||
19 Feb 2010, 17:57 |
|
r22 20 Feb 2010, 05:48
Just for fun Binary Coded Decimal
Code: fild qword[int_somebignumber] ; 56bit between 0x0 and 0xFFFFFFFFFFFFFF fbstp [lbl_bcd] ; 10bytes ALMOST useful ... |
|||
20 Feb 2010, 05:48 |
|
DOS386 22 Feb 2010, 08:35
> trying to implement a hex to dec function
More likely a 64-bit dec out function, no HEX at all > Do the division twice: FASM IDE's contain a COOL CALCULATOR using this code PS @re: I'll answer the other one later |
|||
22 Feb 2010, 08:35 |
|
Tomasz Grysztar 22 Feb 2010, 08:52
revolution wrote: Do the division twice: Rather than "mov eax,esi" you should do Code: mov eax,edx add eax,esi |
|||
22 Feb 2010, 08:52 |
|
edemko 22 Feb 2010, 09:06
How can divide a dqword(128bit) by a dword?
|
|||
22 Feb 2010, 09:06 |
|
Tomasz Grysztar 22 Feb 2010, 09:15
serfasm wrote: How can divide a dqword(128bit) by a dword? |
|||
22 Feb 2010, 09:15 |
|
revolution 22 Feb 2010, 09:20
Tomasz Grysztar wrote: Rather than "mov eax,esi" you should do |
|||
22 Feb 2010, 09:20 |
|
edemko 22 Feb 2010, 10:07
true as a remainder(edx) could be 1 and the low 32 bits(esi) could be -1
|
|||
22 Feb 2010, 10:07 |
|
Tomasz Grysztar 22 Feb 2010, 10:10
revolution wrote:
Oh, sorry, I meant it should stay in EDX. Stupid mistake. |
|||
22 Feb 2010, 10:10 |
|
revolution 22 Feb 2010, 10:13
serfasm wrote: true as a remainder(edx) could be 1 and the low 32 bits(esi) could be -1 I think the original code I posted above is correct. |
|||
22 Feb 2010, 10:13 |
|
Tomasz Grysztar 22 Feb 2010, 10:14
revolution wrote: I think the original code I posted above is correct. |
|||
22 Feb 2010, 10:14 |
|
revolution 22 Feb 2010, 10:19
serfasm wrote: How can divide a dqword(128bit) by a dword? Code: ;edi=highest part of dqword ;ebp=2nd highest ;ebx=3rd highest ;esi=lowest part of dqword ;ecx=divisor mov edx,0 ;previous remainder is zero mov eax,edi div ecx mov edi,eax ;highest mov eax,ebp div ecx mov ebp,eax ;2nd highest mov eax,ebx div ecx mov ebx,eax ;3rd highest mov eax,esi div ecx mov esi,eax ;lowest ;edx=remainder |
|||
22 Feb 2010, 10:19 |
|
edemko 22 Feb 2010, 10:20
adding big remainder(edx) of a high ordered dividend(edi) to eax=esi
we, even expanding result to 64 bits, can get integer overflow on the next DIV iteration |
|||
22 Feb 2010, 10:20 |
|
edemko 22 Feb 2010, 10:21
oops, my post is old, i'll continue from yours, revolution
|
|||
22 Feb 2010, 10:21 |
|
edemko 22 Feb 2010, 10:28
It looks easy enough. But returning to decimal system to understand better
i must say about borrowing from the higher ranks but you do not. Argue with you tomorrow: must go home, bye. Last edited by edemko on 22 Feb 2010, 10:33; edited 1 time in total |
|||
22 Feb 2010, 10:28 |
|
revolution 22 Feb 2010, 10:32
You run the code in a loop. At at iteration edx is the LSD which you should store somewhere (push edx), and later recall in reverse order (pop reg) to print the digits.
|
|||
22 Feb 2010, 10:32 |
|
zhak 22 Feb 2010, 10:33
i didn't try dqword conversion, yet, but the idea that revolution suggested in his first post works correctly. i just modified the algo to do "double division" only when needed (if div overflow error will occur)
|
|||
22 Feb 2010, 10:33 |
|
edemko 22 Feb 2010, 10:34
What is an LSD.
Sorry, i've found the borrow mechanism of you out. Still, can an overflow happen? Last edited by edemko on 22 Feb 2010, 10:38; edited 1 time in total |
|||
22 Feb 2010, 10:34 |
|
zhak 22 Feb 2010, 10:35
least significant digit, i suppose
Last edited by zhak on 22 Feb 2010, 10:37; edited 1 time in total |
|||
22 Feb 2010, 10:35 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.