Division Using Shift In Assembly Language

1.1k Views Asked by At

I am new to assembly programming and I have a question.

I learned that LSL is faster than MUL instruction and we can use the LSL for multiplication by 2 and LSR for division by 2. Moreover, in the multiplication case, we can do some tricks such as the multiplication by 3 using shift and add

mov r0,#2  
mov r1,r0    ; saving a copy of r0 for adding later
lsl r0,#1    ; multiplying r0 with 2 by shifting left 1 bit
add r0,r1    ; adding the originial r0 to get the multiplication-by-3 result

Is there a similar method for division? for example, if I have the number 9 and I want to divide it by 3, what operations could be done for such a case.

0

There are 0 best solutions below