Posts

Showing posts from September, 2022

Parameter passing mechanism of function call in C language

Image
The X86 instruction set started with the 16-bit 8086 and has experienced more than 40 years of development. The 64-bit X86-64 instruction set is now widely used. The registers have also changed from the previous 16-bit to the current 64-bit. The number of registers is also greatly increased. Of course gcc must also be constantly upgraded as the instruction set changes. In the 64-bit era, the parameter passing of C language in function calls has also undergone great changes. This article verifies this change by compiling C language programs into assembly language. Reading this article requires not only knowledge of C language, but also some knowledge of assembly language. All examples in this article are verified under Ubuntu 20.04, and the gcc version used is 9.4.0. 1. Parameter passing for calling functions in C language under 32-bit. In the 32-bit era, C language actually used the stack to pass parameters when calling functions. Before executing the call instruction, the parameters t...