Architecture 05 Flashcards

1
Q

What is the flags register in x86-64?

A
  • 64 bits, but not available as general purpose register
  • Individual bits reflect execution of preceding instruction
  • Conditional jumps executed based on these flags
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the individual bits of the flags register?

A
  • bit 0 is carry flag (did add/sub result in carry bit?)
  • bit 2 is parity flag (last result had even number of bits?)
  • bit 6 is zero flag (last result was 0?)
  • bit 7 is sign flag? (last result was negative?)
  • bit 11 is overflow flag? (did add/sub result in overflow?)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is RIP relative addressing?

A
  • Avoids direct addressing (with an absolute address)

* Instead address is current value of rip plus displacement

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

What is an advantage of RIP relative addressing?

A

Position independent code - code that runs no matter where it is loaded in memory

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

What is a disadvantage of RIP relative addressing?

A

Displacement is limited to 32 bits

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

What does the conventional use of memory by a program consist of?

A
  • Program (lowest address is here)
  • Static data (variables outside functions/static variables)
  • Dynamic data (heap - grows up through malloc)
  • Free space (out of memory when heap meets stack)
  • Stack (highest address, grows down through function calls)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a stack frame consist of?

A
  • Arguments
  • Local variables
  • Saved registers
  • Return address
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why wait until the stack and heap meet to declare there is no memory left?

A

Avoids setting bound on size of stack alone and setting bound on size of heap alone

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

What does the call of a function mainly consist of relative to the stack frame?

A
  • Push arguments (or put in registers if possible)
  • Execute callq (pushes value from rip before setting rip to new value)
  • Push old value from 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
10
Q

What does the exit of a function mainly consist of relative to the stack frame?

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

What is the red zone?

A

A 128 byte area below rsp which the callee can use for temporary data without creating a new stack frame

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

What’s special about how arguments are passed on via the stack (not via registers)?

A

They are pushed on in reverse order, so the last argument is pushed first

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

What must be done before executing a ret instruction?

A

A function must load the return value into the location that the processor uses

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