flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Tomasz Grysztar 07 Aug 2018, 16:02
DIV instruction only takes one argument (which specifies a divisor, not a dividend) because the value to divide is always taken from the same place - EDX:EAX pair of registers.
32-bit DIV divides 64-bit value in EDX:EAX (EDX is the high part) by the divisor given by its operand. This is a division with remainder and thus has two results. The quotient is put into EAX and remainder is put into EDX. I suspect that remainder is exactly what you need as a result for the "mod" macro. This could then look like: Code: macro mod a, b { mov eax,a cdq div b mov a,edx } Code: macro mod a, b { if ~ eax eq a mov eax,a end if cdq div b if ~ edx eq a mov a,edx end if } |
|||
![]() |
|
Mino 07 Aug 2018, 16:33
I understand better now, and you gave more than I asked, thank you very much
![]() But why does div act this way, and not like other operators? To manage operations such as modulo for example? |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.