1/89
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
How many general purpose registers are there in x86-64?
16
How many general purpose registers did the 8086 have?
8
Why are transistors foundational for computers?
They are small, tough, power efficient, and can turn on and off billions of times per second
What does compilation from C do?
Translates C to assembly, then assembly to machine code
What is the program counter?
Holds the memory address of the next instruction to be executed
What is the program counter called in assembly?
%rip
What is the integer register file?
16 named locations containing 64 bit values, holding the register addresses used for C pointers or integer data
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)
What do condition code registers do?
Hold status information about the most recently executed arithmetic or logical instructions
What is the range of size for x86-64 instructions?
1 - 15 bytes
Disassemblers need access to source code or assembly code of the program. True or false?
False
What is the 2 byte (16 bit) data type called in x86-64?
Word
What is the 4 byte (32 bit) data type?
Double word ("l")
What is the 8 byte (64 bit) data type?
Quad word ("q")
What are the 2 formats for floating point data in x86-64?
Single (4 bytes) and double (8 bytes) precision
What is the fastest type of memory?
Registers
What is %rbp?
The base pointer to the bottom of the stack
What is %rsp?
The stack pointer
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
What do calling conventions regulate?
- Placement of function arguments
- Where return values go
- What registers a function may use
- How local variables are allocated
What is the caller?
A function that calls another function
What is the callee?
The function being called
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
What is the return register in x86-64?
%rax
How do calling conventions handle function parameters being structures?
They use the ABI (application binary interface) to determine how to handle it
What are the two most used ABIs?
- 64-bit Microsoft ABI
- x86-64 System V ABI (Linux, macOS, BSD)
How does Microsoft ABI handle function parameters being structures?
All structures are passed by value and pushed onto the stack.
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
What are the steps required to call a function sometimes called?
The entry sequence
What are the steps required to return sometimes called?
The exit sequence
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
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
What are the three operand possibilities?
- Immediate
- Register
- Memory
What are immediates?
Constant values written using $, followed by an integer or number (e.g. $-577 or $0x1F)
What are registers (as an operand)?
An arbitrary register to be referenced in the instruction
What is memory (as an operand)?
An effective (or computed) address that must be accessed in the instruction
What does mov do?
Copy data from one location to another
x86-64 allows move instructions between memory and memory. True or false?
False, memory-memory is not allowed
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
What does memory-memory movement look like in x86-64?
1. movq -4(%rbp), %rax
2. movq %rax, -16(%rbp)
What type of move instruction is?:
movl $0x4050, %eax
Immediate - Register
What type of move instruction is?:
movw %bp, %sp
Register - Register
What type of move instruction is?:
movb (%rdi, %rcx), %al
Memory - Register
What type of move instruction is?:
movb $-17, (%r10)
Immediate - Memory
What type of move instruction is?:
movq %rax, -12(%rbp)
Register - Memory
What is movabsq used for?
64-bit immediate data
What is special about movabsq?
You can only have an immediate as a source operand
What is the suffix for this move instruction?
mov_ %eax, (%rsp)
l
3 multiple choice options
What is the suffix for this move instruction?
mov_ (%rax), %dx
w
3 multiple choice options
What is the suffix for this move instruction?
mov_ $0xFF, %bl
b
3 multiple choice options
What is the suffix for this move instruction?
mov_ (%rsp, %rdx, 4), %dl
b
3 multiple choice options
What is the suffix for this move instruction?
mov_ (%rdx), %rax
q
3 multiple choice options
What is the suffix for this move instruction?
mov_ %dx, (%rax)
w
3 multiple choice options
Where is this moving?
mov_ %eax, (%rsp)
Register - Memory
Where is this moving?
mov_ (%rax), %dx
Memory - Register
Where is this moving?
mov_ $0xFF, %bl
Immediate - Register
Where is this moving?
mov_ (%rsp, %rdx, 4), %dl
Memory - Register
Where is this moving?
mov_ (%rdx), %rax
Memory - Register
Where is this moving?
mov_ %dx, (%rax)
Register - Memory
What is wrong with this move instruction?
movb $0xF, (%ebx)
%ebx cannot be an address (it is 32 bits)
What is wrong with this move instruction?
movl %rax, (%rsp)
Moving 64 bits - 64 bits is not a movl, it is a movq
What is wrong with this move instruction?
movw (%rax), 4(%rsp)
This is memory-memory, which is not allowed
What is wrong with this move instruction?
movb %al, %sl
%sl doesn't exist
What is wrong with this move instruction?
movq %rax, $0x123
Immediates cannot be a destination
What is wrong with this move instruction?
movl %eax, %dx
This should be movw because of %dx
What is wrong with this move instruction?
movb %si, 8(%rbp)
%si is 2 bytes (16 bits), so this should be a movw
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
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
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
What does the movz instruction do?
Move with zero-extension
What does the movs instruction do?
Move with signed extension
What is unique about the stack in assembly?
It grows downward
What does %rsp hold?
The address of the top of the stack element (the most recent item pushed onto the stack)
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
What does push1 %rax do?
- subq $8, %rsp - decrement the stack pointer
- movq %rax, (%rsp) - store the value of %rax on the stack
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
What does popq %rdx do?
- movq (%rsp), %rdx - read from %rsp and store in %rdx
- addq $8, %rsp - increment stack pointer
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
Given %rax = x, %rcx = y:
What is the result of leaq 6(%rax), %rdx?
%rdx = 6 + x
Given %rax = x, %rcx = y:
What is the result of leaq (%rax, %rcx), %rdx?
%rdx = x + y
Given %rax = x, %rcx = y:
What is the result of leaq (%rax, %rcx, 4), %rdx?
%rdx = x + 4y
Given %rax = x, %rcx = y:
What is the result of leaq 7(%rax, %rax, 8), %rdx?
%rdx = 7 + x + 8x = 7 + 9x
Given %rax = x, %rcx = y:
What is the result of leaq 0xA(, %rcx, 4), %rdx?
%rdx = 10 + 4y
Given %rax = x, %rcx = y:
What is the result of leaq 9(%rax, %rcx, 2), %rdx?
%rdx = 9 + x + 2y
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.
What does x86-64 use for unsigned 8 byte multiplication?
mulq
What does x86-64 use for signed 8 byte multiplication?
imulq
Where does x86-64 store the result of dividing 8 bytes?
The quotient is stored in %rax, and the remainder is stored in %rdx
What does x86-64 use for unsigned 8 byte division?
divq
What does x86-64 use for signed 8 byte division?
idivq