Professional Documents
Culture Documents
SLOT: L55+L56
DATE: 02-04-2021
NAMES OF STUDENTS :
SUBMITTED TO FACULTY:
Naresh.K
ASCENDING ORDER USING BUBBLE SORT
Iteration-1:
53H 25H 19H 02H
25H 53H 19H 02H
25H 19H 53H 02H
25H 19H 02H 53H
Iteration-2:
Iteration-3:
PROGRAM CODE:
.model small
.stack 64
.data
List DW 53h, 25h, 19h, 02h
Count EQU 04h
.code
start:Mov AX,@data
Mov DS,AX
Mov DX,Count-1
Again0:Mov CX,DX
Lea SI,List
Again1:Mov AX,[SI]
Cmp AX,[SI+2]
JL PR1
XCHG [SI+2],AX
XCHG [SI],AX
PR1:ADD SI,02h
Loop Again1
DEC DX
JNZ Again0
Mov AH,4Ch
int 21h
end
end start
Result:
Video link:
https://drive.google.com/file/d/1qfSqVezhL2NvNcd3cM9MqbyA0vWkbG-
f/view?usp=sharing
Largest and smallest number
Sample input and output:
Count=6
Sample input: 5,2,1,6,4,3
After executing the value at the AX register is 0206 where 02 refers to the
smallest number and 06 refers to the largest value.
OUTPUT: SMALLEST:01 AND LARGEST:06
Instructions Used:
MOV: moves data from one location to another.
DEC: Used to decrement the provided byte/word by 1.
CMP: Compares two operands.
LEA: is a shift-and-add instruction.
JNC: Jump if not carry
JC: Jump if carry
JNZ: Jump no zero
Pseudo code:
1. First take the input and store it in a register and set sequence counter
for finding greatest number
2. Then after we need to compare it with the next input if it is greater
than or equal it moves to next step and sequence counter increases. If it
less than the next input they both get swapped i.e. next input is
transferred to the register and value stored in register to next input and
the sequence counter increases and next same continues till the
sequence counter becomes n-1
3. Similarly, for finding smallest number we need to compare the value
stored in register with the next input if it is less than or equal it moves to
next step and sequence counter increases. If it greater than the next
input they both get swapped i.e. next input is transferred to the register
and value stored in register to next input and the sequence counter
increases and same continues till the sequence counter becomes n-1
4. Now we see the values of both largest and smallest at AX register.
PROGRAM CODE:
.MODEL SMALL
.STACK 64
DATA SEGMENT
A DB 5,2,1,6,4,3
B DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV CX,0000
MOV CL,06
LEA BX,A
MOV AL,00
MOV AH,BYTE PTR[BX]
L1:CMP AL,BYTE PTR[BX]
JNC L2
MOV AL,BYTE PTR[BX]
L2:CMP AH,BYTE PTR[BX]
JC L3
MOV AH,BYTE PTR[BX]
L3:INC BX
DEC CL
CMP CL,00
JNZ L1
INT 21H
CODE ENDS
END START
Result:
Video link:
https://drive.google.com/file/d/1FsFbGuGtYyNqvwfSl1ZKPHHnAAdKXVt3/view
?usp=sharing