In this code example
typedef struct { short int a1; short int a2;} st1;
typedef struct { int sum; int diff;} st2;
st2 test (st1 s1) {
st2 store;
store.sum = s1.a1 + s1.a2;
store.diff = s1.a1 - s1.a2;
return store;
}
which has the following machine code in assembly
test:
1 endbr32
2 pushl %ebp
3 movl %esp, %ebp
4 subl $16, %esp
5 movzwl 12(%ebp), %eax
6 movswl %ax, %edx
7 movzwl 14(%ebp), %eax
8 cwtl
9 addl %edx, %eax
10 movl %eax, -8(%ebp)
11 movzwl 12(%ebp), %eax
12 movswl %ax, %edx
13 movzwl 14(%ebp), %eax
14 cwtl
15 subl %eax, %edx
16 movl %edx, %eax
17 movl %eax, -4(%ebp)
18 movl 8(%ebp), %ecx
19 movl -8(%ebp), %eax
20 movl -4(%ebp), %edx
21 movl %eax, (%ecx)
22 movl %edx, 4(%ecx)
23 movl 8(%ebp), %eax
24 leave
25 ret $4
I don't understand what's going on in lines 5 to 8 and then 10 to 14. I imagine it's a way to manipulate short int, but I'd like to better understand what each instruction is doing when compared to its C code