-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathasm.snippets
195 lines (154 loc) · 2.55 KB
/
asm.snippets
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
snippet scode Start basic code for assembly
.data
.text
.global main
main:
snippet scodes Start basic code for assembly with _start label
.data
.text
.globl _start
_start:
snippet lo Long
$1: .long $2
snippet wo Word
$1: .word $2
snippet by Byte
$1: .byte $2
snippet sp Space
$1: .space $2
snippet ai Ascii
$1: .ascii "$2"
snippet az Asciz
$1: .asciz "$2"
snippet ze Zero
$1: .zero "$2"
snippet qu Quad
$1: .quad "$2"
snippet si Single
$1: .single "$2"
snippet do Double
$1: .single "$2"
snippet fl Float
$1: .single "$2"
snippet oc Octa
$1: .single "$2"
snippet sh Short
$1: .single "$2"
snippet exit0 Exit without error
movl \$1, %eax
xorl %ebx, %ebx
int \$0x80
snippet exit Exit with error
mov \$1, %eax
mov $1, %ebx
int \$0x80
snippet readfstdin Read fixed length text from stdin
mov \$3, %eax
mov \$2, %ebx
mov $1, %ecx
mov $2, %edx
int \$0x80
snippet writestdout Write text to stdout
mov \$4, %eax
mov \$1, %ebx
mov $1, %ecx
mov $2, %edx
int \$0x80
snippet writestderr Write text to stderr
mov \$4, %eax
mov \$2, %ebx
mov $1, %ecx
mov $2, %edx
int \$0x80
snippet * Multiplication
mov $1, %eax
mul $2
snippet / Division
mov $1, %eax
div $2
snippet jmpl Conditional lower jump
cmp $1, $2
jl $3
snippet jmple Conditional lower or equal jump
cmp $1, $2
jle $3
snippet jmpe Conditional equal jump
cmp $1, $2
je $3
snippet jmpn Conditional not equal jump
cmp $1, $2
jn $3
snippet jmpg Conditional greater jump
cmp $1, $2
jg $3
snippet jmpge Conditional greater or equal jump
cmp $1, $2
je $3
snippet loopn Loop n times
mov $1, %ecx
et_for:
$2
loop et_for
snippet loopnn Loop n-1 times
mov $1, %ecx
dec %ecx
et_for:
$2
loop et_for
snippet loopv Loop through a vector
lea $1, %edi
xor %ecx, %ecx
et_for:
cmp %ecx, $2
je $3
$4
inc %ecx
jmp et_for
snippet mul Multiply
xor %edx, %edx
mov $1, %eax
mul $2
snippet mul64 Multiply numbers greater than 2^32
mov $1, %edx
mov $2, %eax
mul $3
snippet div Divide
xor %edx, %edx
mov $1, %eax
div $2
snippet div64 Divide numbers greater than 2^32
mov $1, %edx
mov $2, %eax
div $3
snippet pr Call printf
pushl $1
call printf
popl $2
snippet sc Call scanf
pushl $1
call scanf
popl $2
snippet mindex Current index from a matrix
xor %edx, %edx
movl $1, %eax
mull $2
addl $3, %eax
snippet ffl Call fflush
pushl \$0
call fflush
popl $1
snippet at Call atoi
pushl $1
call atoi
popl $2
snippet len Call strlen
pushl $1
call strlen
popl $2
snippet proc Basic procedure
$1:
pushl %ebp
movl %esp, %ebp
$2
popl %ebp
ret