Running 2 Youtube Channel : The Masti Adda (Fun based ) : The Knowledge Adda (Knowledge based) : Subscribe for Knowledge with Fun....

Write a program to multiply two 8 bit numbers, output 8 bit or more than 8 bit number using memory location and repetitive addition method.

Written by @
Apparatus Used: Microprocessor kit, Keyboards
Assumption: Suppose in this case first number is stored at 2050 and second number is stored at 2051. Multiplication can be achieved by adding the multiplicand repeatedly as many times as the multiplier. As 05*08. 05+05+05+05+05+05+05+05=40
Algorithm:
  • Load first number in D-E register Pair
  • Store 2nd Number in Register C.
  • Initialize H-L register Pair as 00 for result.
  • Add DE+HL pair for result.
  • Decrement counter by one.
  • Check counter is zero or not. If counter is not zero repeat addition.
  • Store output at given location.
Program:
Memory Add
Mnemonics
Op-code
Comments
2000
LDA
2050 H
Load first number in accumulator
2003
MOV
E,A
Move first number in register E
2004
MVI
D,00 H
Load D with 00 as 1st No.
2006
LDA
2051 H
Load Second number in Accumulator
2009
MOV
C,A
Initialize second number as Counter
200A
LXI
H,0000 H
Initialize Result=0
200D
DAD
D
Result= Result + First Number
200E
DCR
C
Decrement the counter
200F
JNZ
200D
If counter is not 0,repeat addition
2012
SHLD
2052
Store output
2015
RST
5
Set Breakpoint
2016
END

End the program
Description of used instruction:
MVI: This instruction is used to store 8 bit data in specified register.
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
LHLD addr: This instruction copies the contents of memory location given within the instruction into L register and contents of next memory location into the H register.
DAD rp: This instruction adds the contents of the specified register pair to the contents of the HL register pair.
SHLD: The contents of register L are stored in the memory location specified by the 16-bit address in the operand and the contents of register H are stored in the next memory location.
MOV rd,rs: This instruction copies data from the source register into destination register.
LDA adr: Load data into register A (accumulator) directly from the address given within the instruction.
DCR: This instruction is used decrement the content of specified register by 1.
JNZ: If result is not zero it will jump to the target address.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set breakpoint for the execution.
END: This instruction is used to execute the program.
Result:
Input:
2050-A1 H
2051-04 H
Output: 
2052 -84 H
2053- 02 H
Procedure to look output
  • After press ENTER, You will get first screen
  • Press G and Provide Initial address (as 2000)
  • Press SHIFT+4,You will get first screen again
  • Press M and Provide Input location for Input (M2050)
  • Press ENTER and Provide your Input at location (2050: A1)
  • Press ENTER and Provide your Second Input (2051 :04)
  • Press SHIFT+4
  • Press G and Provide Initial address (as 2000)
  • Press SHIFT+4,You will get first screen again
  • Press M and Provide address for output (M2052) and press ENTER
  • You will get your desired output.

No comments:

Post a Comment