002 Mpmctermwork
002 Mpmctermwork
Assembly language provides very low-level control over the CPU and memory, which allows the
program to:
Step-by-Step Breakdown:
1. Concept:
o You’ll input a string of bytes.
o The program will sort the bytes using a simple algorithm like bubble sort.
o The sorted result will be displayed in both ascending and descending order.
2. Registers Used:
o SI (Source Index) and DI (Destination Index) will point to memory locations.
o CX will be used as a loop counter.
o AX, BX for temporary data storage.
o AL, BL for byte-wise comparison.
3. Assumptions:
o The string is stored in memory starting at a certain address.
o The string length is known and will be stored in a register.
.MODEL SMALL
.STACK 100H
.DATA
string DB 'HELLO' ; Input string to be sorted
length DW $ - string ; Calculate the length of the string
sortedAsc DB 5 DUP(0) ; To store the ascending sorted result
sortedDesc DB 5 DUP(0) ; To store the descending sorted result
.CODE
MAIN PROC
; Set up the data segment
MOV AX, @DATA
MOV DS, AX
; Now copy the ascending sorted result to sortedDesc for descending sorting
LEA SI, sortedAsc
LEA DI, sortedDesc
MOV CX, length
COPY_DESC:
MOV AL, [SI]
MOV [DI], AL
INC SI
INC DI
LOOP COPY_DESC
• We first copy the input string string to a buffer sortedAsc for ascending sorting.
Bubble Sort:
• We use two loops: the outer loop to control the number of passes and the inner loop to
compare and swap the elements.
• CMP is used to compare two adjacent bytes. If they are in the wrong order, we swap them.
Descending Order:
• After sorting in ascending order, the array is reversed to get the descending order.
This is a simple and efficient way to implement sorting in assembly for the 8086 microprocessor.
ABSTRACT
The Intel 8086 microprocessor, introduced in 1978, marked a significant advancement
in computer architecture. As a 16-bit microprocessor, it was capable of addressing up
to 1 MB of memory through its unique segmented memory model, which divides
memory into segments (code, data, stack, and extra). This segmentation allows
programs to utilize memory more efficiently and simplifies the management of large
codebases.
The 8086 features a comprehensive instruction set that supports arithmetic, logical,
and control flow operations, enabling complex computations and robust programming
capabilities. It operates with a maximum clock speed of 10 MHz and employs a
multiprocessing architecture, which allows multiple processors to operate
concurrently, thereby enhancing computational power and efficiency
This assembly language program for the 8086 microprocessor sorts a string of
characters in both ascending and descending order using the bubble sort algorithm.
The program leverages the 8086's segmented memory model to organize the data and
code, efficiently manipulating memory and registers. The string is first copied into a
buffer, preserving the original, and then sorted based on the ASCII values of the
characters. Key 8086 instructions such as LOOP, CMP, and conditional jumps control
the sorting process, while the SI and DI registers are used to index memory for
comparison and swapping.
After sorting the string in ascending order, the program reverses the result for
descending order. The program terminates using a DOS interrupt, showcasing low-level
CPU control and memory management typical in assembly language. This project
demonstrates fundamental concepts of assembly programming, including register
manipulation, memory segmentation, string handling, and sorting algorithms,
providing a practical example of working with low-level system instructions.