Architecture Flashcards
(40 cards)
What part of a computer executes machine code?
- CPU
- machine code instructions are processed by the CPU
- each instruction is a primitive command that executes a specific command, such as moving data
- written in HEX
What translates machine code into assembly language?
- Assembler
- NASM (Netwide Assembler)
ISA
- Instruction Set Architecture
- set of instructions that a programmer (compiler) must understand and use to write a program
- memory, registers, instructions, etc.
- EX: x86 instruction set (or architecture)
What does 32 or 64 refer to in ISA?
- width of the CPU registers
- each CPU has a fixed set of registers
- registers are temporary variables used by the CPU to get and store data
- EX: GPRs (General Purpose Registers)
What are the eight general purpose registers?
- EAX
- ECX
- EDX
- EBX
- ESP
- EBP
- ESI
- EDI
EAX
- Accumulator
- used in arithmetic operation
ECX
- Counter
- used in shift/rotate instruction and loops
EDX
- Data
- used in arithmetic operation and I/O
EBX
- Base
- used as a pointer to data
ESP
- Stack Pointer
- pointer to the top of the stack
EBP
- Base Pointer
- pointer to the base of the stack
ESI
- Source Index
- used as a pointer to a source in stream operation
EDI
- Destination
- used as a pointer to a destination in stream operation
What is the additional register that is important for x86 architecture?
- EIP
- The Instruction Pointer
- controls the program execution by storing a pointer to the address of the next instruction (machine code) that will be executed.
- it tells the CPU where the next instruction is
What are the four regions that process memory is divided into?
- text
- data
- the heap
- the stack
Text Region
- instruction segment
- contains the program code (instructions)
- marked as read-only since the program should not change during execution
Data Region
- divided into initialized data and uninitialized data
- initialized data includes items such as static and global declared variables (pre-defined; can be modified)
- uninitialized data, named Block Started by Symbol (BSS), also initializes variables that are initialized to zero or do not have explicit initialization (ex. static int t)
Heap
- starts right after the BSS segment
- during execution, the program can request more space in memory via BRK and SBRK system calls
Stack
- LIFO block of memory
- located in the higher part of memory
- an array used for saving a function’s return addresses, passing function arguments, and storing local variables
- ESP identifies the top of the stack
- ESP is modified each time a value is pushed in (PUSH) or popped out (POP)
Which direction does the stack grow?
- The stack grows downwards
- starts at higher memory and grows towards lower memory addresses
- knowing the limits of the memory allowed lets the programmer know who big the Heap or Stack will be
Which direction does the heap grow?
- The Heap grows upwards
- starts from lower memory addresses and grows to higher memory addresses
Explain the PUSH process?
- a PUSH instruction subtracts 4 (32-bit) or 8 (64-bit) from the ESP and writes the data to the memory address in the ESP
- then the ESP is updated to the top of the stack
- the Stack grows backward, therefore the PUSH subtracts 4 or 8 in order to point to a lower memory location on the Stack.
- if we do not subtract, the PUSH operation will overwrite the current location pointed by ESP (the top) and we would lose data
Explain the POP process?
- the POP operation is the opposition of PUSH
- it retrieves data from the top of the Stack
- therefore, the data contained at the address location in ESP (the top of the stack) is retrieved and stored (usually in another register)
- after a POP operation, the ESP value is incremented, in x86 by 4
Prologue
- a Function component
- prepares the Stack to be used, similar to putting a bookmark in a book