T
T
Timebird2017-01-09 17:09:35
Programming
Timebird, 2017-01-09 17:09:35

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 divand/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

3 answer(s)
S
sitev_ru, 2017-01-09
@sitev_ru

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

PS This is for x86

M
Mercury13, 2017-01-09
@Mercury13

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...

A
Andrew, 2017-01-09
@OLS

Do you feel sorry for the processor cycles for such a division algorithm?
The number of iterations should not exceed the capacity of the dividend - this is in the worst case (dividing by 2).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question