February 23, 2012
Write an assembly language program to arrange array of data in ascending order.
Apparatus Used: Microprocessor Kit, Keyboard
Used Instruction:
Result
Input:
Assumption: We have to write a program to arrange given data into the ascending order.
Algorithm:
- Initialize HL pair as memory pointer
- Get number of count into C
- C. Copy it into Register D
- Get the first value into the register A
- A. Compare it to with next location data
- If they are out of order, exchange the contents of A-register and memory
- B. Decrement the register D by 1
- Repeat A and B step till register D is zero
- D. Decrement Register C by 1
- Repeat from C to D till C becomes zero.
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
H,2500 H
|
Memory pointer Initialization
|
2003
|
MOV
|
C,M
|
Get Count into C
|
2004
|
DCR
|
C
| |
2005
|
MOV
|
D,C
|
Copy into Register D
|
2006
|
INX
|
H
|
Get First Number
|
2007
|
MOV
|
A,M
|
Store into Accumulator
|
2008
|
INX
|
H
|
Get Next Number
|
2009
|
CMP
|
M
|
Compare First no & 2nd No
|
200A
|
JC
|
2012
|
Check for carry
|
200D
|
MOV
|
B,M
|
Store Number into B
|
200E
|
MOV
|
M,A
| |
200F
|
DCX
|
H
|
Get Previous Number
|
2010
|
MOV
|
M,B
| |
2011
|
INX
|
H
|
Get Next Number
|
2012
|
DCR
|
D
|
Decrement D
|
2013
|
JNZ
|
2007
|
Check for D=0
|
2016
|
DCR
|
C
|
Decrement C
|
2017
|
JNZ
|
2005
|
Check for C-0
|
201A
|
RST
|
5
|
Set Breakpoint
|
201B
|
END
|
End the program
|
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.
DCX: This instruction is used to decrement the content of specified register pair by one.
DCR: This instruction is used decrement the content of specified register by 1.
CMP M: Compare data in memory with accumulator
JC: Jump if carry at specified memory address.
JNZ: Jump if value of specified register is not zero.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Input:
2500-05 (Array Size)
2501-05
2502-04
2503-03
2504-02
2505-01
Output:
2501-01
2502-02
2503-03
2504-04
2505-05
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 (M2500)
- Press ENTER and Provide your Input at location (2500:05)
- Press ENTER and provide your Input at location (2501:05) 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 (M2501) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment