Embed presentation
Download to read offline
![struct S {
double x;
int *ip;
int a[12];
};
Assuming the function foo on the left is compiled into the assembly on the right, what expression is
missing at the blank after the return keyword?
int foo(struct S *ptr) {
return _____________;
}
foo:
movq 8(%rdi), %rax
movl (%rax), %eax
ret
a) ptr->a[0]
b) ptr->a[1]
c) *ptr->ip
d) ptr->a
int foo(struct S *ptr) {
return _____________;
}
foo:
movq 8(%rdi), %rax
movl (%rax), %eax
ret](https://image.slidesharecdn.com/structsdoublexintipinta12assuming-230320200834-15ee877f/75/struct-S-double-x-int-ip-int-a12-Assuming-pdf-1-2048.jpg)
The document presents a C function `foo` that takes a pointer to a structure `s` and asks what expression should replace the blank after the return statement. It provides assembly code corresponding to the function, indicating a specific memory operation. The options for the missing expression involve accessing elements from the structure and its pointer.
![struct S {
double x;
int *ip;
int a[12];
};
Assuming the function foo on the left is compiled into the assembly on the right, what expression is
missing at the blank after the return keyword?
int foo(struct S *ptr) {
return _____________;
}
foo:
movq 8(%rdi), %rax
movl (%rax), %eax
ret
a) ptr->a[0]
b) ptr->a[1]
c) *ptr->ip
d) ptr->a
int foo(struct S *ptr) {
return _____________;
}
foo:
movq 8(%rdi), %rax
movl (%rax), %eax
ret](https://image.slidesharecdn.com/structsdoublexintipinta12assuming-230320200834-15ee877f/75/struct-S-double-x-int-ip-int-a12-Assuming-pdf-1-2048.jpg)