A Disassembly Example with Function and Stack
Learn how function parameters are passed via stack in the disassembly code and how parameters mismatch can result in defects.
We'll cover the following...
Example of disassembled code with comments
Here is the commented code disassembly of the main function with memory addresses removed for visual clarity:
Here is the commented disassembly of the arithmetic function, with memory addresses removed for visual clarity:
We can put a breakpoint on the first arithmetic calculations address and examine raw stack data pointed to by the sp register:
gcc FunctionParameters.cpp Arithmetic.cpp -o FunctionParameters
gdb ./FunctionParameters
After executing and loading the program, we get into the GDB container and see the following output:
We create the breakpoint of the programs with the break main command:
break main
The breakpoint is shown below:
Now, we run the program until the GDB breaks in:
set disable-randomization off
run
After running the program, it gives the breakpoint and starts the program’s execution: