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 smallest number in array of data

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: Let assume that We have to write a program to find smallest number among 10 data. Data are stored at different memory location and we have to store smallest 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 small otherwise first number will be small
  • If second number is small 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
JC
200D
Jump if 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 1.
DCR: This instruction is used decrement the value of given 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.
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:
2500-0A (Length of series)
2501-01
2502-02
2503-03
2504-10
2505-12
2506-25
2507-35
2508-45
2509-21
250A-07

Output:
 2550-01 H (Smallest 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