Objective:: Computer Systems Engineering
Objective:: Computer Systems Engineering
Objective:: Computer Systems Engineering
Practical no.13
To become familiar with Conditional and unconditional Jump
Objective:
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. There job
is to compare the data values and make results according to logic specified. For
example,
This code takes BX value and then complements all the bits and stores the new
value to BX. So it stores 0F value in BX after executing NOT operation. For another
example,
AND operation performs bit by bit AND operation and then stores the value in first
operand. In upper code CX holds the final result.
OR operation performs bit by bit OR operation and then stores the value in first
operand. In upper code CX holds the final result. Similar case happens for XOR and
it is given below,
Test operation is a little different from AND operation. It performs bit by bit AND
operation but it does not change any operands value.
2
All the logical instructions stated above upgrades all the flag register values except
AF register. 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 0 (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.
Exercise Part 1:
(a) Program 1:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
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
(c) Program 3:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
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 obtained result.
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
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. 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,
SUB AX, BX
JZ L3T2
DIV BX
HLT
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 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,
Exercise Part 2:
(a) Program 1:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
SUB AX, BX
JMP L3T2
EEE316: DIV BX
JMP Last
AND AX, CX
TEST AX, BX
JMP EEE316
Last: HLT
CODE ENDS
END
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 1:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ADD AX, BX
JC L3T2
JNZ Last
SUB AX,CX
JZ EEE316
Last: HLT
CODE ENDS
END
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. Subtract 86B1H from 3F42H and store 0 in CX if overflow occurs and 1 if no
overflow occurs.