Running 2 Youtube Channel : The Masti Adda (Fun based ) : The Knowledge Adda (Knowledge based) : Subscribe for Knowledge with Fun....

Write an assembly language program find largest number in array of data

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to find largest number among 05 data. Data are stored at different memory location and we have to store largest number at memory location also.
 
Algorithm:
  • Initialize counter of length of array
  • 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
MVI
C, 05 H
Set Counter
2002
LXI
H,2501 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 larger no in accumulator
200D
DCR
C
Decrement counter by 1
200E
JNZ
2007
Check the value of counter=0
2011
STA
2550
Store largest number
2014
RST
5
Set Breakpoint
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 1. 
DCR: This instruction is used decrement the value of given register by 1. 
CMP M: Compare data in memory with accumulator 
JNC: Jump if no 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 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: 
2501-01 
2502-02
2503-03 
2504-10 
2505-12 
Output: 
2550-12 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 (M2501)
  • 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.

No comments:

Post a Comment