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 4 digit BCD number, output 16 bit numbers.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to decimal addition 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
  • Make result as Valid BCD
  • Move D in Accumulator
  • Add H and D and store output in H
  • Make result as Valid BCD
  • 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
DAA
Adjust result to make valid BCD
200A
MOV
L,A
Store output in L
200B
MOV
A,D
Move Content of D into A
200C
ADC
H
Add H and D
200D
DAA
Adjust result to make valid BCD
200E
MOV
H,A
Move output in H
200F
SHLD
2054
Store output
2012
RST
5
Set Break Point
2013
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.
DAA: If the value of low order four bits in the accumulator is greater then 9 or if auxiliary carry flag is set, the instruction adds 6 to the low order four bits. If the value of high order four bits in the accumulator is greater then 9 or if auxiliary carry flag is set, the instruction adds 6 to the high order four bits
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.

2 comments:

  1. best site for mp and best collection for revision of mp

    ReplyDelete