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