-
Notifications
You must be signed in to change notification settings - Fork 16
/
c06-02.asm
56 lines (36 loc) · 941 Bytes
/
c06-02.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
51
52
53
54
55
56
[org 0x100]
jmp start
data: dw 60, 55, 45, 50
swapflag: db 0
swap:
mov ax, [bx + si] ; this changes ax
xchg ax, [bx + si + 2]
mov [bx + si], ax
ret
bubblesort:
dec cx
shl cx, 1 ; This changes cx
mainloop:
mov si, 0 ; This changes si
mov byte[swapflag], 0
innerloop:
mov ax, [bx + si] ; This changes ax
cmp ax, [bx + si + 2]
jbe noswap
call swap ; another call here
mov byte[swapflag], 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