March 16, 2012
Write an assembly language program to calculate the sum of series of 8-bit numbers, output 8-bit or more
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: In this program the length of series is in memory location 2300 H and series itself begins from memory location 2301 H. The result of sum is stored in memory location 2500 H and 2501 H.
Algorithm:
- Load the length of the array in accumulator
- Initialize counter
- Clear accumulator
- Get first data and add the first data with accumulator
- Check for carry, if carry generated then Increment register else jump to next data
- Increment the Pointer
- Decrement counter
- Check counter for zero, if not zero then add next number and so on
- Store output and carry
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LDA
|
2300 H
|
Load length of array in Accumulator
|
2003
|
MOV
|
C,A
|
Initialize counter as A
|
2004
|
XRA
|
A
|
Make sum=0
|
2005
|
LXI
|
H,2301 H
|
Get first data
|
2008
|
MOV
|
B,A
|
B make as 0 for store carry
|
2009
|
ADD
|
M
|
Add first data to accumulator
|
200A
|
JNC
|
200E
|
If carry is not then jump to 200E
|
200D
|
INR
|
B
|
If carry, Increment B
|
200E
|
INX
|
H
|
Increment the Pointer
|
200F
|
DCR
|
C
|
Decrement counter
|
2010
|
JNZ
|
2009
|
Check for counter
|
2013
|
STA
|
2500 H
|
Store output
|
2016
|
MOV
|
A,B
|
Store carry in accumulator
|
2017
|
STA
|
2501 H
|
Store the carry
|
201A
|
RST
|
5
|
Set the Breakpoint
|
201B
|
END
|
End the program
|
Used Instruction:
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
XRA: Logically AND the contents of register/memory with the accumulator.
MVI: This instruction is used to store 8 bit data in specified register.
MOV: This instruction is used to copy the content from source register to destination register.
INX: This instruction is used to increment the content of register pair by 1.
ADD: This instruction is used to add the content of specified register to the content of accumulator and store output in accumulator.
DCR: This instruction is used decrement the content of specified register by 1.
JNZ: Jump if value of specified register is not zero.
JNC: Jump if not carry at specified memory address.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input: 2300 H-04 H
2301 H-9A H
2302 H-52 H
2303 H-89H
2304 H-3E H
Output: 2500-B3 H
2501-01 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 (M2300)
- Press ENTER and provide your Input at location (2300:04H)
- Press ENTER and provide your Input at location (2301:9AH)
- Press ENTER and provide your Input at location (2302:52H) and so on…
- 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 (M2500) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment