Answer the question
In order to leave comments, you need to log in
How to divide two numbers in Assembler using a loop?
It is necessary, for example, to divide the number 154 by 3. How to do this using a loop? I understood the idea: we need to subtract from the number by 3 until we reach zero and, accordingly, write the remainder into one variable, the number of iterations of such subtractions into another. But how to do it without the help of operations div
and/or idiv
? For some reason, the AVR Studio compiler does not recognize them.
Answer the question
In order to leave comments, you need to log in
Apparently something like this ... sketched, but did not check ... test, pliz ...
mov eax, 154
mov ecx, 0
loop1:
inc ecx
sub eax, 3
jb loop1
I would like to clarify.
1. Dimensions of the dividend and divisor.
2. Signed or unsigned?
3. Do I need a balance?
4. Do we divide by a constant or by something unknown in advance?
Here, for example, divide a 16-bit unsigned by an arbitrary 8-bit unsigned, as I understand it, without a remainder.
www.avr-asm-tutorial.net/avr_en/calc/DIV8E.html
This is how division by a constant (6 in this case) works.
stackoverflow.com/questions/34136339/how-does-divi...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question