Text: Language C:
Problem description:
Given the following C program and its corresponding Assembly code, match the corresponding C statements with the appropriate Assembly instructions.
Hint: You can try to get on taz, make a copy of the C code, run "gcc -c filename.c" to generate the Assembly code, and then set up two vertical tmux windows to compare.
=== C Code ===
#include <cstdlib.h>
void arith() {
int x = 5;
int y = 124;
int *t = malloc(sizeof(int) * 1);
*(t + 2) = 2;
*(t + 4) = *(t + 2) + x;
*(t + 5) = y;
}
=== End C Code ===
=== Assembly Code ===
push %rbp
mov %rsp, %rbp
sub $8, %rsp
mov $5, -8(%rbp)
mov $124, -12(%rbp)
movq $8, %rdi
call malloc
mov %rax, -16(%rbp)
mov $2, (%rax + 8)
mov (%rax + 16), %edx
add %edx, -8(%rbp)
mov -12(%rbp), %eax
mov %eax, (%rax + 20)
nop
leave
ret
=== End Assembly Code ===