0% found this document useful (0 votes)
53 views2 pages

Lab 3 MP

This document discusses programming in assembly language. It introduces jump instructions, including unconditional jumps (JMP) and conditional jumps (JNZ, JNBE). It provides examples of using conditional jumps to implement loops and if-else statements by comparing values and branching execution. Specifically, it shows how to use CMP to subtract values and JNBE to conditionally jump based on the result, allowing if-else logic. It also asks questions about flags, conditional jumps, implementing while loops, differences between jumps and calls, and analyzing a delay loop.

Uploaded by

Izwan Fazry
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)
53 views2 pages

Lab 3 MP

This document discusses programming in assembly language. It introduces jump instructions, including unconditional jumps (JMP) and conditional jumps (JNZ, JNBE). It provides examples of using conditional jumps to implement loops and if-else statements by comparing values and branching execution. Specifically, it shows how to use CMP to subtract values and JNBE to conditionally jump based on the result, allowing if-else logic. It also asks questions about flags, conditional jumps, implementing while loops, differences between jumps and calls, and analyzing a delay loop.

Uploaded by

Izwan Fazry
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/ 2

Lab 3: Programming in Assembly Language

1.0 Background

In previous lab, you have been introduced to some basic instructions of x86 instruction set with
few small programs to practice. In today’s lab, we will explore more Instruction Set with some
simple tricky problems. We will explore the implementation of IF-ELSE like instructions in x86.

One basic instruction is Jump instructions, which are used to alter the execution path of
instruction in your program. Since in 8088, the CS register and IP are used to keep track the next
instruction to be fetched for execution. There for, jump instructions will alter these two registers.

There are TWO types of jump instructions,


(i) unconditional jump , we have only one unconditional jump instruction, which is JMP.
In simple word it is analogue to “GOTO’ instruction in HLL.

(ii) As opposite to this unconditional jump, there is conditional jump, which is characterized by
instructions such as JNZ, JNBE and many more. Compare these two instructions:

JMP 0FFF means jump to address 0FFF (h)


JNZ 0FFF JUMP NOT ZERO means if the previous instruction’s result was not zero,
then jump to address 0FFF (h). Else if the result is zero (condition is not
met ) then proceed with next line.

[ Note : There are 31 conditional jump instructions provided in 8088 microprocessor ]

.
2.0 A loop instruction using JNZ instruction
For example:

Mov cx,10
** ------
dec cx
jnz **

This is equivalent to:

Mov cx,10
** ------
loop **

5
Write an assembly language program to compute  2x
1
[ using JNZ ]

3.0 More Assembly Language Instructions

CMP AX,DX – Subtracts DX from AX (AX-DX), but does not store the result. Instead it sets
some flags.
JNBE 200 – “JUMP NOT BELOW NOR EQUAL “
If the previous instruction (for example, CMP AX, DX) resulted in a positive
value , then jump to the instructions at address 200.

1
Lab 3: Programming in Assembly Language

IF –ELSE

Since CMP is a subtraction operation, we can use CMP with a conditional jump instruction to
implement the IF-ELSE statement. We also can implement WHILE – DO loop programs as we
will see later.

3.1 Implimenting CMP and JNBE

Mov ax, value1


Mov bx, value2
Mov cx,1
Cmp ax,bx
Jnbe NEXT
Dec cx
NEXT inc cx

[ Note : You can count the address NEXT . The jump instruction takes 2 memories, and DEC takes 1]

Test the above program for


1. ax > bx
2. ax < bx .

If AX > BX,
AX is compared to BX. If JNBE evaluated to be true, only INC CX will be executed, and the value
of CX will be 2. If JNBE is false, both DEC CX and INC CX will be executed, and the value of CX
will be 1.

Now with the values of ax < bx, reverse the CMP instruction. What you observe?

Step 4
Write a program that counts the number of times a certain number appears in a range of memory.
(Hint: to compare two numbers, subtract the two numbers. If the numbers are equal, the
subtraction result will be zero. Then you can use JNZ.)

Questions:

1. What are flags? How many flags are available in 8088?


2. In CMP instructions, which flags are effected?
3. How can we implement While-Do loop by using CMP and jump instructions?
4. Describe the difference between a jump and call instructions.
5. The following program is known as delay loop . How many times does the JNZ DLY
instruction get executed?

Mov cx,100H
DLY: Dec cx
JNZ DLY
Next: ..... .

You might also like