Flash Cards for Lecture 4 of Comp Arch
Creator
username could not be found
System V AMD64 ABI and Microsoft x64 calling convention
Graph coloring algorithms and linear scan allocation.
Registers R8 through R15; additional general-purpose registers.
Direct addressing, register addressing, indirect addressing, indexed addressing.
Register allocation is the process of assigning registers to hold variables and intermediate values during compilation.
RDI, RSI, RDX, RCX, R8, R9
MOV (move data), ADD (addition), SUB (subtraction), AND (logical AND), OR (logical OR), XOR (logical XOR), CMP (compare)
Segmentation is a memory management technique where memory is divided into logical segments.
Buffer overflows, format string vulnerabilities, and integer overflows.
PUSH decrements RSP and then writes data onto the stack; POP reads data from the stack and then increments RSP.
Uses the value in a register as a pointer to the memory location.
Specifies the memory address directly within the instruction.
Paging is a memory management technique where memory is divided into fixed-size pages.
Used to implement just-in-time (JIT) compilation, where code is generated at runtime.
Writing secure code involves careful handling of register values and memory addresses to prevent exploits.
Segment registers (CS, DS, SS, ES, FS, GS) are used to point to these segments.
x64 registers are essential for efficient code execution, memory management, and system-level operations.
RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP, R8-R15
Used for Single Instruction Multiple Data (SIMD) operations, such as vector and parallel processing.
Reverse engineering involves analyzing compiled code to understand its functionality.
Used to store function pointers (addresses of functions).
General-purpose registers used for integer arithmetic and data manipulation.
Registers can be accessed in different sizes: 64-bit (e.g., RAX), 32-bit (e.g., EAX), 16-bit (e.g., AX), and 8-bit (e.g., AL, AH).
RSP (Stack Pointer)
JE (jump if equal), JNE (jump if not equal), JG (jump if greater), JL (jump if less)
Context switching involves saving the state of the current process (including register values) and loading the state of another process.
Used for passing arguments to functions and storing return values.
Debugging tools (e.g., GDB, WinDbg) allow you to inspect register values and track program execution.
The CALL instruction pushes the return address onto the stack, and the RET instruction pops the return address from the stack.
Minimize memory access and improve performance.
Stack pointer register; points to the top of the stack.
CALL (call a subroutine) and RET (return from a subroutine).
The stack grows downward (towards lower memory addresses).
Used to store status and control bits for system operations.
Analyzing register usage can reveal the program's logic and data manipulation techniques.
Used to store metadata about objects, such as their type and size.
Assembly language programming, compiler design, and reverse engineering.
Destination index register; used as a pointer to a destination in string operations.
RAX
RBX, RBP, R12-R15, RSP
Registers and stack
Profile the code to identify performance bottlenecks, and then optimize register usage in those areas.
The stack is used to store local variables, return addresses, and to pass additional arguments to functions.
Multimedia eXtensions, Streaming SIMD Extensions, Advanced Vector Extensions
Used for exception handling and interrupt handling.
AND, OR, XOR, NOT, SHL (shift left), SHR (shift right), ROL (rotate left), ROR (rotate right)
Instructions operate on registers to perform arithmetic, logical, and data transfer operations.
MMX, SSE, AVX
Bitwise operations manipulate individual bits within registers.
Used for low-level tasks such as manipulating hardware registers and implementing cryptographic algorithms.
Base pointer register; used to point to the base of the current stack frame.
Translation Lookaside Buffer (TLB) is a cache for frequently used page table entries.
The registers available and their usage vary across different architectures, affecting portability.
Base register; often used as a pointer to data.
Data register; used in I/O operations and some arithmetic instructions.
Contains the address of the next instruction to be executed.
Accumulator register; used in arithmetic operations and return values.
XMM0-XMM15
RIP (Instruction Pointer), RFLAGS (Status Flags)
Calling conventions are standardized rules for how functions receive arguments and return values.
Adds an offset to the value in a register to access memory.
Uses the value in a register as the operand.
Understanding register usage is critical for optimizing code and debugging issues.
Source index register; used as a pointer to a source in string operations.
Contains status flags (e.g., zero, carry, overflow) that reflect the result of the most recent arithmetic or logical operation.
RAX, RCX, RDX, RSI, RDI, R8-R11
Optimizing code involves using registers efficiently to reduce memory access and improve performance.
CMP (compare) sets flags in the RFLAGS register, which are then used by conditional jump instructions (e.g., JE, JNE, JG, JL).
Counter register; used in loops and string operations.
Caller-saved registers must be saved by the calling function if their values need to be preserved after the call. Callee-saved registers must be saved by the called function before they are modified, and restored before returning.
Used to control the flow of execution based on conditions.
x64 architecture is widely used in modern desktop, server, and mobile devices.
Extra Segment registers; can be used to point to additional data segments.
Destination Index; also used for string operations.
The register that holds the address of the next instruction to be executed.
Code Segment; points to the segment containing the current program code.
Stack Pointer; points to the top of the stack.
Data Segment; points to the segment containing data.
Stack Segment; points to the segment containing the stack.
Source Index; used for string operations.
Segment registers (CS, DS, SS, ES, FS, GS) define memory segments.
Used for addressing memory locations.
AH refers to the high byte of the AX register.
Often used to store function return values.
AL refers to the low byte of the AX register.
Used as a counter in loops and string operations.
Base Pointer; points to the base of the stack frame.
General-purpose registers used for arithmetic and data manipulation.
Instruction Pointer; points to the next instruction to be executed.
32-bit registers (e.g., EAX) are extended versions of 16-bit registers (e.g., AX).
16-bit registers (e.g., AX) can be further divided into 8-bit registers (e.g., AH and AL).
Contains flags that indicate the result of operations (e.g., zero, carry).
Overflow, Direction, Interrupt enable, Trace (trap), Sign, Zero, Auxiliary Carry, Parity, Carry
Displays a list of usable commands
Scrolls through available files/directories that begin with whatever you have started typing
Immediate data is coded directly in the instruction's machine code
VERY close to machine code, human-readable encoding of machine code, each instruction corresponds to a machine instruction, not readable by machine (needs to be assembled)
Arithmetic, logical, and other operations
CPU state is visible and accessible to the program, all CPU state is stored in its register file, i.e. the memory on the CPU
DS (Data), CS (Code), SS (Stack), ES (Extra), IP (Instruction Pointer)
masm programName.asm (hit enter 4 times), link programName (hit enter 4 times), programName.exe
Strings may be up to 64KB in length, string addressing modes uses SI, DI, DS, and ES registers
Objects of different types are declared and allocated memory, memory is accessed by accessing the objects, local variables used to store temporary values, CPU state is hidden from programmer, object type defines what operations can be performed, single statement can perform a complex task
Assembly instructions are not case sensitive, comments are preceded by ';', no terminating character, code should be heavily commented
Constant integer (8, 16, or 32 bits), name of a register is specified, reference to a location in memory
The base and index registers are added to give the segment offset of where the operand is located
IA32 (aka i386/i486/Pentium)
8086 (1979): 20-bit address bus and 16-bit data bus, 80386 (1985): 32-bit address bus and 32-bit data bus, Pentium (1993): 32-bit address bus and 64-bit data bus
Change directory to the folder called 'FolderName' in your current directory
Displays the disassembly starting from the net instruction to be executed
Specify the method for finding the memory address of an operand
Operand is located at the address given by adding 8 or 16 bit displacement to either Sl or DI and combing the result with a segment register
Run program Prog.exe (must be in your current directory)
Previous command
Immediate, register, direct, register indirect, based, indexed, based indexed, string, and port addressing
Translate HLL program to assembly code, assemble assembly code to machine code, link object code with runtime library, yields an executable
Bus Interface Unit (BIU), Execution Unit (EU)
Go up a level in the folder hierarchy
Jumps to a line of code in the program
Only a small address field is needed in instruction, no memory references are required
Uses a register instead of a constant to specify the 16-bit offset address of the operand
Registers, ALU, Control Unit, Execution Unit, etc
Addressing and string operations
The set of instructions (and their encodings) that a processor can execute
Assembly (human readable, not executable), machine code (binary, executable)
Step through the code one line at a time, allowing you to see the CPU state at any point
Address space is very limited
Operand is located at the address given by adding 8 or 16 bit displacement to either BX or BP and combing the result with a segment register
Understand how computers execute code, understand what optimizations the compiler performs, reverse engineer a piece of software, improve efficiency of a program, write programs that have direct control over system hardware
Maintaining the stack
Single memory reference to access data
Four 16-bit registers, eight 8-bit registers
Gives status of the last instruction and the processor
Dumps a section of memory
The I/O ports may be addressed by a byte sized constant, limited to I/O ports in the range 0 to 255
Display contents of current directory, one page at a time
Limited address space
Base Pointer (BP), Stack Pointer (SP), Destination Index (DI), Source Index (SI)