Assembly language program to find the range of bytes

Problem – Write an assembly language program that if an input number BYTE1 lies b/w 50H to 80H display it on output PORT2. If BYTE1 is less then 50H then simply print 00H at the output PORT1.

Examples:

Input:  64H
Output: output at PORT2 -->64H
Input:  40H
Output: output at PORT1 -->00H 

Algorithm –

  1. Load the BYTE1 in accumulator A.
  2. Copy the Data from the accumulator to register B.
  3. Subtract the 50H from the accumulator(BYTE).
  4. Jump if subtraction is negative.
  5. If jump condition is true then it will simply print 00H at PORT1.
  6. If jump condition is false then BYTE1 will greater than 50H and in further instructions, it will also check the upper limit 80H of the BYTE1 so all the numbers lie b/w 50H to 80H those will print at PORT2.

Program –



MEMORY ADDRESS MNEMONICS COMMENT
2000
2002
2003
2004
2007
2008
2009
200A
200B
200C
200D
200E
200F
MVI A, BYTE1
MOV B, A
SUI 50H
JC DELETE
MOV A, B
SUI 80H
JC DISPLAY
DELETE:XRA A
OUT PORT1
HLT
DISPLAY:MOV A, B
OUT PORT2
HLT
[A]<–[BYTE1]
[B]<–[A]
[A]<–[A-50]H
Jump to DELETE, if CY=1
[A]<–[B]
[A]<–[A-80]H
Jump to DISPLAY, if CY=1
[A]<–[A Exclusive OR A]
output the content of the accumulator at PORT1
program termination
[A]<–[B]
output the content of the accumulator at PORT2
program termination

Explanation –

  1. MVI A, BYTE1: load the accumulator A from BYTE1.
  2. MOV B, A: copy the content of accumulator to register B.
  3. <SUI 50H:> subtract the 50H from the content of the accumulator(BYTE1) and load it into accumulator.
  4. JC DELETE: here JC is jump instruction with carry flag check condition, carry flag will 1 if the subtraction is negative if the subtraction is positive then carry flag will be 0. SUI 50H will be positive if Accumulator content (BYTE1) will be greater or equal to 50H. if CY=0 result is positive and no jump will be performed.
  5. MOV A, B: copy the content of register B (BYTE1) to accumulator.
  6. SUI 80H: subtract the 80H from the accumulator. If the accumulator content will be less than 80H then result will be positive and it will jump to DISPLAY label and display the BYTE at PORT2 if the number will be in range 50H to 7FH.
  7. If in step-4, JC DELETE true means the subtraction result will positive then it will jump to delete and clear the content of accumulator and display 00H at output PORT1.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.