-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPROC_Sort.asm
63 lines (49 loc) · 1.11 KB
/
PROC_Sort.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
TITLE MASM Template (main.asm)
INCLUDE Irvine32.inc
.data
Sequence DD 132, 159, -16, 137, 6, 14, 67, -3, 0, 98, 45, 842, -12, -63, 48, 1180, -1500, 9999
.code
Comment /* Sorts Sequence to ascending sequence. */
Sort PROC USES eax ebx edi esi
mov esi, lengthOf Sequence - 1
MainSortLoop:
mov edi, 0 ;iter for Sequence
mov bl, 0 ;bool wasSwap = False
Sorting:
mov eax, Sequence[edi * 4]
inc edi
cmp eax, Sequence[edi * 4]
jle IsSmaller
xchg eax, Sequence[edi * 4] ;swap values
dec edi
mov Sequence[edi * 4], eax
inc edi
mov bl, 1 ;wasSwap = Ture
IsSmaller:
cmp edi, esi ;goes through whole Sequence
jb Sorting
cmp bl, 1 ;if (wasSwap == True) repeat
je MainSortLoop
ret
Sort ENDP
Comment /* Writes Sequence separated with white space. */
WriteSequence PROC USES eax edx edi
mov esi, 0 ;iter
WriteDown:
mov eax, Sequence[esi * 4]
call WriteInt
mov al, ' '
call WriteChar
inc esi
cmp esi, lengthOf Sequence
jb WriteDown
call Crlf
ret
WriteSequence ENDP
main PROC
call WriteSequence
call Sort
call WriteSequence
exit
main ENDP
END main