Categories
- 4th semester (27)
- 5th semester (3)
- ADA (13)
- Assembly Level Language (12)
- BE (45)
- C Language Programming (5)
- C language (20)
- C++ Language (5)
- CCP Lab programing (3)
- Computer Programming Lab (3)
- DAA Lab Programming (13)
- Data Structure and C++ laboratory Program (6)
- Data Structure and C++ labotary Program (5)
- Design and Analysis of algorithm (14)
- First Year (5)
- MASM (12)
- Microprocessor (12)
- Microprocessor lab program (12)
- System Software & OS Laboratory (5)
- Unix program (4)
- bachelor of engineering (30)
- basic (1)
- basic mathematics (2)
- beginners (10)
- c++ program (9)
- calculations (7)
- computer science (30)
- downloadable (5)
- engineering syllabus (4)
- simple program (6)
Trend Posts
Blogger news
Author
Followers
Showing posts with label Bubble Sort. Show all posts
Showing posts with label Bubble Sort. Show all posts
Friday, February 21, 2014
ASSUME
DS: DATA,
CS: CODE
DATA SEGMENT ;
start of data segment
LIST
DB
12H,10H,04H,08H ; n
(4) number of elements stored in a LIST array
COUNT
DB 03H ; n-1
counter value stored in COUNT variable
DATA
ENDS ;
end
of data segment
CODE
SEGMENT ;
start
of code segment
START : MOV
AX, DATA ;
initializing the data segment
MOV DS, AX
XOR AX, AX ; clear
AX register content
MOV CL, COUNT ; store n-1 value (3) in CL register (outer loop count)
BACK2: MOV SI, OFFSET
LIST ; set the pointer to the 1st
location of LIST array
MOV BL, CL ; temporally
store the n-1 value in BL register (inner loop count)
BACK1: MOV AL, [SI] ;
get the 1st array element, ie. LIST [0]
to AL
INC SI ;
increment
the pointer by 1 to point to the next location
; ie: LIST[SI+1]
CMP AL, [SI] ; compare
AL with LIST[SI+1]
JB NEXT ;
if 1st
element is less than 2nd element then go to NEXT to
;
decrement the
inner loop count value in BL, to indicate one
;
comparison is
over.
XCHG [SI],
AL ; otherwise swap
the numbers.
MOV [SI-1],
AL
NEXT:
DEC BL ;
decrement
inner loop count value.
JNZ BACK1 ; if inner loop count value is not 0, then go to
BACK1 to
;
repeat the
comparison of remaining elements of LIST array.
LOOP BACK2 ; decrement the outer loop count
value in CL register
; (perform n-1 passes)
MOV AH, 4CH ;
terminate the program
INT 21H
CODE ENDS ;
end
of code segment
END
START
Output:
D:\MASM>
Masm 3a.asm;
D:\MASM>
Link 3a.obj;
D:\MASM>
TD 3a.exe
Then
press F7 to trace the program (line
by line execution).
Click on View
menu and select Dump to see the
output.
Subscribe to:
Posts (Atom)