-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
63 lines (52 loc) · 928 Bytes
/
main.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
WriteFile proto
ExitProcess proto
.data
;N=16 Random
array db 0,5,13,12,7,14,10,9,15,8,3,4,6,11,2,16,1,-1
;N=16 Best Case
;array db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,-1
;N=16 Worse case
; array db 16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,-1
;binary search
;linear search
.code
main proc
mov rax, -1
lea rbx, array
mov rdx, 0
;Find the size of the array
findSizeLoop:
inc rax
mov dh, [rbx+rax]
cmp dh, -1
loopne findSizeLoop
;Bubble sort
dec rax
bubbleSortOuter:
mov rcx,rax
mov rsi, 0
bubbleSortInner:
mov dh, [rbx+rsi]
mov dl, [rbx+rsi+1]
;COMPARE
cmp dh, dl
jg swap
postSwap:
inc rsi
loop bubbleSortInner ; prob a compare here too with loops/rcx
dec rax
mov rcx, rax
inc rcx
loop bubbleSortOuter
;done sorting
jmp done
swap:
;SWAP
mov [rbx+rsi], dl
mov [rbx+rsi+1], dh
jmp postSwap
done:
nop
call ExitProcess
main endp
end