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

Write an assembly language program to arrange 10 given data in descending order.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to arrange 10 data into the descending order. Let assume that data starting from memory location 2500 H
Algorithm:
  • Initialize outer counter as well as inner counter
  • Initialize memory pointer for data
  • Get the first data into accumulator
  • Get next data
  • Compare first data and next data
  • Check for larger number
  • If first number >next data then exchange the content else decrement counter
  • Increment memory pointer
  • Check the counter inner counter =0 if yes then decrement counter 1 if not then repeat the process from 2007
  • Check the counter=0 if counter1=0 then end the program else repeat the process from 2002.
  • Store the output
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
MVI
B,09 H
Initialize outer counter
2002
LXI
H,2500 H
Initialize memory pointer
2005
MVI
C,09
Initialize inner counter
2007
MOV
A,M
Get 1st No in accumulator
2008
INX
H
Get 2nd  Number
2009
CMP
M
Compare First no & 2nd No
200A
JNC
2012
Check for carry
200D
MOV
D,M
Store Number into D
200E
MOV
M,A
Get accumulator at memory
200F
DCX
H
Get Previous Number
2010
MOV
M,D
Store D at memory location
2011
INX
H
Get Next Number
2012
DCR
C
Decrement C
2013
JNZ
2007
Check for C=0 if not then jump
2016
DCR
B
Decrement B
2017
JNZ
2002
Check for B=0,if not then jump
201A
RST
5
Set Breakpoint
201B
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.
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
JNC: Jump if no 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.
 
Result:
Input:
2500-07
2501-05
2502-04
2503-03
2504-02
2505-01
2506-09
2507-08
2508-06
2509-0F
Output:
2500-0F
2501-09
2502-08
2503-07
2504-06
2505-05
2506-04
2507-03
2508-02
2509-01
 
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:07)
  • 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 (M2500) and press ENTER
  • You will get your desired output.

No comments:

Post a Comment