-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbleSort.asm
More file actions
50 lines (40 loc) · 866 Bytes
/
bubbleSort.asm
File metadata and controls
50 lines (40 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
ORG 100H
.data
arr DB 10 DUP(0)
length DW 0AH
;SI is i
;DI is j
.code
start:
LEA DI, arr
MOV CX, length
; read from the user
LEA DI, arr
MOV CX,10
read_loop:
MOV AH, 1
INT 21h
STOSB
LOOP read_loop
; Sort (bubble sort)
MOV CX, length
DEC CX
OuterLoop:
XOR SI, SI ;i
MOV DI, CX ;j
InnerLoop:
CMP SI, DI
JE outOFInnerLoop
MOV AL, arr[SI]
MOV BL, arr[SI + 1]
CMP AL, BL
JLE contiune ; No need to swap if AL <= BL
; Swap elements
MOV arr[SI], BL
MOV arr[SI + 1], AL
contiune:
INC SI
JMP InnerLoop
outOFInnerLoop:
LOOP OuterLoop
HLT