Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Theory Division using shift Use the assembly language (masm615) Two numbers A (a

ID: 3812217 • Letter: T

Question

Theory

Division using shift

Use the assembly language (masm615)

Two numbers A (an an-1 ... a2 a1 a0) and B (bn bn-1 ... b2 b1 b0). The division of A/B yields a quotient Q (bn qn-1 ... q2 q1 q0) and a remainder R that can be calculated by a series of shifts and subtractions.  

Algorithm:(note: << represents logic shift to left)

Initialize i = n, Q = 0, Y = 0

Y = (Y << 1) + ai

If Y >= B then:  
{Q = Q + 1,
Y = Y - B}

i = i - 1

If i > 0 then goto 2

R = Y

Assignment

Your assignment will be to implement division suing shift instruction and conditional instructions and separately signed division.

Make sure your code works for 0's as arguments.

Explanation / Answer

Please find below for implementation of given logic

mov i,n
mov q,0
mov y,0

SHR y,1
ADD y,ai

L1:
ADD q,1
SHL y,b
cmp y,b
JGE L1

SHL i,1

L2:
mov r,y
cmp i,0
JGE L2