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 at given location
  • Store first number in D-E pair
  • Load Second Number
  • Store content of E in Accumulator
  • Add L and E and store output in L
  • Move D in Accumulator
  • Add H and D and store output in H
  • Store content of H and L at given location
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LHLD
2050 H
Get First Number
2003
XCHG

Save Ist Number in D-E pair
2004
LHLD
2052 H
Get  2nd No in H-L pair
2007
MOV
A,E
Save data of E in A  
2008
ADD
L
Add E and L
2009
MOV
L,A
Store output in L
200A
MOV
A,D
Move Content of D into A
200B
ADC
H
Add H and D
200C
MOV
H,A
Move output in H
200D
SHLD
2054
Store output
2010
RST
5
Set Break Point
2011
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.
MOV rd,rs: This instruction copies data from the source register into destination register.
ADD r: This instruction adds the content of specified register to the contents of accumulator and store result in the accumulator.
ADC r: This instruction will add the content of specified register with content of accumulator with carry.
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 execute 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