You are on page 1of 13

LAB ASSIGNMENT-3

MICRO PROCESSORS AND MICRO CONTROLLERS

SLOT: L55+L56

DATE: 02-04-2021

NAMES OF STUDENTS :

I. N. Sai Likhitha -19BCT0004


II. Ch.Tharun Tej -19BCT0015
III. Likhitha Modugula -19BCT0032
IV. Shreyas Guduri -19BCT0046

SUBMITTED TO FACULTY:
Naresh.K
ASCENDING ORDER USING BUBBLE SORT

Sample input and output:


Count – 04H
The inputs are:53H 25H 19H 02H

Iteration-1:
53H 25H 19H 02H
25H 53H 19H 02H
25H 19H 53H 02H
25H 19H 02H 53H

Iteration-2:

19H 25H 02H 53H


19H 02H 25H 53H

Iteration-3:

02H 19H 25H 53H


Instructions Used:
XOR: Operation between bits of source and destination operands.
MOV: moves data from one location to another.
DEC: Used to decrement the provided byte/word by 1.
CMP: Compares two operands.
JLE: Jump less than or equal
XCHG: exchanges the content of a register with the content of another register
or with the content of memory location.
INC: adds one to the destination operand.
JNZ: Jump no zero
Pseudo code:
1.first we have an array of four elements,we maintain a inner and an outer loop
for the ascending order.here,we have 4 elements,so we will do n-1
operations,and then n-2 operations till the value is 1
2.Decrease the count by 1.
3.Again travel from starting memory location to (last-1, by help of count) and
compare two numbers if first number is greater than second number then
swap them.
4. Second iteration fix the position for last two numbers.
5.Repeat till the count becomes 0.

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

You might also like