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

MP Exp9 - Largestarray Lab Manual

The document describes an experiment to write an assembly language program that finds the largest number in an array, using instructions like CMP to compare values, LOOP to repeatedly execute code, and conditional jumps to transfer control flow based on conditions; it provides theory on how these instructions work and includes a flow chart, program listing, and results storing the largest value in memory.

Uploaded by

soniathalavoor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

MP Exp9 - Largestarray Lab Manual

The document describes an experiment to write an assembly language program that finds the largest number in an array, using instructions like CMP to compare values, LOOP to repeatedly execute code, and conditional jumps to transfer control flow based on conditions; it provides theory on how these instructions work and includes a flow chart, program listing, and results storing the largest value in memory.

Uploaded by

soniathalavoor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Computer Engineering

Academic Year: 2020-2021 Semester: IV


Class / Branch: SE Computer Subject: Microprocessor Lab

Experiment No. 9

1. Aim: Write an Assembly program to find largest number from a given array.

2. Hardware used: DYNA-86L Kit ,SMPS,Keyboard

3. Theory :-
Microprocessor 8086 can compare two numbers by using CMP instruction. This instruction compares
a byte / word in the specified source with a byte / word in the specified destination. The source can be
an immediate number, a register, or a memory location. The destination can be a register or a memory
location. The comparison is actually done by subtracting the source byte or word from the destination
byte or word. The source and the destination are not changed, but the flags are set to indicate the
results of the comparison. AF, OF, SF, ZF, PF, and CF are updated by the CMP instruction.
For the instruction CMP BX, CX, the values of CF, ZF, and SF will be as follows:
CMP BX, CX
CF ZF SF
BX = CX 0 1 0
BX > CX 0 0 0
BX < CX 1 0 1

In assembly language programing set of instructions can be executed n number of times using “LOOP
label” instruction.
LOOP label
This instruction is used to repeat a series of instructions some number of times. The number of times
the instruction sequence is to be repeated is loaded into CX. Each time the LOOP instruction executes,
CX is automatically decremented by 1. If CX is not 0, execution will jump to a destination specified
by a label in the instruction. If CX = 0 after the auto decrement, execution will simply go on to the
next instruction after LOOP. The destination address for the jump must be in the range of –128 bytes
to +127 bytes from the address of the instruction after the LOOP instruction.

Suppose following set of instructions need to be execute 5 times using assembly instructions then
LOOP label instruction is useful.
To execute set of instruction five times, load CX register with 0005, use LOOP instruction to decrease
CX counter value by 1 and monitor its value. If CX value is not equal to zero then control will jump to
BACK label/address. Once CX reaches to zero, control will execute very next instruction after LOOP
BACK.

Conditional jump
If some specified condition is satisfied in conditional jump, the control flow is transferred to a target
instruction.
CMP AL, [BX]
JC LABEL
If, after a compare or some other instructions which affect flags, the carry flag is 1, this instruction
will cause execution to jump to a label given in the instruction. If CF is 0, the instruction will have no
effect on program execution.

Flow Chart for finding Smallest Number Flow Chart for finding Largest Number
4.Program :

MOV BX, 3000H ;Load BX with 3000H


MOV AL, [BX] ;Transfer data from memory to AL register
MOV CX, 0007H ;Load counter with 07.
BACK: INC BX ;Increment BX register to point memory location
CMP AL, [BX] ;Compare two data bytes
JNC NEXT ;If AL is greater then jump to NEXT
MOV AL, [BX] ;If AL is smaller then load AL with greater number
NEXT LOOP BACK ;Repeat until CX is not zero
MOV [3008], AL ;Store largest number in one of memory location
INT 3

Result:
Location Data bytes
3000H 65 24 46 86 64 02 45 75
3008H 02 00 00 00 00 00 00 00

5. Conclusion :

You might also like