-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.s
87 lines (65 loc) · 1.46 KB
/
main.s
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
.global _start
.section .data
str_size: .asciz "Tamanho do array: "
fmt_scanf: .asciz " %d"
fmt_printf: .asciz "Digite %d números:\n"
str_menu: .asciz "Selecione o algoritmo de ordenação:\n\t[1] Selection Sort\n\t[2] Bubble Sort\n\t[3] Heap Sort\n\t[4] Comb Sort\n> "
option: .int 0
size: .int 0
.section .text
_start:
// Selecionar algoritmo
pushl $str_menu
call printf
addl $4, %esp
pushl $option
pushl $fmt_scanf
call scanf
addl $8, %esp
// Ler tamanho
pushl $str_size
call printf
addl $4, %esp
pushl $size
pushl $fmt_scanf
call scanf
addl $8, %esp
// Ler números
pushl size
pushl $fmt_printf
call printf
addl $4, %esp
call alloc_array
addl $4, %esp
pushl %eax
pushl size
call input
switch_algo:
movl option, %eax
cmpl $1, %eax
je switch_selection
cmpl $2, %eax
je switch_bubble
cmpl $3, %eax
je switch_heap
cmpl $4, %eax
je switch_comb
jmp switch_end
switch_selection:
call selection_sort
jmp switch_end
switch_bubble:
call bubble_sort
jmp switch_end
switch_heap:
call heap_sort
jmp switch_end
switch_comb:
call comb_sort
switch_end:
call output
addl $4, %esp
call free
addl $4, %esp
pushl $0
call exit