The Stack Flashcards

1
Q

What does the PUSH instruction do?

A

PUSHes a value onto the top of the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the POP instruction do?

A

POPs a value off the top of the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly