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

Write a program to add the corresponding elements of two arrays having five 8-bit numbers each and store them in a third array. Output should be not more than 8-bit.

Written by @
Apparatus Used: Microprocessor kit, Keyboards
Assumption: The Arrays start at memory locations 2100H, 2200H and 2300 H respectively. Assume that all the sums obtained in the process are not more than 8-bits.
 
Algorithm:
  • Initialize the pointer for data array1, data array2 and also for result array.
  • Add corresponding element for data array1 and data array 2.
  • Store the output at result array.
  • Increase the data array pointer
  • Compare the lower byte of first array with 05
  • Repeat process till equal to zero
  • Store output
  • End the Program  
Program:
Memory Add
Mnemonics
Op-code
Comments
2000
LXI
H, 2100 H
Initialize pointer for first data array
2003
LXI
B, 2200 H
Initialize pointer for second data array
2006
LXI
D, 2300 H
Initialize pointer for result data array
2009
LDAX
B
Load data in A from second array
200A
ADD
M
Add corresponding element in first array
200B
STAX
D
Store the result at result array
200C
INX
H
Increment the pointer 1
200D
INX
B
Increment the pointer 2
200E
INX
D
Increment the result  pointer
200F
MOV
A,L
Move the lower byte of array 1 in A
2010
CPI
05
Compare lower byte with 0A
2012
JNZ
2009
If it is not equal zero, repeat process
2015
RST
5
Set Break-point
2016
END
End the program

Description of used instruction: 
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand. 
MOV: This instruction is used to copy the content from source register to destination register.
ADD: This instruction is used to add the content of specified register to the content of accumulator and store output in accumulator. 
INX: This instruction is used to increment the content of specified register pair by one. 
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.
STAX: The contents of accumulator are copied into memory location specified by whose address specified by BC or DE register pair. 
LDAX: The contents memory location specified by BC or DE register pair copies into accumulator. 
RST 5: This instruction is used to set break-point for the execution. 
END: This instruction is used to execute the program. 
 
Result: 
Input: 
2100-01, 2101-01, 2102-03, 2103-04, 2104-08 
2200-01, 2201-01, 2202-03, 2203-04, 2204-06 
Output: 2300-02, 2301-02, 2302-06, 2303-08, 2304-0E
 
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 (M2100)
  •  Press ENTER and Provide your Input at location (2100:01) and so on
  •  Press SHIFT+4
  •  Press G and Provide Initial address (as 2000)
  •  Press ENTER and Provide your Input at location (2201:01)
  •  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 (M2300) and press ENTER
  •  You will get your desired output.

No comments:

Post a Comment