Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

CPEN 100A Lab

BSEE 3-2
Name: Course and Section
Sipat, John Rovic B.
202102574 Date Performed 04/09/24
Student No.:
Date Submitted 04/15/24 Grade

Lab Activity 5
Branch Instructions and Program Loops

Objectives:

At the end of this activity, the student should be able to:

1. Familiarize the user with the applications of conditional and unconditional branch
instructions.
2. Familiarize the user with the technique of designing program loops.
3. practice using status flags in decision-making.

Materials/Equipment:

Laptop with EMU8086 IDE

Theory/Concepts:

The real power of a computer comes from its ability to choose between
two or more sequences of actions based on some conditions, repeat a sequence of
instructions if some condition exists, or repeat a sequence of instructions until
some conditions exist. Flags indicate whether some condition is present or not.
Jump instructions are used to tell the computer the address to fetch its next
instruction from. Figure 3.1 shows in diagram form the different ways a Jump
instruction directs the 8088 to fetch its next instruction from some place in
memory other than the next sequential location.

The 8088 has two types of jump instructions, conditional and unconditional.
When 8088 fetches and decodes an Unconditional Jump instruction, it always
goes to the specified jump destination. You might use this type of Jump
instruction at the end of a program so that the entire program runs repeatedly.

When the 8088 fetches and decodes a Conditional Jump instruction, it


evaluates the state of a specified flag to determine whether to fetch its next
instruction from the jump destination location or to fetch its next instruction from
the next sequential memory locations.
Procedure:

Part 5.1

1. Encode the following assembly program.

2. Click the Emulate button.

3. Click the aux button and select memory.

4. Once the Random Access Memory is displayed, change the memory location from
0100 to 0500 and then click the update button.

5. Click the Single Step button and observe the effect on the registers and memory.
EVIDENCE #1

PASTE THE IMAGE OF YOUR EMULATOR HERE


EVIDENCE #2

PASTE THE IMAGE OF YOUR MEMORY OUTPUT HERE

Observations:
Registers and memory locations are initialized at the start of the assembly program. It
then starts a loop that starts at 0500h and ends when CL is zero, writing the value of AL into
memory locations one after the other. The count of CLs is decreased and the memory location
is increased with each loop iteration. This shows an example of a simple program loop that
uses conditional jump instructions to modify its execution according to the state of the CL
register.
Part 5.2

Write a program that will count the number of zeroes in memory locations 0600H – 0609H.

EVIDENCE #1

PASTE THE IMAGE OF YOUR CODE HERE


EVIDENCE #2

PASTE THE IMAGE OF YOUR EMULATION OUTPUT HERE

Observations:
In memory regions 0600H through 0609H, this program iterates over each location,
incrementing a counter if the value stored there is zero. This just counts the number of zeros
that are present at those locations. It demonstrates how to carry out the counting procedure
periodically until all memory locations are inspected using conditional jumps and loop
constructs. It also makes use of the test instruction to precisely change the counter and check
for zero values.
V. Conclusions

Basic programming concepts like loops and branch instructions enable decision-
making and repetitive code execution. Programs can use branch instructions, like conditional
and unconditional jumps in assembly language, to immediately transfer control to specific
sections or modify their flow based on predetermined criteria. While conditional branches—
like jump if equal (JE) or jump if not zero (JNZ)—are used to make decisions inside the
program, unconditional branches—like jump (JMP) or call subroutine (CALL)—allow non-
linear execution pathways. Program loops, often performed with the assistance of branch
instructions, make it possible to handle repetitive tasks effectively by repeating running a
block of code until a predefined condition is satisfied. The framework is made up of branch
instructions and program loops.

VI. Viva Questions

1. What is/are the difference between conditional and unconditional jump instructions?

Conditional jump instructions are used for making decisions based on criteria,
whereas unconditional jump instructions are used to transfer control unconditionally to a
particular place. Both types of leaps are necessary when writing assembly language and low-
level programming loops, subroutine calls, and branching logic.

2. List down instruction/s used in implementing conditional and unconditional jump


instructions.

1. Conditional Jump Instructions


• JZ (Jump if Zero): When the Zero Flag (ZF), which signifies that the
outcome of the previous operation was zero, is set, control is moved to the
designated address.
• JNZ (Jump if Not Zero): If the Zero Flag (ZF), which signifies that the
outcome of the previous operation was not zero, is clear, control is
transferred to the designated address.
• JC (Jump if Carry): In the event that an unsigned overflow is detected and
the Carry Flag (CF) is set, control is moved to the designated address.
• JNC (Jump if No Carry): When there is no unsigned overflow and the
Carry Flag (CF) is clear, control is sent to the designated location.
• JNE (Jump if Not Equal): If the Zero Flag (ZF) is not set, the system will
jump to a predetermined place.

2 Unconditional Jump Instructions


• JUMP (Jump): Transfers control unconditionally to the designated
location, ignoring any flag conditions or past operation outcomes.
3. As an additional practice exercise, create a program that will copy the content of ten
memory locations (0550H-0559H) to memory locations (0650H – 0659H).

You might also like