Assignment III

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

1.

Write an Assembly Language Program for 8085 Microprocessor to


multiply two 8 bit no using Add & Shift Method. The program must have a
check for zero input condition.

Soln: Here the multiplicand is stored in location E050H and the multiplier is stored
in E051H .The result will be stored in E070H(LSB Byte) and E071H(MSB Byte).
First we are checking if multiplicand or multipler is zero.If any one or both are zero
then there is no need to perform multiplication and 00H is stored in E070H and
E071H.Otherwise the multiplication is done by Add and Shift method and result is
stored in the same location.Here we check the multiplier bit and if it is 1 then
multiplicand is added with the output location(initially zero) and shifted left by one
bit and if multiplier bit is 0 addition is skipped and partial product is shifted left by
1bit.This continues until all multiplier bit is checked.
Address Hex Code Opcode Operand Comments
8000H 31 F0 FF LXI SP,FFF0H Initialize Stack Pointer
8003H 2A 50 E0 LHLD E050H Place contents of E050H in L
register and contents of E051H in
H register
8006H EB XCHG Multipler in D and multiplicand
in E
8007H 21 00 00 LXI H,0000H Clear HL pair
800AH 7A MOV A,D
800BH FE 00 CPI 00H }Check if multipler is zero and
800DH CA 19 00 JZ 8019H terminate process if it is zero
8010H 7B MOV A,E
8011H
8013H
FE 00
CA 19 00
CPI
JZ
00H
8019H
}Check if multiplicand is zero
and terminate process if it is zero
8016H CD 1D 00 CALL 801DH Call subroutine for
multiplication
8019H 22 70 E0 SHLD E070H Store the result in E070H(LSB
Byte)and E071H (MSB Byte)
801CH CF RST1 Restart
801DH 7A MOV A,D Take multiplier in Accumulator
801EH 16 00 MVI D,00H Clear D to use DAD instruction
8020H 06 08 MVI B,08H Set up counter to count no of
bits to be rotated
8022H 1F RAR Check if multiplier bit is 1
8023H D2 27 00 JNC 8027H If not skip adding multiplicand

8026H 19 DAD D If multiplier bit is 1,add


multiplicand to HL and place
partial product in HL
8027H EB XCHG Place multiplicand in HL
8028H 29 DAD H Shift left multiplicand
8029H EB XCHG Retrieve shifted multiplicand
802AH 05 DCR B One operation
complete,decrement counter
802BH C2 22 00 JNZ 8022H Go to next bit if counter is not
zero
802EH C9 RET Return to main program if
counter is zero

RESULT:
INPUT: OUTPUT:
MEMORY CONTENT
MEMORY CONTENT
LOCATION
LOCATION
E070H 0CH
E050H 04H
E051H 03H E071H 00H
2. Write an Assembly Language Program for 8085 Microprocessor to multiply
two 8 bit no using Repeated Addition Method. The program must have a check
for zero input condition.

Soln: :Here the multiplicand is stored in location 2000H and the multiplier is stored
in 2001H .The result will be stored in 2500H(LSB Byte) and 2501H(MSB Byte). First
we are checking if multiplicand or multipler is zero. If any one or both are zero then
there is no need to perform multiplication and 00H is stored in 2500H and
2501H.Otherwise the multiplication is done by repeated addition method and result is
stored in the same location. For this we decrement the multiplier by one each time and
go on adding multiplicand with the partial product(which is initialised with zero) until
multiplier becomes zero.
Address Hex Code Opcode Operand Comments
8000H 21 00 20 LXI H,2000H Set up memory pointer
8003H 7E MOV A,M
8004H C6 00 ADI 00H }Check if multiplicand is zero and
8006H CA 1D 80 JZ 801DH terminate if if it is zero
8009H 4F MOV C,A Copy multiplicand in register C
800AH 23 INX H Increament memory pointer
800BH 7E MOV A,M
800CH C6 00 ADI 00H }Check if multiplier is zero and
800EH CA 1D 00 JZ 801DH terminate if if it is zero
8011H 06 00 MVI B,00H Clear register B
8013H 60 MOV H,B Clear register H
8014H 69 MOV L,C Multiplicand in register C
8015H 3D DCR A Decrement Multiplier
8016H CA 21 80 JZ 8021H Goto 8021H if multipler becomes
zero
8019H 09 DAD B Add multiplicand with itself and
store in HL pair
801AH C3 15 80 JMP 8015H Goto 8015H to repeat the task
801DH 26 00 MVI H,00H
801FH 2E 00 MVI L,00H }Store all zero in HL pair if
multiplicand and multiplier is zero
8021H 44 MOV B,H Copy contentf of H in register B
8022H 4D MOV C,L Copy contentf of L in register C
8023H 21 00 25 LXI H,2500H Set up memory pointer for output
location
8026H 71 MOV M,C Store low oreder byte in 2500H
8027H 23 INX H Increament memory pointer
8028H 70 MOV M,B Store high oreder byte in 2501H
8029H 76 HLT Wait

RESULT:
INPUT: OUTPUT:

MEMORY CONTENT MEMORY CONTENT


LOCATION LOCATION
2000H 08H 2500H F8H
2001H FFH
2501H 07H

3. Write an Assembly Language Program for 8085 Microprocessor to multiply


two signed no using Booth’s Algorithm.
Soln.Booth’s algorithm is suitable for signed no multiplication.Here we cosider the
MSB of both multiplicand and multiplier as the sign bit.So the maximum no that can
be multiplied is 7FH(using 8bit register to store the input data) and for negative nos
sign bit will be 1 and no. is represented in 2’s complement form. The result will be
given in 2’s complement From the sign bit of the result we can interpret whether the
result is positive or negative.
The Multiplicand is stored in E050H and multiplier is stored in E051H. The
product will be stored in HL pair(MSB Byte in H,LSB Byte in L).
Address Hex Code Opcode Operand Comments
E000H 3A 51 E0 LDA E051H Load Accumulator with Multiplier
E003H 47 MOV B,A Copy multiplier to register B
E004H 0E 00 MVI C,00H
E006H 3A 50 E0 LDA E050H Load Accumulator with
Multiplicand
E009H 26 00 MVI H,00H Pad zero(to the left of
multiplicand)
E00BH 6F MOV L,A Copy multiplicand to register L
E00CH 16 08 MVI D,08H Set up counter
E00EH E6 01 ANI 01H
E010H 5F MOV E,A
E011H 7C MOV A,H
E012H E6 80 ANI 80H
E014H B3 ORA E
E015H E2 1B E0 JPO E01BH
E018H C3 25 E0 JMP E025H
E01BH F2 22 E0 JP E022H
E01EH 09 DAD B
E01FH C3 25 E0 JMP E025H
E022H 7C MOV A,H
E023H 90 SUB B
E024H 67 MOV H,A
E025H 7D MOV A,L
E026H E6 01 ANI 01H
E028H 37 STC
E029H E2 2D E0 JPO E02DH
E02CH 3F CMC
E02DH 7C MOV A,H
E02EH 1F RAR
E02FH 67 MOV H,A
E030H 7D MOV A,L
E031H 1F RAR
E032H 6F MOV L,A
E033H 15 DCR D
E034H C2 0E E0 JNZ E00EH
E037H CF RST 1

RESULT:
INPUT: OUTPUT:

MEMORY CONTENT REGISTER CONTENT


LOCATION H 00H
E050H 04H L 0CH
E051H 03H

You might also like