You are on page 1of 11

Course: Laboratory Activity No.

:
Name: Section:
Date Performed:
Date Submitted:
Instructor:

LABORATORY ACTIVITY NO. 6


CONTROL FLOW

1. Objective(s):

The activity aims to introduce the control flow statements in assembly language.

2. Intended Learning Outcomes (ILOs):

The students shall be able to: construct a program with some conditions in assembly language

3. Discussion
Instructions are stored consecutively in memory, but program rarely execute in exact order. But the simplest
programs include jumps and procedure calls that alter the execution path the microprocessor takes. The
control flow can make a transfer from one part of a program to another and it divide into three groups
conditional, unconditional and CMP (CoMPare).

Conditional jump
a jump that is executer only if a specified condition is TRUE.
Format:
Jxx <label>

- where xx is an abbreviation for a particular condition.


Conditional Jumps to use with Signed Numbers

Opcode Meaning

JL (JNGE) Jump if less than (not greater than or equal)


JG (JNLE) Jump if greater than (not less than or equal)
JLE (JNG) Jump if less than or equal (not greater than)
JGE (JNL) Jump if greater than or equal (not less that)
JE Jump if equal
JNE Jump if not equal

Conditional Jumps to use with Unsigned Numbers

Opcode Meaning

JB (JNAE) Jump if below (not above or equal)


JA (JNBE) Jump if above (not below or equal)
JBE (JNA) Jump if below or equal (not above)
JAE (JNB) Jump if above or equal (not below)
JE Jump if equal
JNE Jump if not equal

Example: JGE Correct


JL Wrong
Unconditional Jump
a jump that is always executed; that is, it does not depend on a condition being TRUE or FALSE. To
perform an unconditional jump, use the JMP instruction.
Format:
JMP <label>
The CMP Instruction
CMP (CoMPare) instruction is used to compare character data, as well as, numeric data fields. The
main use of CMP is in decision making in conjunction with conditional jump instructions.
Format:
CMP <register> , <register>
CPM <register> , <HEX /character ASCII/decimal>
Example:
CMP AL, 41H
JE Correct
JMP Wrong

4. Resources:
1 Desktop Computer
TASM
5. Procedure:

CONDITIONAL AND UNCONDITIONAL

A sample programs that input a single character using JGE, JL and unconditional jump instruction.

.model small
.stack
.data

Var1 db "Enter a single character $"


Var2 db "UPPERCASE CHARACTER $"
VAr3 db "lowercase character $"
Var4 db "WRONG ENTRY $"

.code
start:
mov ax, @data
mov ds,ax

mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184Fh
int 10h

mov ah, 2
mov bh, 0
mov dh, 10 ; y position
mov dl, 14 ; x position
int 10h

mov ah, 9
mov dx, offset Var1
int 21h

mov ah, 2
mov bh, 0
mov dh, 10 ; y position
mov dl, 54 ; x position
int 10h

mov ah, 07h ;input


int 21h
cmp al, 41h
jge UP

back:
cmp al, 61h
jge LOWnum
jmp wrong

UP:
cmp al, 5bh
jle dispUp
jmp back

dispUp:
mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184fH
int 10h

mov ah, 2
mov bh, 0
mov dh, 12 ; y position
mov dl, 34 ; x position
int 10h

mov ah, 9
mov dx, offset Var2
int 21h
jmp exit

LOWnum:
cmp al, 7bh
jle dispLow
jmp wrong

dispLow:
mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184fH
int 10h

mov ah, 2
mov bh, 0
mov dh, 12 ; y position
mov dl, 34 ; x position
int 10h

mov ah, 9
mov dx, offset Var3
int 21h
jmp exit

wrong:
mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184fH
int 10h

mov ah, 2
mov bh, 0
mov dh, 12 ; y position
mov dl, 34 ; x position
int 10h

mov ah, 9
mov dx, offset Var4
int 21h

exit:
mov ah, 4ch
int 21h
end start

Explain how does conditional jump works


_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

Compare (CMP) and Unconditional Jump


.model small
.stack
.data
Var db "Enter a character to know the MESSAGE $"
Var1 db "Welcome to Assembly Program $ "
Var2 db "Thank you for using the PROGRAM $"
Var3 db "WRONG ENTRY $"
.code
start:
mov ax, @data
mov ds,ax

mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184fH
int 10h

mov ah, 2
mov bh, 0
mov dh, 10 ; y position
mov dl, 14 ; x position
int 10h

mov ah, 9
mov dx, offset Var
int 21h

mov ah, 2
mov bh, 0
mov dh, 10 ; y position
mov dl, 54 ; x position
int 10h

mov ah, 1
int 21h

cmp al, 41h


je CORRECT1

cmp al, 42h


je CORRECT2
jmp wrong

CORRECT1:
mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184fH
int 10h

mov ah, 2
mov bh, 0
mov dh, 12 ; y position
mov dl, 34 ; x position
int 10h
mov ah, 9
mov dx, offset Var1
int 21h
jmp exit

CORRECT2:
mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184fH
int 10h

mov ah, 2
mov bh, 0
mov dh, 12 ; y position
mov dl, 34 ; x position
int 10h

mov ah, 9
mov dx, offset Var2
int 21h
jmp exit

wrong:
mov ah, 6
mov bh, 10H
mov cx, 0
mov dx, 184fH
int 10h

mov ah, 2
mov bh, 0
mov dh, 12 ; y position
mov dl, 34 ; x position
int 10h

mov ah, 9
mov dx, offset Var3
int 21h

exit:
mov ah, 4ch
int 21h
end start

What is the program all about?


_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

What values are needed to be entered to run the program correctly?


_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

What is the difference of conditional jump and unconditional jump?


_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

6. Data and Results:


Create a program that will print the corresponding assign on each key pressed and it will display the string
data function 01h, function 07h and conditional/unconditional instruction.
Sample: Press letter Capital A or Small a?
A: You press Capital A.

Using CMP, Conditional Jump and Unconditional Jump create a program that will allow the user to
input numbers from 0 to 9 only and will convert and display its equivalent number to word.

Sample Output: Enter a Number (0 – 9): 9

Equivalent Word: nine

Create a program that will enter a user’s name and a password. If the username and password is correct, it
display the following:
Your username should be student number and your password should be your first name

Sample output: Username : 0511056

Password : *******--- (aim)

: ……………………….. Welcome <Name> ………………………………..

7. Conclusion:
Based from the results of the experiment, what general rule can you apply for?

CONDITIONAL JUMP
______________________________________________________________________________________________
______________________________________________________________________________________________
______________________________________________________________________________________

UNCONDITIONAL JUMP
______________________________________________________________________________________________
______________________________________________________________________________________________
______________________________________________________________________________________

8. Assessment (Rubric for Laboratory Performance):


BEGINNER ACCEPTABLE PROFICIENT
CRITERIA SCORE
1 2 3
I. Laboratory Skills
Members do not Members occasionally Members always
Manipulative
demonstrate needed demonstrate the demonstrate the
Skills
skills needed skills needed skills
Members are able to
Members are able to
Experimental Members are unable to set-up the materials
set-up the materials
Set - Up set-up the materials with minimum
with supervision
supervision
Members always
Members do not Members occasionally
demonstrated
Process Skills demonstrate targeted demonstrate targeted
targeted process
process skills process skills
skills
Members follow safety Members follow
Safety Members do not follow
precautions most of the safety precautions at
Precaution safety precautions
time all times
II. Work Habits
Time Members finish
Members do not finish
Management/ Members finish on time ahead of time with
on time with
Conduct of with incomplete data complete data and
incomplete data
Experiment time to revise data
Members are on
Members do not know Members have defined
tasks and have
their tasks and have no responsibilities most of
defined
Cooperative and defined responsibilities. the time. Group
responsibilities at all
Teamwork Group conflicts have to conflicts are
times. Group conflicts
be settled by the cooperatively managed
are cooperatively
teacher most of the time
manages at all times
Clean and orderly
Clean and orderly
Messy workplace workplace with
Neatness and workplace at all times
during and after the occasional mess
Orderliness during and after the
experiment during and after
experiment
experiment
Members do not
Ability to do Members require Members require
need to be
independent supervision by the occasional supervision
supervised by the
work teacher by the teacher
teacher
Other comments/observation:
TOTAL SCORE
RATING = (total score) x 100%
24

Evaluated By: Date:

You might also like