-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_test.asm
101 lines (87 loc) · 1.17 KB
/
sample_test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# my quicksort
data segment
a DW 0003H, 0002H, 0009H, 0001H
ends
stack segment stack
ST DB 100 DUP(0)
TOP EQU 300
ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, TOP
mov si, offset a
mov di, 6
call quicksort
mov ax, 4c00h
int 21h
quicksort proc near
;partition ==> q
cmp si, di
jnb end_quicksort
push si
push di
call partition
pop di
pop si
cmp bx, 0
je quick2
push di
push bx
push si
mov di, bx
sub di, 2
call quicksort
pop si
pop bx
pop di
quick2:
push si
push bx
push di
mov si, bx
add si, 2
call quicksort
pop di
pop bx
pop si
end_quicksort:
RET
quicksort endp
partition proc near
; a, si, di
push ax
push si
mov bx, si
mov cx, di
sub cx, si
SHR cx, 1
s:
mov ax, [di]
cmp ax, [bx]
jb exchange
mov ax, [bx]
push [si]
pop [bx]
mov [si], ax
add si, 2
;change [bx] with [si]
exchange:
add bx, 2
loop s
;exchange [si] with [di]
mov ax, [di]
push [si]
pop [di]
mov [si], ax ;now si is the place of the partition place
mov bx, si
pop si
pop ax
RET
partition endp
ends
end start