Lecture 05 Flashcards

1
Q

What is the rflags register for?

A

It is updated after every instruction to reflect its result. Individual bits represent whether the result was zero, negative, resulted in overflow etc.
Programs can make conditional jumps based on these flags.

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

What is ‘rip relative addressing’?

A

‘RIP relative addressing’ is when an address is computed as some displacement, plus the current value of register RIP.
This means that code will work regardless of where it is loaded into memory, but the displacement is limited to 32 bits.

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

The stack:
A - Grows from the top of the memory space downwards.
B - Grows from the bottom of memory upwards.
C - Does not change size during execution.

A

A - The stack starts at the top of the memory space, and grows downwards as data is added to it.

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

The heap:
A - Grows from the top of the memory space downwards.
B - Grows from the bottom of memory upwards.
C - Does not change size during execution.

A

B - The heap grows upwards as data is allocated to it.

For example, a malloc() call will allocate data on the heap.

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

Static Data:
A - Grows from the top of the memory space downwards.
B - Grows from the bottom of memory upwards.
C - Does not change size during execution.

A

Static data does not change size during execution.

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

What sort of data is held in a stack frame?

A

Arguments, local variables, saved registers, and the return address.

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

What sort of data is held in the heap?

A

Anything allocated using malloc(). This is usually variables that are passed between different functions.

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

What sort of data is held in the ‘Static Data’ section of memory?

A

Global variables, static variables.

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

Can the heap contain gaps? Why?

A

The heap may contain gaps as memory can be freed after it has been used, removing it from the heap.

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

How large is the ‘red-zone’ beneath rsp?

A

128 bytes

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

What order are arguments pushed onto the stack:

In order, or in reverse order?

A

Arguments are pushed onto the stack in reverse order, i.e. the last argument is pushed on first.

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

What are the five main steps for calling a function in assembler?

A
  • Push arguments (or put them in registers if possible)
  • Execute callq (which pushes value from rip before setting rip to a new value)
  • Push old value of rbp
  • Set rbp to value from rsp
  • Decrement rsp to make space for local variables and saved register values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the four main steps of exiting from a function in assembler?

A
  • Increment rsp to free space used for local variables and saved register values.
  • Pop old value from rbp, putting it back in rbp.
  • Execution of retq (which pops address and puts it back in rip)
  • Increment rsp to free space taken up by arguments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly