Switch Functions
Empty Function
void increment(short *array, short num) {
for (int x = 0; x < num; x++) {
array[x]++;
}
}
int main(void) {
short numbers[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
increment(numbers, 9);
return 1;
}
This generates the following assembly:
increment:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-24], rdi
mov eax, esi
mov WORD PTR [rbp-28], ax
mov DWORD PTR [rbp-4], 0
jmp .L2
.L3:
mov eax, DWORD PTR [rbp-4]
cdqe
lea rdx, [rax+rax]
mov rax, QWORD PTR [rbp-24]
add rax, rdx
movzx edx, WORD PTR [rax]
add edx, 1
mov WORD PTR [rax], dx
add DWORD PTR [rbp-4], 1
.L2:
movsx eax, WORD PTR [rbp-28]
cmp eax, DWORD PTR [rbp-4]
jg .L3
nop
pop rbp
ret
.size increment, .-increment
.globl main
.type main, @function
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov WORD PTR [rbp-32], 0
mov WORD PTR [rbp-30], 1
mov WORD PTR [rbp-28], 2
mov WORD PTR [rbp-26], 3
mov WORD PTR [rbp-24], 4
mov WORD PTR [rbp-22], 5
mov WORD PTR [rbp-20], 6
mov WORD PTR [rbp-18], 7
mov WORD PTR [rbp-16], 8
lea rax, [rbp-32]
mov esi, 9
mov rdi, rax
call increment
mov eax, 1
leave
ret