Lab 3 MP
Lab 3 MP
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.
(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:
.
2.0 A loop instruction using JNZ instruction
For example:
Mov cx,10
** ------
dec cx
jnz **
Mov cx,10
** ------
loop **
5
Write an assembly language program to compute 2x
1
[ using JNZ ]
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.
[ Note : You can count the address NEXT . The jump instruction takes 2 memories, and DEC takes 1]
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:
Mov cx,100H
DLY: Dec cx
JNZ DLY
Next: ..... .