0% found this document useful (0 votes)
111 views

Lab 2 - Intel 8086 Microprocessor: Logical Instructions and Jump Commands in Assembly Language

This document provides instructions for Lab 2 of the Microprocessors and Interfacing Laboratory course, which focuses on logical instructions and jump commands in Intel 8086 assembly language. Students will write simple programs using logical operations like AND, OR, XOR as well as unconditional and conditional jump commands. The lab objectives are to practice using these instructions in assembly language programs and observe how they work.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views

Lab 2 - Intel 8086 Microprocessor: Logical Instructions and Jump Commands in Assembly Language

This document provides instructions for Lab 2 of the Microprocessors and Interfacing Laboratory course, which focuses on logical instructions and jump commands in Intel 8086 assembly language. Students will write simple programs using logical operations like AND, OR, XOR as well as unconditional and conditional jump commands. The lab objectives are to practice using these instructions in assembly language programs and observe how they work.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Independent University, Bangladesh (IUB)

School of Engineering and Computer Science


Department of Electrical and Electronic Engineering

Spring 2016

COURSE CODE : ECR 209L


COURSE NAME : Microprocessors and Interfacing Laboratory
CREDIT : 1
COURSE TEACHER : Dr. Mustafa Habib Chowdhury

LAB 2 – Intel 8086 Microprocessor: Logical


Instructions and Jump Commands in Assembly
Language

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.

These commands are explained below.

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,

MOV BX, 30H; In binary 110000


NOT BX; In binary 001111

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,

MOV BX, 70H ; In binary 1110000


MOV CX, 40H ; In binary 1000000
AND CX, BX ; In binary 1000000

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.

MOV BX, 70H ; In binary 1110000


MOV CX, 40H ; In binary 1000000
OR CX, BX ; In binary 1110000
3
OR operation performs bit by bit OR operation and then stores final result in first operand. In
upper code the CX register is the final operand and holds the final result. Similar case
happens for XOR and it is given below,

MOV BX, 70H ; In binary 1110000


MOV CX, 40H ; In binary 1000000
XOR CX, BX ; In binary 0110000

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,

MOV BX, 70H ; In binary 1110000


MOV CX, 40H ; In binary 1000000
TEST CX, BX ; In binary CX value is 1000000

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.

MOV BX, 70H ; In binary 1110000


MOV CX, 40H ; In binary 1000000
AND CX, BX ; In binary 1110000

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

Observe the content of the CX register. What operation happened here?

(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.

MOV AX, 3254H


MOV BX, 1F4BH
MOV CX, 412AH
ADD AX, CX
JMP L3T2
SUB AX, BX
L3T2: AND AX, BX
HLT

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,

MOV AX, 125BH


MOV BX, 125BH
MOV CX, 412AH
SUB AX, BX
JZ L3T2
NOT CX

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:

Write following codes and perform indicated operations.

Write following codes and perform indicated operations.

(a) Program 1:

MOV AX, 7A24H

MOV BX, 15A3H

SUB AX, BX

JMP L3T2

EEE316: DIV BX

JMP Last

L3T2: MOV CX, 45B1H

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:

MOV AX, 7A24H


MOV BX, 95A3H
ADD AX, BX
JC L3T2
EEE316: OR AX, 23H
JNZ Last
L3T2: MOV CX, 0FC7H
SUB AX,CX
JZ EEE316
Last: RET

Update the register values in every step.

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.

2. Take 2 arbitrary numbers x and y. If x>1000H perform x+y. If x<1000H


perform x-y. Store the result in DX.

10

You might also like