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: 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
  • Clear Accumulator
  • Get First Number
  • Compare first and Accumulator
  • 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
XRA
A
Clear the accumulator
2005
INX
H
Get First data
2006
CMP
M
Compare 2nd data with A
2007
JNC
200B
Check for no carry
200A
MOV
A,M
Store larger no. in Acc
200B
INX
H
Increment Pointer
200C
DCR
C
Decrement Counter
200D
JNZ
2007
Jump if counter is not 0
2010
STA
2550
Store largest number
2013
RST
5
Set Breakpoint
2014
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. 
XRA: This instruction is used to perform AND-ing operation with given data and accumulator. 
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 (Number of Data) 
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

No comments:

Post a Comment