Okay, so lets get started!
Section 8: Basic Stack Manipulation.
If you have ever programmed before, the Stack is kind of like an array.
Except the array has a pointer to the top or working register.
Values can be pushed to and popped from the stack.
The stack is stored in RAM so it might be a teeny tiny bit slower than
eax and such.
The pointer is stored in
esp, don't mess with this unless you are very smart.
Every time you pop a value from the stack you decrease the stack pointer by 4 and store whatever was there in the register specified afterword.
Every time you push a value to the stack you increase it by 4 and then it does the operation of putting the value there.
To pop a value to the stack you do:
To push a value you do:
This can be useful for saving registers like this:
_start: mov eax, 1 push eax mov eax, 4 pop eax
Section 9: Functions.
So functions in Assembly are broken up into 3 parts.
Let's go in order and break it down.
The basic function prologue looks like this:
push ebp mov ebp, esp sub esp, *
ebp is the
What is this?
It's the register that stores the location after your calls!
It stores the next line number.
Then we push
Then to save the value of
esp we put
sub, that is a keyword for subtraction. There is also
Both of these store the result in the first variable defined
So the syntax is
sub <a>, <b>
And both could be a value or a register.
Then it will try to store the result in
So we are subtracting the stack pointer by
Well, you want to replace
* with the stack change times 4
A good way to put it is pretending that the pointer starts at 0 when you enter the function.
pop action increases or decreases the stack by
Hope that makes sense.
This is just your code
This is your basic epilogue.
mov esp, ebp pop ebp ret
We include that
And undo everything.
Anyway Sorry for this one being short tomorrows will be 3 sections long.
The usual, upvote, feedback.
I don’t mean to be pushy or anything and I don’t want to rush you, but when does the next one come out?
Every time you pop a value from the stack you decrease the stack pointer by 1.
This seems a bit misleading...
Hm idk this one seems super slim... maybe elaborate more on how the stack works n’ stuff? Like talk about indexing the rsp or rbp using [ rbp + 3 ] n’ stuff like that?