Professional Documents
Culture Documents
20bce2164 Micro Lab Da4
20bce2164 Micro Lab Da4
LAB ASSIGNMENT – 4
NAME: Karthik Chidurala
Reg No: 20BCE2164
LOOP2:
MOV AL,[SI]
INC SI
CMP AL,[SI]
JC LOOP1
XCHG AL,[SI]
XCHG [SI-1],AL
LOOP1:
DEC CH
JNZ LOOP2
DEC CL
JNZ LOOP3
HLT
Input:
SI pointing at 1200h
Code:
;Descending order code
MOV SI,1200h
MOV CL,[SI]
DEC CL
LOOP3:
MOV SI,1200h
MOV CH,[SI]
DEC CH
INC SI
LOOP2:
MOV AL,[SI]
INC SI
CMP AL,[SI]
JC LOOP1
XCHG AL,[SI]
XCHG [SI-1],AL
LOOP1:
DEC CH
JNZ LOOP2
DEC CL
JNZ LOOP3
HLT
Input:
Input: size of array=4 and array=01,02,03,04
Output:
Code written in emu8086:
3. Find the smallest number in an array
Algorithm:
1. Take array input as 8,14,5,10,15
2. Initialize res
3. Move array to AX register
4. Set count as 4
5. Set bl as 79h (A very high number)
6. Store the array element to AL
7. Compare AL and BL, if AL<BL then set BL=AL
8. Decrement counter, if not 0 then go to step 6
Code:
;Smallest number
data segment
STRING1 DB 08h,14h,05h,0Fh,09h
res db ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
mov cx, 04h
Output:
SI at the end of all the iterations will be set to 4 which indicates the
end of the array
Code written in emu8086:
4. Find the largest number in an array
Algorithm:
1. Take array input as 8,14,5,3,9
2. Initialize res
3. Move array to AX register
4. Set count as 4
5. Set bl as 79h (A very high number)
6. Store the array element to AL
7. Compare AL and BL, if AL>BL then set BL=AL
8. Decrement counter, if not 0 then go to step 6
Code:
;largest number
data segment
STRING1 DB 08h,14h,05h,03h,09h
res db ?
data ends
code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 04h
mov res,bl
int 3
code ends
end start
Output: