March 1, 2020

Assembly language - stack and subroutine calls

Almost every modern and civilized processor has a special register called "sp" for stack pointer. And almost every modern high level language uses the stack for subroutine calls and local variables.

Compiler generated code to deal with the stack can be tricky and confusing. Each compiler has its own convention for how subroutines are called, and how arguments are passed to subroutines and I won't try to explain all that here, simply to warn you about it. If you are going to get deep into reverse engineering some compiler generated code or if you want to write assembly language routines called from C, you will need to master it.

One convention is very common, and that is that the register r0 (if there is a register r0!) returns values from functions. Arguments (the first few anyway) may be passed in registers. The rest (or all of the arguments) may be pushed onto the stack.


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org