You are on page 1of 3

Experiment No.

05

Objective: Learning how to manipulate with sequence of numbers in assembly


language. Comparison and jumps will be reviewed in this lab.

Lab Work:
Write an assembly program that finds the highest value in the following array of
numbers:

.MODEL SMALL
.DATA
GRADES DB 19H, 93H, 69H, 55H, 99H
HIGHEST DB ?

.CODE
MAIN: MOV AX,@DATA
MOV DS, AX
MOV BX, OFFSET GRADES
MOV CX, 05
YELLOW: MOV AL, [BX]
GREEN: CMP [BX], AL
JA YELLOW
INC BX
LOOP GREEN
MOV HIGHEST, AL
MOV AH,4CH
INT 21H
END MAIN

H.W. 2 (deadline: next lesson)


Write a program that finds the lowest value in the above numbers.

Reminder: 
The Processor Flags Register
The following diagram shows the location of the various flags in the processor status
register.

Flag Code When set(1) Code When Reset (=0)


OF overflow flag OV (overflow) NV (no overflow)

DF direction flag DN (down) UP (up)


IF interrupt flag EI (enable interrupt) DI (disable interrupt)
SF sign flag NG (negative) PL (plus, or positive)
ZF zero flag ZR (zero) NZ (not zero)
AF auxiliary carry flag AC (auxiliary carry) NA (no auxiliary carry)
PF parity flag PE (parity even) PO (parity odd)
CF carry flag CY (carry) NC (no carry)

Instruction Jump Condition Test


The following table lists the most common jump instructions and the tests they perform:

Instruction Jump Condition Test


JE Jump if Equal ZF=1
JNE Jump if Not Equal ZF=0
JG Jump if Greater (ZF=0) AND (SF=OF)
JGE Jump if Greater or Equal SF=OF
JL Jump if Less SF≠OF
JLE Jump if Less or Equal (ZF=1) OR (SF≠OF)

The following conditional branches are similar to the above but involve comparisons
which treat the operands as unsigned integers:

Instruction Jump Condition Test


JA Jump if Above (CF=0) AND (ZF=0)
JAE Jump if Above or Equal CF=0
JB Jump if Below CF=1
JBE Jump if Below or Equal (CF=1) OR (ZF=1)

Finally, the branches below specifically test flags:

Instruction Jump Condition Test


JO Jump on Overflow OF=1
JNO Jump on No Overflow OF=0
JC Jump on Carry CF=1
JNC Jump on No Carry CF=0
JS Jump on Sign (Negative) SF=1
JNS Jump on No Sign (Positive) SF=0
JZ Jump if Zero (same as JE) ZF=1
JNZ Jump if Not Zero ZF=0

You might also like