The Stack Flashcards Preview

Assembly x86 > The Stack > Flashcards

Flashcards in The Stack Deck (11)
Loading flashcards...
1
Q

What does the PUSH instruction do?

A

PUSHes a value onto the top of the stack.

2
Q

What does the POP instruction do?

A

POPs a value off the top of the stack.

3
Q

What happens to the ESP when you PUSH a value on to the stack?

A

The memory address decreases as the stack grows.

4
Q

What happens to the ESP when you POP a value off of the stack?

A

The memory address increases as the stack shrinks.

5
Q

Which register is pushed onto the stack at the beginning of a new function?

A

EBP (base pointer of the previous stack frame)

6
Q

How would you reserve space on the stack for a local variable?

A

“SUB ESP, 10” would reserve 10 (hex) bytes of data on the stack

7
Q

After pushing the previous functions EBP to the stack, what do we do with the EBP?

A

“MOV EBP, ESP”. We set the value of EBP to the current ESP to create the new stack frame for the current scope of the function

8
Q

When returning out of a function back to the original, how do we obtain the previously used stack frame?

A

“MOV ESP, EBP; POP EBP;” sets the ESP to the original EBP, removing the previous stack frame data, and POPs the value off of the top into EBP. This is the original EBP which recreates the stack frame.

9
Q

Which three instructions are likely to be seen at the end of a function that returns to main() ?

A

“MOV ESP, EBP” -> clear the stack back to main() stack frame
“POP EBP” -> restore the base pointer of main()
“RETN” -> return to main()

10
Q

If the ESP is “0x0012E650” and 2 registers are PUSH’d, what is the new value of the ESP?

A

0x0012E648 or “ESP - 8”

11
Q

If the ESP is “0x0012E650” and 2 registers are POP’d, what is the new value of the ESP?

A

0x0012E658 or “ESP + 8”