February 07, 2012
Write an assembly language program to calculate the sum of series of 8-bit numbers,output 8-bit or more than 8 bit.
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 the carry is stored in location 2501 H.
Algorithm:
- Initialize counter as number of data
- Initialize pointer as first location of data
- Clear accumulator
- Initialize carry
- Add the first data with accumulator
- Check for the carry, if not carry then get next number, else get carry
- Decrement counter
- Check counter for zero, if not zero then add next number and so on
- Store output and carry memory location
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LDA
|
2300 H
| |
2003
|
MOV
|
C,A
|
Initialize counter
|
2004
|
LXI
|
H,2301 H
|
Initialize pointer
|
2007
|
MVI
|
A,00
|
Clear the accumulator
|
2009
|
MVI
|
B,00
|
Initialize carry=0
|
200B
|
ADD
|
M
|
Sum(L)=sum+data
|
200C
|
JNC
|
2010
|
Check carry
|
200F
|
INR
|
B
|
Add carry
|
2010
|
INX
|
H
|
Increment pointer
|
2011
|
DCR
|
C
|
Decrement counter
|
2012
|
JNZ
|
2009
|
Check if counter is zero
|
2015
|
STA
|
2500 H
|
Store sum
|
2018
|
MOV
|
A,B
| |
2019
|
STA
|
2501 H
|
Store carry
|
201C
|
RST
|
5
|
Set Break-point
|
201D
|
END
|
End the program
|
Used Instruction:
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
SUB r: This instruction subtract the content of specified register from the contents of accumulator and store result in 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.
JNC: Jump if not carry at specified memory address.
INR: It will increment the content of specified register by one.
JNZ: Jump if value of specified register is not zero.
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-89 H
2304 H-3E H
Output: 2500-B3 H
2501-01 H (Carry)
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
SUB r: This instruction subtract the content of specified register from the contents of accumulator and store result in 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.
JNC: Jump if not carry at specified memory address.
INR: It will increment the content of specified register by one.
JNZ: Jump if value of specified register is not zero.
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-89 H
2304 H-3E H
Output: 2500-B3 H
2501-01 H (Carry)
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