January 27, 2012
Write an assembly language program to find larger number between two numbers
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to find larger number between two number and we have to store larger number at memory location.
Algorithm:
- Get First Number and store it in accumulator
- Get second Number
- Compare first and second number
- Check for the carry if carry generated then second number is greater otherwise first number will be greater
- If second number is greater then move it into Accumulator otherwise store output.
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
H,2050 H
|
Store First Number
|
2003
|
MOV
|
A,M
|
Save in Accumulator
|
2004
|
INX
|
H
|
Get the 2nd number
|
2005
|
CMP
|
M
|
Compare First Number & 2nd
|
2006
|
JNC
|
200A
|
Jump if no carry
|
2009
|
MOV
|
A,M
|
Move number in accumulator
|
200A
|
STA
|
2052
|
Store larger number
|
200D
|
RST
|
5
|
Set Break-point
|
200E
|
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.
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 specified register pair by one.
CMP M: Compare data in memory with accumulator
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: 2050-10, 2051-01
Output: 2052-10 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 (M2050)
- Press ENTER and Provide your Input at location (2050:10)
- Press ENTER and Provide your Input at location (2051: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 (M2052) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment