Suppose I define a new struct:
struct s {
int *x;
struct {
short sh[2];
int i;
} w;
struct s *next;
};
In addition, I write a function to initialize it:
void init_s(struct s *ss) {
ss->w.sh[1] = /* Line 1 */;
ss->x = /* Line 2 */;
ss->next = /* Line 3 */;
}
The compiler generates the following assembly code for init_s:
init_s: # line 1
movw 8(%rdi), %ax # line 2
movw %ax, 10(%rdi) # line 3
leaq 12(%rdi), %rax # line 4
movq %rax, (%rdi) # line 5
movq %rdi, 16(%rdi) # line 6
retq # line 7
What I am trying to do is fill in the missing lines of code for init_s based on the assembly. I have figured out (or at least I think so) lines 1 and 2. Line 1 should be ss->w.sh[0] and line 2 should be &(ss->w.sh[2]). However, I am having trouble with line 3. I think it would be &(ss->x) based on the assembly, but I feel like this is incorrect and I'm not sure why. Any feedback or suggestion would be greatly appreciated in helping me learn more about assembly and structs.