In this article, we will learn how to construct C code from x86 assembly for structures. The article is divided into two parts. In the first part, we will write C code that involves structures and analyze the corresponding x86 assembly code. In the second part, we will look into x86 assembly code and try to construct corresponding C code that involves structures.
Let’s write this small piece of C code first.
#include <stdio.h> struct s{ int a; char b; }; int main() { struct s ss; ss.a = 10; ss.b = 'a'; return 0; }
Now, we can compile the above C code using the GCC compiler and get the corresponding x86 assembly code using the following commands:
$ gcc structures.c $ objdump -M intel -d a.out
Please note that the “-M intel” option will generate the x86 assembly code in the Intel syntax. The corresponding x86 assembly code will look like the following:
00000000004004d6 <main>: 4004d6: push rbp 4004d7: mov rbp,rsp 4004da: mov DWORD PTR [rbp-0x10],0xa 4004e1: mov BYTE PTR [rbp-0xc],0x61 4004e5: mov eax,0x0 4004ea: pop rbp 4004eb: ret 4004ec: nop DWORD PTR [rax+0x0]
0 Comments