You are on page 1of 6

Lab Assignment (3)

Gaurav Kumar

19075031

CSE(B.Tech.)

A)Multiplication of Two 8-Bit Numbers by Bit Rotation


Method

Code:

;<Multiplication of Two 8-Bit Numbers by Bit Rotation Method>

jmp start

;data
;Example Multiply two numbers 25 and 26
;Multiplicand is 25 and multiplier is 26
;25*26 = 650
;code

start: nop
LHLD 1000H ;Get Multiplicand in H-L pair. 25 in L[1000] and 00 in H[1001] register
XCHG ;it exchanges the content of H and L register with D and E registers.
LDA 1002H ;Get Multiplier in accumulator i.e A = 26
LXI H,0000H ;Initial product in HL = 0000
MVI C,08H ;Count=08 in register C
up: DAD H ;it adds the content of H and L register to itself
RAL ;Rotate multiplier(Accumulator) to left by 1 bit.
jnc down ;if no carry then jump
DAD D ;Product = Product + Multiplicand
down: DCR C ;Decrement Count
JNZ up ;Jump until C=0
SHLD 1003H ;It copies the data from H and L.L goes to 1003h and H goes to 1004h
hlt ;Terminate Program Execution

Input and Output:

Lab Assignment (3) 1


Multiplicand = 0*256(stored at 1001h) + 25(stored at 1000h)
Multiplier = 26 (stored at 1002h)

Product = 2*256(stored at 1004h) + 138(stored at 1003h) = 650

Screenshots:

Lab Assignment (3) 2


B) Division of Two 8-Bit Numbers by Repeated
Subtraction Method

Code:

Lab Assignment (3) 3


;<Division of Two 8-Bit Numbers by Repeated Subtraction Method.>

jmp start

;data
;Example Divide 10 by 3
;code
start: nop

LDA 1000H ;[1000]=>A (Divisor) i.e 3 here


MOV B,A ;Take divisor in register B i.e B = 3
LDA 1001H ;Take dividend in register A i.e A = 10
MVI C,00H ;initialize quotient = 0 i.e C = 0
CMP B ;Compare A to B here 10 > 3 therefore CY and zero flag are reset
JC down ;Jump if carry
up: SUB B ;Dividend - divisor => A
INR C ;C = C + 1 i.e increase quotient
CMP B ;Is dividend < divisor
JNC up ;If not,go back i.e loop runs till dividend > divisor
down: STA 1002H ;Store Remainder i.e the value in A here it is 1
MOV A,C ;C=>A Quotient Value is copied to Accumulator
STA 1003H ;Store Quotient(i.e value at A) at 1003
hlt ;terminate program execution

Input and Output:

Divisor = 3 (1000h → 3)
Dividend = 10 (1001h → 10)

Remainder = 10%3 = 1 (1002h → 1)

Quotient = 10/3 = 3 (1003h → 3)

Screenshots:

Lab Assignment (3) 4


Lab Assignment (3) 5
Lab Assignment (3) 6

You might also like