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.
Input: 64H Output: output at PORT2 -->64H Input: 40H Output: output at PORT1 -->00H
- Load the BYTE1 in accumulator A.
- Copy the Data from the accumulator to register B.
- Subtract the 50H from the accumulator(BYTE).
- Jump if subtraction is negative.
- If jump condition is true then it will simply print 00H at PORT1.
- 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.
MVI A, BYTE1
MOV B, A
MOV A, B
DISPLAY:MOV A, B
Jump to DELETE, if CY=1
Jump to DISPLAY, if CY=1
[A]<–[A Exclusive OR A]
output the content of the accumulator at PORT1
output the content of the accumulator at PORT2
- MVI A, BYTE1: load the accumulator A from BYTE1.
- MOV B, A: copy the content of accumulator to register B.
- <SUI 50H:> subtract the 50H from the content of the accumulator(BYTE1) and load it into accumulator.
- 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.
- MOV A, B: copy the content of register B (BYTE1) to accumulator.
- 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.
- 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 CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.