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

Write an assembly language program to add two 16 bit numbers, output 16 bit numbers.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to add two 16 bit numbers. In this case for any 16 bit number, lower byte takes a location and also higher byte take a location, same for the second number and also for output, so we use 6 memory locations for this.
Algorithm:
  • Load First number in H-L Pair
  • Save H-L pair value into D-E Pair
  • Load 2nd Number into H-L Pair
  • Add First Number and Second Number
  • Store Output
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LHLD
2050 H
Load First Number
2003
XCHG

Store First Number in D-E
2004
LHLD
2052 H
Load Second Number
2007
DAD
D
Add First Number and 2nd No.
2008
SHLD
2054
Store Output
200B
RST
5
Set Break-point
200C
END

End the program

Used Instruction:
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.
XCHG: Exchange the Contents of H with D and L with E.
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.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to end the program.
Result:
Input:
First Number-1234
2nd Number-2345
Store as
2050-34
2051-12
2052-45
2053-23
Output:
2054-79
2055-35
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:34)
  • Press ENTER and Provide your Input at location (2051:12)
  • Press ENTER and Provide your Input at location (2052:45)
  • Press ENTER and Provide your Input at location (2053:23)
  • 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 (M2054) and press ENTER
  • You will get your desired output.

No comments:

Post a Comment