0% found this document useful (0 votes)
61 views

COA Lab Session 8

Uploaded by

beshahashenafi32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

COA Lab Session 8

Uploaded by

beshahashenafi32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab session 8: Control Structure and Cycle Instructions

Objective

The objective of lab session 8 is


 To understand the basic concept of control structure and cycle instructions in assembly
programming language
 To differentiate mnemonic that used for control structure and cycle instructions
 To know how the processor used CX register to operate cycle instructions
 To write assembly language program with control structure and cycle instructions,
assemble, link and run.

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

MOV AH, 09h


LEA DX, newline
INT 21h
LOOP One

12. Rewrite the above solution using JUMP statement


13. Determine the output of the following fragment of code

MOV BL, „b‟ MOV BL, „b‟ MOV BL, „b‟


MOV CX, 4 MOV CX, 4 MOV CX, 4
loop1: loop1: loop1:
MOV AH, 02H MOV AH, 02H MOV AH, 02H
MOV DL, BL MOV DL, BL MOV DL, BL
INT 21H INT 21H INT 21H
LOOP loop1 CMP BL, „b‟ CMP BL, „b‟
LOOPE loop1 LOOPNE loop1

In-lab Exercise

14. Write full program for the above block of code?


15. Write a block of code that take 2 numbers from the user and display the maximum
number?
The output:
Enter the first number: 4
Enter the second number: 5
The maximum number is: 5
16. Write a block of code that take 3 numbers from the user and display the minimum and
maximum number?

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

You might also like