Lab 2 - Intel 8086 Microprocessor: Logical Instructions and Jump Commands in Assembly Language
Lab 2 - Intel 8086 Microprocessor: Logical Instructions and Jump Commands in Assembly Language
Spring 2016
1
2
Objective:
• Using logical instructions in assembly language.
• Incorporating Jump commands in assembly programs.
• Writing simple assembly language programs with logical and Jump instructions.
Introduction:
Both logical instructions and Jump commands are widely used in assembly language.
Logical instructions:
Logical instructions include NOT, AND, OR, XOR, TEST etc. instructions. Their job is to
compare the data values and make results according to logic specified. For example,
This code takes a value into the register BX and then complements all the bits of the entered
value and stores the new value ALSO to BX. So it stores 0Fh value in BX after executing
NOT operation. In another example,
AND operation performs bit by bit AND operation of the contents of register BX and CX and
then stores the final result in the CX register.
The TEST operation is a little different from the AND operation. It performs bit by bit AND
operation between the two operands but it does not change any operands value. For
example,
All the logical instructions stated above upgrades all the flag register values except AF
(Auxilliary Flag). NOT command does not effect any flags. How flags are affected is stated
below.
After this operation Zero Flag is 0 (ZF = 0; as the value of CX is not 0), Carry Flag is 0 (CF =
0; as there is no carry), Parity Flag is 0 (PF = 0; as there are odd number of 1’s), Sign Flag is
1 (SF = 1), Overflow Flag is 0 (OF = 0; as there is no overflow). In this all the flags can be
determined.
Do not confuse yourself with semicolon given after each line in assembly codes above.
Comments are written after semi colon ‘;’ in assembly language.
4
Exercise Part 1:
Write following codes and perform indicated operations.
(a) Program 1:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
MOV BX, 3256H
MOV CX, 1554H
AND CX, BX
HLT
CODE ENDS
END
(b) Program 2:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
MOV BX, 3256H
MOV CX, 1554H
XOR CX, BX
HLT
CODE ENDS
END
5
Observe content of CX register. What operation happened here?
(c) Program 3:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
MOV AX, 1027H
MOV BX, 5A27H
MOV CX, 54A5H
OR AX, BX
XOR AX, CX
NOT AX
TEST CX, BX
AND CX, AX
HLT
CODE ENDS
END
Perform this operation in single step mode and write the values of registers for every step.
Obtain binary values for upper hexadecimal values and perform bit by bit operation for every
step. Compare your hand calculation with the obtained simulation result.
6
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.
In this example L3T2 is a level. As we can see in fifth line JMP command is used. It makes
the program to go from fifth line to L3T2 level that is seventh line. So sixth line is not
executed.
There are two types of Jump commands. These are (i) Conditional Jump and (ii)
Unconditional Jump. The previous example is an unconditional jump. Conditional Jumps
are like IF-ELSE statements and requires a specific condition to be met in order to execute
the Jump command. For example, if some flags are affected only then these conditional jump
instructions are executed. We can look at the following example,
7
L3T2: AND AX,CX
HLT
Clearly observe the code. In the 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 L3T2 is
written. It means if ZF = 1 then go to L3T2:. Otherwise continue. As ZF = 1, program moves
to eighth line. This is a conditional Jump. Some other conditional jumps are JG, JL, JNZ, JE,
JGE, JLE etc.
Exercise Part 2:
(a) Program 1:
SUB AX, BX
JMP L3T2
EEE316: DIV BX
JMP Last
AND AX, CX
TEST AX, BX
JMP EEE316
Last: HLT
8
Perform this operation in single step mode and write the values of registers for
every step. Explain why we need ‘Last’ termed level? What will happen if it is not
used?
(b) Program 2:
9
Home Task:
1. Write an assembly code that will determine whether a number is greater than
5 or equal of less, and put 0 or 1 or 2 for the conditions in DX.
10