Member-only story
Learning Assembly Language — A Helpful Guide [Part 3]
So far we have focused mainly on instructions and registers, and how these interact, but we will start to understand more about how memory and complete programs work within assembly. The best place to start is by understanding how we make calls to functions, and one of the key elements of program execution — a STACK!
Function Calls
Anyone who has programmed in higher-level programming languages such as Java and Python, understands the importance of using functions. These split up the code, organising it into reusable code that can perform a specific — required — purpose.
Covering labels and jumps in part 2, we know how we can easily move around our program, however it is useful to divide your program into functions instead, as they allow better understand of our code, and allow us to pass parameters for cleaner solutions.
The main two instructions we need to know, which allow us to create functions, are as follows:
call -Similar to jump command, but once finished, returns to the next specified instruction
ret — Tells the program to resume execution from after the last call instruction.
The call instruction remembers where we need to return to through one important piece of information, the return address. This piece of information points at the address which we will jump to when the ret instruction is called. But how do we store this value?