Stack and Functions Flashcards
(40 cards)
type of data structure where items are added and then removed in reverse order
stack
stack is often referred to as ___
LIFO (Last In, First Out)
stack is heavily used for _____
the storage of information during procedure or function calls
adding an item to a stack is referred to as a ______
push operation
removing an item from a stack is referred to as a _______
pop operation
pop and push syntax
pop <operand64> push <operand64>
how is stack implemented in memory?
it is implemented growing downward
register used to point to the current top of stack in memory
RSP (stack pointer register)
what is being adjusted when performing push and pop operations?
the stack pointer register (RSP)
what happens in a push operation?
- rsp is decreased by 8
- operand is copied to the stack at [rsp]
what happens in a pop operation?
- current top-of-stack [rsp], is copied into the operand
- rsp is increased by 8
general format for declaring/defining a function
global <funcName> - is typically placed before any of the sections <funcName>: ; function body ret (return statement)
a function may be defined how many times?
only once
true/false
there is a specific order required for how functions are defined
false, there is no specific order
two (2) main actions that function(s) calls
- linkage
- argument transmission
function must be able to return to the correct place in which it was originally called
linkage
function must be able to access parameters to operate on or return results
argument transmission
two (2) instructions that handle the linkage
call <funcName>
- ret
how does
call <funcName>handle linkage?
it transfers control to the stated function
ex. from the _start label to the function specified in the function call
how does ‘ret’ handle linkage?
from the current function, it returns control back to the calling routine (from where it was called)
how does
call <funcName>work?
saves the address of where to return by placing the contents of the RIP on the stack
where does rip point to?
the next instruction
note: rip = instruction pointer register
how does ‘ret’ work?
ret pops the current top of stack (rsp) into the rip which points the control back to the return address initially saved into the stack when the function was first called
refers to sending information to a function and obtaining a result as appropriate for the specific function
argument transmission