COA Lab Session 8
COA Lab Session 8
Objective
Pre-lab Exercise
1. The CMP and SUB instructions are the same in the computer system; both instructions
subtract the source operator from the destiny operator and store the result of the
operation.
A. True B. False
2. Which of the following jump instruction works without condition
A. JMP B. JA C. JE D. JNZ
3. Which mnemonic is represent (similar operation) jump if it above
A. JA B. JNBE C. JZ D. A and B
4. Which register will be used as iterator variable in cycle instructions?
A. AX B. BX C, CX D. DX
5. Write a block of code that compare the content of AL=01h and BL=03h?
Use the below data variables declaration for question 6 and 7 and display the declared
messages accordingly.
.data
Msg1 db “Equal”
Msg2 db “Not Equal”
Msg3 db “Greater than”
Msg4 db “Less than”
Msg5 db “Greater than or equal”
Msg6 db “Less than or equal”
1|Page
Example: Write a block of code that compare the content of CL=6 and BL=2 and display a message
equal or not equal?
Solution:
MOV CL, 6
MOV BL, 2
CMP CL, BL
JE Msg1Label
JNE Msg2Label
Msg1Label: MOV AH, 09H
LEA DX, Msg1
INT 21
JMP Exit
Msg2Label: MOV AH, 09H
LEA DX, Msg1
INT 21
JMP Exit
Exit: MOV AH, 4CH
INT 21H
6. Write a block of code that take a number and check if it is zero or not. If it is zero display
equal, if not display not equal?
7. Write a block of code that compare the content of CL=1 and BL=2 and display a
message greater than or less than?
8. Write a block of code that displays a message “Welcome-” five time using LOOP?(Similar
with the given output)
Output: Welcome-Welcome-Welcome-Welcome-Welcome-
Solution:
.data
msg DB “Welcome-” ,'$'
.code
.
.
MOV CX, 5
LP1:
MOV AH, 09H
LEA DX, msg
INT 21H
LOOP LP1
9. Write a block of code that displays a message “Welcome” five time using LOOP?(Similar
with the given output)
Output: Welcome
Welcome
Welcome
2|Page
Welcome
Welcome
10. Rewrite the above block of code using JUMP statement?
Solution:
.data
msg DB “Welcome”,13,10,'$'
.code
.
.
MOV CX, 5
LP1:
DEC CX
MOV AH, 09H
LEA DX, msg
INT 21H
CMP CX, 0
JE EXIT
JNE LP1
EXIT:
MOV AH, 4CH
INT 21H
11. Write a block of code that displays the following output?
*****
*****
*****
*****
For the above output we need two loops one for horizontal repetition and other for
vertical repetition.
First we write a single line output.
MOV BL, „*‟ ; Star symbol „*‟ stored inside BL
MOV CX, 5 ; 5 is the number of star
One:
MOV AH, 02H
MOV DL, BL
INT 21H
LOOP One
The above block of code display “ * * * * * ”. To finish the program we need a newline
program and the second loop.
.data
newline db 13,10,'$'
star db „ * ‟,‟$‟
X dw 0
.code
.
.
3|Page
MOV CX, 5
One:
MOV X, CX ; store CX content for the next repetition
MOV CX, 5
Two:
MOV AH, 09h
LEA DX, star
INT 21h
LOOP Two
MOV CX, X
In-lab Exercise
4|Page
The output:
Enter the first number: 8
Enter the second number: 5
Enter the third number: 3
The minimum number is: 3
The maximum number is: 8
17. Write a block of code that displays a sequence of stars “*”. Similar with the given output
Output:
*****
****
***
**
*
Post-lab Exercise
18. Write how the three cycles instructions work (LOOP, LOOPE and LOOPNE) with
examples?
19. Write the difference and similarities between the following instructions
A. CMP Destiny, Source
B. SUB Destiny, Source
5|Page