January 11, 2012
Write an assembly language program find largest number in array of data.
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: Let assume that We have to write a program to find largest number among 10 data. Data are stored at different memory location and we have to store largest number at memory location also.
Algorithm:
- Load data for counter in first memory location
- Get First Number and store it in accumulator
- Decrement the counter by 1
- 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.
- Decrement counter again
- Check value of Counter=0, if counter is zero then end the program, otherwise proceed
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
H,2500 H
|
Number of data at 2500 H
|
2003
|
MOV
|
C,M
|
Number of data as Counter
|
2004
|
INX
|
H
|
Get the first number
|
2005
|
MOV
|
A,M
|
Get First data in Accumulator
|
2006
|
DCR
|
C
|
Decrement Count
|
2007
|
INX
|
H
|
Get Second data to compare
|
2008
|
CMP
|
M
|
Compare First and Second
|
2009
|
JNC
|
200D
|
Jump if no carry
|
200C
|
MOV
|
A,M
|
Store output at 2052
|
200D
|
DCR
|
C
|
Store Carry in A
|
200E
|
JNZ
|
2007
|
Store carry at 2053
|
2011
|
STA
|
2550
|
Store largest number
|
2014
|
RST
|
5
|
Set Break-point
|
2015
|
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.
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 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
JNC: Jump if not carry at specified memory address.
JNZ: Jump if value of specified register is not zero.
STA: This instruction is used to store the content of accumulator at given location.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
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 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
JNC: Jump if not carry at specified memory address.
JNZ: Jump if value of specified register is not zero.
STA: This instruction is used to store the content of accumulator at given location.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input:
2500-0A (Length of array)
2501-01
2502-02
2503-03
2504-10
2505-12
2506-25
2507-35
2508-45
2509-21
250A-07
Output:
2550-45 H (Largest Number)
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:10)
- Press ENTER and provide your Input at location (2501:01) 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 (M2550) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
obvious approach
ReplyDeleteThanx
DeleteI understand the algorithm but i'm having a hard time coding.. the assembly syntax is new to me.. can u help me? i need to find the largest and smallest value in n input.. if it were C or java it would have been much easier..
ReplyDeleteplease help me finding the highest and the lowest value among the three inputs of the user... please .. assembly language
ReplyDelete