forked from recluze/assembly-lang-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c06-01.asm
50 lines (33 loc) · 918 Bytes
/
c06-01.asm
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 0x100]
jmp start
data: dw 60, 55, 45, 50
swap: db 0
bubblesort:
dec cx
shl cx, 1 ; we will be jumping by 2 every time. So, *2
mainloop:
mov si, 0 ; use as array index
mov byte[swap], 0 ; reset swap flag for this iteration
innerloop:
mov ax, [bx + si]
cmp ax, [bx + si + 2]
jbe noswap
mov dx, [bx + si + 2]
mov [bx + si], dx
mov [bx + si + 2], ax
mov byte[swap], 1
noswap:
add si, 2
cmp si, cx
jne innerloop
cmp byte[swap], 1
je mainloop
ret ; notice this!!
start:
mov bx, data
mov cx, 4
; make a function call
call bubblesort
; data is now sorted!
mov ax, 0x4c00
int 0x21