Professional Documents
Culture Documents
Lab: 4
Section: BSCS
dd
Department: CS
Subject: Computer organization & Assembly Time Allowed:
Instructor: Engr. Shahid Mehmood Total Marks: 10
Instructions:
Name: ___________________
1. Attempt all questions.
Roll No: _________________ 2. Time management is the key to so success.
Flags x x x x OF DF IF TF SF ZF x AC x PF x CY
We can divide the flag bits into two sections. The Status Flags, and the Control Flags.
Status Flags:
There are 6 status flags in microprocessor 8086
Control Flag:
In 8086 there are 6 different flags which are set or reset after 8-bit or 16-bit operations.
These flags and their functions are listed below.
Flag Bit Function
SF After any operation if the MSB is 1, then it indicates that the number is
negative. And this flag is set to 1
ZF If the total register is zero, then only the Z flag is set to 1 otherwise zero
PF If the number of ones in the result are even, then parity flag is equal to 1.
If the number of ones in the result are odd, then parity flag is equal to 0.
DF This is directional flag. This is used in string related operations. D = 1, then the
string will be accessed from higher memory address to lower memory address,
and if D = 0, it will do the reverse.
IF This is interrupt flag. If I = 1, then CPU will recognize the interrupts from
peripherals. For I = 0, the interrupts will be ignored
TF This trap flag is used for on-chip debugging. When T = 1, it will work in a single
step mode. After each instruction, one internal interrupt is generated. It helps to
execute some program instruction by instruction.
1
Unconditional jump
Syntax:
Jump label name
Example:
main proc
Label1:
Move dl, ‘A’
Move ah,2
Int 21h
Jump Label1
Main endp
2
Conditional jump
A jump instruction using any condition
Let us discuss the CMP instruction before discussing the conditional instructions.
CMP Instruction:
Compare the destination operand to the source operand.
Subtract the source from destination and does not change the value
of source and destination.
Affects the flag register values
Syntax
CMP DESTINATION, SOURCE
CMP compares two numeric data fields. The destination operand could be either in
register or in memory. The source operand could be a constant (immediate) data,
register or memory.
Example
CMP reg, reg cmp dl, al
CMP reg, constant cmp de, 3
CMP reg, [memory address] cmp dl,[SI]
CMP is often used for comparing whether a counter value has reached the number of
times a loop needs to be run. Consider the following typical condition −
INC EDX
CMP EDX, 10 ; Compares whether the counter has reached 10
JLE LP1 ; If it is less than or equal to 10, then jump to LP1
Unconditional Jump
As mentioned earlier, this is performed by the JMP instruction. Conditional execution
often involves a transfer of control to the address of an instruction that does not follow
the currently executing instruction. Transfer of control may be forward, to execute a new
set of instructions or backward, to re-execute the same steps.
Syntax
The JMP instruction provides a label name where the flow of control is transferred
immediately. The syntax of the JMP instruction is −
JMP label
Example
The following code snippet illustrates the JMP instruction −
MOV AX, 00 ; Initializing AX to 0
MOV BX, 00 ; Initializing BX to 0
MOV CX, 01 ; Initializing CX to 1
L20:
ADD AX, 01 ; Increment AX
ADD BX, AX ; Add AX to BX
SHL CX, 1 ; shift left CX, this in turn doubles the CX value
JMP L20 ; repeats the statements
Conditional Jump
If some specified condition is satisfied in conditional jump, the control flow is transferred
to a target instruction. There are numerous conditional jump instructions depending
upon the condition and data.
Following are the conditional jump instructions used on signed data used for arithmetic
operations −
Following are the conditional jump instructions used on unsigned data used for logical
operations −
Example:
.model small
.stack 100h
.data
msg1 db 10,13, “Enter the first number: $”
msg2 db 10,13, “Enter the second number:$”
msg3 db 10,13, “Numbers are equal$”
msg4 bd 10,13, “Numbers are not equal$”
.code
Main proc
Mov ax, @data
Mov dx,ax
mov cl,al
Mov ah,1
Int 21h
Mov dl,al
Cmp dl, cl
Je Lablel1
Mov dx offset msg4
Mov ah,9
Int 21h
Label 1:
Mov dx, offset msg3
Int ah,9
Int 21h
Main endp
End main
Task
Q 1:
Write a program in which you get any two input from user and perform task (addition, subtraction,
multiplication and division) using jump command.
main:
mov AH,02H
mov CX,26
mov DL, 'A'
Label1:
cmp DL, 'A'
add DL, 01H
int 21H
mov DL, 0DH
mov DL, 0AH
int 21H
cmp DL, 'Z'
je Next
jmp Label1
Next:
mov AH,4CH
int 21h
mov ax,numB
mov bx,3
imul bx ;Multiply bx (3) by ax (B)
add ax,6 ;Add 6 to the above
mov bx,numX
add bx,numD ;Add X + D
idiv bx ;Divide bx (X + D) by ax ((B * 3) + 6)
mov res,ax ;Set ax as result
int 21h
;Display Result
mov ax,@data
mov ds,ax ;set DS to point to the data segment
lea dx,ResPrompt ;get ResPrompt
mov ah,09h ;display string function
int 21h ;display "A = "
mov ax,@data
mov ds,ax ;set DS to point to the data segment
lea dx,res ;get result
mov ah,09h ;display string function
int 21h ;display result
References:
https://www.tutorialspoint.com/instruction-cycle-in-8085-microprocessor