Question: 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

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 setup two vertical tmux windows to compare ...
=== C Code ===
#include
void arith (){
int x =5;
int y =124;
int *t = malloc(sizeof(int)*10);
*(t +2)=2;
*(t +4)=*(t +2)+ x;
*(t +5)= y;
}
=== End C Code ===
=== Assembly Code ===
push %rbp
mov %rsp,%rbp
sub $0x10,%rsp
movl $0x5,-0x10(%rbp)
movl $0x7c,-0xc(%rbp)
mov $0x28,%edi
callq 20
mov %rax,-0x8(%rbp)
mov -0x8(%rbp),%rax
add $0x8,%rax
movl $0x2,(%rax)
mov -0x8(%rbp),%rax
add $0x8,%rax
mov (%rax),%ecx
mov -0x8(%rbp),%rax
add $0x10,%rax
mov -0x10(%rbp),%edx
add %ecx,%edx
mov %edx,(%rax)
mov -0x8(%rbp),%rax
lea 0x14(%rax),%rdx
mov -0xc(%rbp),%eax
mov %eax,(%rdx)
nop
leaveq
retq
=== End Assembly Code ===
Question 21 options:
mov -0x8(%rbp),%rax
add $0x8,%rax
mov (%rax),%ecx
mov -0x8(%rbp),%rax
add $0x10,%rax
mov -0x10(%rbp),%edx
add %ecx,%edx
mov %edx,(%rax)
movl $0x5,-0x10(%rbp)
mov $0x28,%edi
callq 20
mov %rax,-0x8(%rbp)
movl $0x7c,-0xc(%rbp)
mov -0x8(%rbp),%rax
add $0x8,%rax
movl $0x2,(%rax)
mov -0x8(%rbp),%rax
lea 0x14(%rax),%rdx
mov -0xc(%rbp),%eax
mov %eax,(%rdx)
1.
int *t = malloc(sizeof(int)*10);
2.
int x =5;
3.
int y =124;
4.
*(t +2)=2;
5.
*(t +4)=*(t +2)+ x;
6.
*(t +5)= y;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!