EEE 3216 Experiment 03
EEE 3216 Experiment 03
Experiment No. 03
Name of the Experiment: Introduction to JMP and LOOP Instructions in Assembly Language
A. Objectives
The objectives of this experiment are to
1. Understand the functionality of the JMP and LOOP instructions in assembly language.
2. Learn how to implement loops and jumps in assembly programs.
3. Observe the behavior of the program flow using JMP and LOOP instructions.
B. Theory
JUMP Commands:
Sometimes it is necessary to go from one line of program to another line without executing some
intermediate lines. For this Jump commands are used. We can explain this with a simple example.
MOV AX,3254H
MOV BX,1F4BH
MOV CX,412AH
ADD AX, CX JMP
S7
SUB AX, BX
In this example S5 is a level. As we can see in fifth line JMP command is used. It makes the
program to go from fifth line to S7 level that is seventh line. So sixth line will not be executed.
There are two types of Jump commands. These are (i) Conditional jump and (ii) Unconditional
Jump. Previous example is an unconditional jump. Conditional Jumps are like if statements. If
some flags are affected only then these jump instructions executed. We can look at the following
example,
MOV AX,125BH
MOV BX,125BH
MOV CX, 412AH
SUB AX, BX
JZ S5
DIV BX
Clearly observe the code. In fourth line subtraction operation is performed. As both AX and BX
have same value. Their subtracted value is 0. So ZF is set to 1. In fifth line JZ S5 is written. It
means if ZF = 1 then go to S5, otherwise continue. As ZF = 1, program moves to seventh line. This
is a conditional Jump. Some other conditional jumps are listed below.
MNEMONIC CONDITION TESTED "JUMP IF ... "
JA/JNBE (CF or ZF)=O above/not below nor equal
JAE/JNB CF=O above or equal/not below
JB/JNAE CF=l below/not above nor equal
JBE/JNA (CF or ZF)= 1 below or equal/not above
JC CF=l carry
JE/JZ ZF=l equal/zero
JG/JNLE ((SF xor OF) or ZF) = 0 greater/not less nor equal
JGE/JNL (SF xor OF)=O greater or equal/not less
JL/JNGE (SF xor OF) = 1 less/not greater nor equal
JLE/JNG ((SF xor OF) or ZF) = 1 less or equal/not greater
JNC CF=O not carry
JNE/JNZ ZF=O not equal/not zero
JNO OF=O not overflow
JNP/JPO PF=O not parity/parity odd
JNS SF=O not sign
JO OF=l overflow
JP/JPE PF= 1 parity/parity equal
JS SF= 1 sign
JCXZ CX=0 Register cx = 0
Note: "above" and "below" refer to the relationship of two unsigned values;
"greater" and "less" refer to the relationship of two signed values.
Program 1:
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 1000H
JC IIUC
JZ EEE
LAST: HLT
CODE ENDS
END
Shift and Rotate commands are used to convert a number to another form where some bits are shifted or
rotated. The basic difference between shift and rotate is that the shift command makes “fall off” bits at the
end of the register. Where rotate command makes “Wrap around” at the end of the register. There are both
arithmetic (SAL and SAR) and logical (SHL and SHR) shift instructions. Graphical operations for these
commands are shown below.
Some simple codes can be given to clarify the idea.
MOV CL,03H ;
In this procedure, SHR commands inserts 0’s from left side. Each time a 0 is inserted right most bit
is vanished from register content.
MOV CL,03H ;
In this procedure, SAR command inserts MSB content from left side. Each time it is inserted right
most bit is vanished from register content.
MOV CL,03H ;
In this case, ROR instruction picks up the LSB and inserts it as MSB and so on.
Program 2:
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 1000H
MOV AX,0055H
MOV DX,0505H
MOV CL, 3
SAL AX,CL
SAR DX,CL
MOV CL, 2
ROR AX,CL
ROL DX,CL
STC
RCL AL, CL
RCRDX,CL
HLT
CODE ENDS
END
C. Apparatus Required
1. 8086 microprocessor kit.
2. Assembler “MASM” and loader “LOD186”.
3. WinComm.
D. Procedures
1. Write the program 1 in notepad and save the file as “filename.asm”. Place this file in the
folder where “masm.exe” exists.
2. Go to command prompt and execute “masm.exe”. You will see the following
message –
Microsoft (R) Macro Assembler Version 5.10
Copyright (C) Misrosoft Corp 1981, 1988. All right reserved.
3. Follow the procedure given below to prepare machine code for your program:
Source filename [.ASM]: filename Press ENTER
5. Follow the procedure given below to prepare HEX (ABS) file for your program:
Object/Command File [.OBJ]: filename Press ENTER
**LOAD COMPLETE
7. Open the “Wincomm” window. Press “L” then “Enter”. You will see the following
message:
8. Strike PgUp or F3 key of your keyboard. A new window will appear. Locate the
“filename.ABS” file and open it.
9. You will observe that file download has started. A message like the following one will
be shown:
:14100000B800008ED88EC0BB00208B078A6F028A4F038BEBB6
:101014003E8B5604268B76068B7E088B1E0A20CCCC
:0E20000012345678ABCDF0146853B1C41020E2
:00000001FF
OK completed !!
10. After loading the program, execute it in single step mode. Fill up the data table and
verify the results.
11. Follow procedures 1 to 10 for program 2.
E. Experimental Table :
Program-1
Offset Instruction / Set Flag
AX BX CX DX IP
Address Mnemonics Bit(s)
Initial Status
ADD AX, BX
JC IIUC
EEE:
OR AX, 23H
JNZ LAST
IIUC:
MOV CX, 0FC7H
SUB AX,CX
JZ EEE
LAST:
HLT
Program 2:
F. Report:
Discuss the effects of each instruction/ mnemonics that are used in this program.
G. References:
1. User’s manual of MDA-8086 microprocessor kit, Midas Engineering.
2. “Assembly Language Programming and Organization of the IBM PC”, Ytha Yu and Charles Marut,
Mitchell McGraw-Hill.
1