You are on page 1of 7

Lab Assignment (3)

Abhinav Gupta
19074001
CSE(IDD)

A)Multiplication of Two 8-Bit Numbers by Bit Rotation Method Code:

Code:

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


jmp start
;data
;Example :- Multiply two numbers 13 and 14
;code

start: nop
LHLD 2500H ;Stores 13 at 2500h in L register and 00 and 2501h in H register
XCHG ;Exchanges the content of H and L register pair with D and E register pair
LDA 2502H ;Load second number in accumulator i.e A = 14
LXI H,0000H ;Initial product in HL = 00
MVI C,08H ;Count=08 in register C
up: DAD H ;adds the content of H and L register to itself
RAL ;Rotate Accumulator to left by 1 bit.
jnc down ;if case of no carry then jump
DAD D ;stores product by adding H and L register with D and E registers
down: DCR C ;Decrement Count
JNZ up ;Jump until C=0
SHLD 2503H
;2503h and 2504h address will hold the solution
;It copies the data from H and L
;L goes to 2503h and H goes to 2504h
hlt ;Terminate Program Execution

Input and Output:


Multiplicand = 0*256(stored at 2501h) + 13(stored at 2500h)
Multiplier = 26 (stored at 2502h)
Product = 0*256(stored at 2504h) + 182(stored at 2503h) = 182
Screenshots:
B) Division of Two 8-Bit Numbers by Repeated Subtraction Method

Code:

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


jmp start
;data
;Example :- Divide 13 by 3(13/3)
;code
start: nop

LDA 2500H ;Divisor (i.e 3 here)is stored at A


MOV B,A ;Divisor is moved to register B
LDA 2501H ;Load dividend in register A i.e A = 13
MVI C,00H ;Initialize C as 0 which stores Quotient
CMP B
;Dividend is compared to Divisor
;since A>B therefor 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 ;Dividend is compared to Divisor
JNC up ;loop runs till carry is 0 i.e A > B
down: STA 2502H ;Store Remainder i.e A = 1
MOV A,C ;C=>A Quotient Value is copied to Accumulator
STA 2503H ;Store Quotient(i.e value at A) at 2503 which is 4
hlt ;terminate program execution

Input and Output:


Divisor = 3 (2500h → 3)
Dividend = 13 (2501h → 13)
Remainder = 13%3 = 1 (2502h → 1)
Quotient = 13/3 = 4 (2503h → 4)
Screenshots:

You might also like