March 17, 2012
Write an assembly language program to calculate the sum of only even number of series of 8-bit numbers, output 8-bit or more than 8 bit number.
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. In this program we have to store carry and output will be eight bit only. The result of sum is stored in memory location 2500 H and carries at 2501 H.
Algorithm:
- Initialize counter as length of series
- Initialize memory pointer for first data·
- Load first data in accumulator
- Rotate right through carry
- Check for no carry, if carry bit is 1 then data is odd otherwise even
- If number is odd load sum in A
- Add accumulator and data from the series
- Check for again carry, If carry is produced then increment D
- Decrement counter by 1
- Check counter for zero, if not zero then repeat the process and so on
- Store output and Carry
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LDA
|
2300 H
|
Load length of series in A
|
2003
|
MOV
|
C,A
|
Initialize counter as C
|
2004
|
LXI
|
H,2301 H
|
Initialize memory pointer
|
2007
|
MVI
|
E,00 H
|
Initialize lower byte sum=0
|
2009
|
MOV
|
D,E
|
Higher byte sum=0
|
200A
|
MOV
|
A,M
|
Load first data in Accumulator
|
200B
|
RAR
|
Rotate right to check LSB of data
| |
200C
|
JC
|
2016
|
Do not add if number is even
|
200F
|
MOV
|
A,E
|
If number is odd, load LSB sum in A
|
2010
|
ADD
|
M
|
LSB Sum=LSB sum + data from series
|
2011
|
MOV
|
E,A
|
Store the result in E
|
2012
|
JC
|
2016
|
If no carry produced then jump to 2016
|
2015
|
INR
|
D
|
If carry produced increment D
|
2016
|
INX
|
H
|
Increment pointer
|
2017
|
DCR
|
C
|
Decrement counter
|
2018
|
JNZ
|
200A
|
Repeat process till counter=0
|
201B
|
MOV
|
A,E
|
If it is zero move LSB sum into A
|
201C
|
STA
|
2500 H
|
Store output
|
201F
|
MOV
|
A,D
|
Move the carry into accumulator
|
2020
|
STA
|
2501 H
|
Store the carry
|
2023
|
RST
|
5
|
Set Break-point
|
2024
|
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.
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.
RAR: Rotates the bits of accumulator right by one position, through the carry
JNC: Jump if No carry at specified memory address.
DCR: This instruction is used decrement the content of specified register by 1.
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 (Length of series)
2301 H-02 H
2302 H-52 H
2303 H-89 H
2304 H-7F H
Output: 2500-54 H (Lower Byte)
2501-00H (Higher Byte)
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:02H)
- 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