CPSC 2310 - Exam 3

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/89

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

90 Terms

1
New cards

How many general purpose registers are there in x86-64?

16

2
New cards

How many general purpose registers did the 8086 have?

8

3
New cards

Why are transistors foundational for computers?

They are small, tough, power efficient, and can turn on and off billions of times per second

4
New cards

What does compilation from C do?

Translates C to assembly, then assembly to machine code

5
New cards

What is the program counter?

Holds the memory address of the next instruction to be executed

6
New cards

What is the program counter called in assembly?

%rip

7
New cards

What is the integer register file?

16 named locations containing 64 bit values, holding the register addresses used for C pointers or integer data

8
New cards

What is the function of the integer register?

Keeps track of the program state and hold temporary data (function arguments, local variables, and return values)

9
New cards

What do condition code registers do?

Hold status information about the most recently executed arithmetic or logical instructions

10
New cards

What is the range of size for x86-64 instructions?

1 - 15 bytes

11
New cards

Disassemblers need access to source code or assembly code of the program. True or false?

False

12
New cards

What is the 2 byte (16 bit) data type called in x86-64?

Word

13
New cards

What is the 4 byte (32 bit) data type?

Double word ("l")

14
New cards

What is the 8 byte (64 bit) data type?

Quad word ("q")

15
New cards

What are the 2 formats for floating point data in x86-64?

Single (4 bytes) and double (8 bytes) precision

16
New cards

What is the fastest type of memory?

Registers

17
New cards

What is %rbp?

The base pointer to the bottom of the stack

18
New cards

What is %rsp?

The stack pointer

19
New cards

What is a calling convention?

Governs how functions on a particular architecture and OS interact, ensuring functions compiled by different compilers can interoperate, allowing OS to run code from different programming languages and compilers

20
New cards

What do calling conventions regulate?

- Placement of function arguments

- Where return values go

- What registers a function may use

- How local variables are allocated

21
New cards

What is the caller?

A function that calls another function

22
New cards

What is the callee?

The function being called

23
New cards

How many registers are set aside in x86-64 for function arguments? What happens if you have more arguments than registers?

6; they are pushed onto the stack

24
New cards

What is the return register in x86-64?

%rax

25
New cards

How do calling conventions handle function parameters being structures?

They use the ABI (application binary interface) to determine how to handle it

26
New cards

What are the two most used ABIs?

- 64-bit Microsoft ABI

- x86-64 System V ABI (Linux, macOS, BSD)

27
New cards

How does Microsoft ABI handle function parameters being structures?

All structures are passed by value and pushed onto the stack.

28
New cards

How does System V ABI handle function parameters being structures?

An algorithm is used to determine how to handle it. If the struct cannot be stored in the registers, it'll be pushed to the stack

29
New cards

What are the steps required to call a function sometimes called?

The entry sequence

30
New cards

What are the steps required to return sometimes called?

The exit sequence

31
New cards

What does the caller do in the entry sequence?

- Store the first 6 arguments in registers

- If there are more than 6 arguments, push the rest to the stack.

- Save any caller-saved registers

- Execute the callq function

32
New cards

What does the callee do in the exit sequence?

- Place the return value in %rax

- Restore the stack pointer (%rsp) to its value at entry

- Execute 'retq' (like pop %rip), which removes the return address from the stack and jumps to that address

- Clean up exit space it prepared for arguments and restore caller-saved registers

33
New cards

What are the three operand possibilities?

- Immediate

- Register

- Memory

34
New cards

What are immediates?

Constant values written using $, followed by an integer or number (e.g. $-577 or $0x1F)

35
New cards

What are registers (as an operand)?

An arbitrary register to be referenced in the instruction

36
New cards

What is memory (as an operand)?

An effective (or computed) address that must be accessed in the instruction

37
New cards

What does mov do?

Copy data from one location to another

38
New cards

x86-64 allows move instructions between memory and memory. True or false?

False, memory-memory is not allowed

39
New cards

How does x86-64 handle memory to memory movement?

It uses two instructions:

- Load the source value into a register

- Write the registers value to the destination

40
New cards

What does memory-memory movement look like in x86-64?

1. movq -4(%rbp), %rax

2. movq %rax, -16(%rbp)

41
New cards

What type of move instruction is?:

movl $0x4050, %eax

Immediate - Register

42
New cards

What type of move instruction is?:

movw %bp, %sp

Register - Register

43
New cards

What type of move instruction is?:

movb (%rdi, %rcx), %al

Memory - Register

44
New cards

What type of move instruction is?:

movb $-17, (%r10)

Immediate - Memory

45
New cards

What type of move instruction is?:

movq %rax, -12(%rbp)

Register - Memory

46
New cards

What is movabsq used for?

64-bit immediate data

47
New cards

What is special about movabsq?

You can only have an immediate as a source operand

48
New cards

What is the suffix for this move instruction?

mov_ %eax, (%rsp)

l

3 multiple choice options

49
New cards

What is the suffix for this move instruction?

mov_ (%rax), %dx

w

3 multiple choice options

50
New cards

What is the suffix for this move instruction?

mov_ $0xFF, %bl

b

3 multiple choice options

51
New cards

What is the suffix for this move instruction?

mov_ (%rsp, %rdx, 4), %dl

b

3 multiple choice options

52
New cards

What is the suffix for this move instruction?

mov_ (%rdx), %rax

q

3 multiple choice options

53
New cards

What is the suffix for this move instruction?

mov_ %dx, (%rax)

w

3 multiple choice options

54
New cards

Where is this moving?

mov_ %eax, (%rsp)

Register - Memory

55
New cards

Where is this moving?

mov_ (%rax), %dx

Memory - Register

56
New cards

Where is this moving?

mov_ $0xFF, %bl

Immediate - Register

57
New cards

Where is this moving?

mov_ (%rsp, %rdx, 4), %dl

Memory - Register

58
New cards

Where is this moving?

mov_ (%rdx), %rax

Memory - Register

59
New cards

Where is this moving?

mov_ %dx, (%rax)

Register - Memory

60
New cards

What is wrong with this move instruction?

movb $0xF, (%ebx)

%ebx cannot be an address (it is 32 bits)

61
New cards

What is wrong with this move instruction?

movl %rax, (%rsp)

Moving 64 bits - 64 bits is not a movl, it is a movq

62
New cards

What is wrong with this move instruction?

movw (%rax), 4(%rsp)

This is memory-memory, which is not allowed

63
New cards

What is wrong with this move instruction?

movb %al, %sl

%sl doesn't exist

64
New cards

What is wrong with this move instruction?

movq %rax, $0x123

Immediates cannot be a destination

65
New cards

What is wrong with this move instruction?

movl %eax, %dx

This should be movw because of %dx

66
New cards

What is wrong with this move instruction?

movb %si, 8(%rbp)

%si is 2 bytes (16 bits), so this should be a movw

67
New cards

What type of extension is used when assigning long = unsigned char?

Zero extension, since we go from 1 byte -> 8 bytes and the right hand side is unsigned

68
New cards

What type of extension is used when assigning unsigned long = short?

Signed extension, since we go from 2 bytes -> 8 bytes and the left hand side is signed

69
New cards

What type of extension is used when assigning short = char?

Signed extension, since we go from 1 byte -> 2 bytes and both sides are signed

70
New cards

What does the movz instruction do?

Move with zero-extension

71
New cards

What does the movs instruction do?

Move with signed extension

72
New cards

What is unique about the stack in assembly?

It grows downward

73
New cards

What does %rsp hold?

The address of the top of the stack element (the most recent item pushed onto the stack)

74
New cards

What do you need to do to push a new quad word onto the stack?

- Decrement the stack pointer by 8

- Write the new value at the new top-of-stack address

75
New cards

What does push1 %rax do?

- subq $8, %rsp - decrement the stack pointer

- movq %rax, (%rsp) - store the value of %rax on the stack

76
New cards

What do you need to do to pop a quad word off the stack?

- Read from the top-of-stack address

- Increment the stack pointer by 8

77
New cards

What does popq %rdx do?

- movq (%rsp), %rdx - read from %rsp and store in %rdx

- addq $8, %rsp - increment stack pointer

78
New cards

What is leaq?

It is a variant of movq, where it reads from memory to a register, and doesn't dereference memory. It copies the effective memory address to the destination

79
New cards

Given %rax = x, %rcx = y:

What is the result of leaq 6(%rax), %rdx?

%rdx = 6 + x

80
New cards

Given %rax = x, %rcx = y:

What is the result of leaq (%rax, %rcx), %rdx?

%rdx = x + y

81
New cards

Given %rax = x, %rcx = y:

What is the result of leaq (%rax, %rcx, 4), %rdx?

%rdx = x + 4y

82
New cards

Given %rax = x, %rcx = y:

What is the result of leaq 7(%rax, %rax, 8), %rdx?

%rdx = 7 + x + 8x = 7 + 9x

83
New cards

Given %rax = x, %rcx = y:

What is the result of leaq 0xA(, %rcx, 4), %rdx?

%rdx = 10 + 4y

84
New cards

Given %rax = x, %rcx = y:

What is the result of leaq 9(%rax, %rcx, 2), %rdx?

%rdx = 9 + x + 2y

85
New cards

What does x86-64 do for multiplying 8 bytes?

The result is 128 bits, which is an oct word. The higher order 64 bits will be stored in %rdx, and the low order 64 bits wil be stored in %rax.

86
New cards

What does x86-64 use for unsigned 8 byte multiplication?

mulq

87
New cards

What does x86-64 use for signed 8 byte multiplication?

imulq

88
New cards

Where does x86-64 store the result of dividing 8 bytes?

The quotient is stored in %rax, and the remainder is stored in %rdx

89
New cards

What does x86-64 use for unsigned 8 byte division?

divq

90
New cards

What does x86-64 use for signed 8 byte division?

idivq