Assembly Language Flashcards
Mnemonics
Opcodes, like mov, add and inc
Registers
Given names like eax, ebx for example.
Labels
Used to represent memory addresses, like num1 for eaxmple
Give an example of a line of assembly code that uses a mnemonic, register and memory address
mov eax, num
EAX
Accumulator register - store calculations
EBX
Base register - store a location
ECX
Counter register - for loops purposes
EDX
Data register - for random data
How can you transfer data from one memory location to another?
You cannot move something directly from memory to memory -> has to be through registers.
CF
Carry flag -> previous operation had a carry from the most significant bit.
ZF
Zero flag -> previous operation had zero results.
SF
Sign flag -> previous operation was positive (0) or negative (1)
OF
Overflow flag -> previous operation was too big to fit in memory
Jumps
Essentially calling a certain part of the code; allows loops (obsidian for examples).
Mutual Recursion
-> sub1 calls sub2, sub2 calls sub1
General case
-> bit that calls itself
Terminating case
-> the bit that causes it to stop
Nested Calls
-> tree structure of recursion
Factorial and fib can also be examples.
Tail recursion
-> recursive call is the last statement that is executed by the function.
Iterative v Non-Iterative
A function which calls itself, compared to a piece of code which doesn’t.
scanf and printf
Both take arguments from the stack, given in the order which they are pushed onto the stack (FIFO). The format specifier normally has to be first, then the remaining information.
Scanf takes exactly 2, printf takes 1 or more.
ESP
Stack pointer (points to top of stack).
In certain examples, we increase by 4 bytes to get next instruction, since stacks grow downwards.
EIP
Instruction Pointer (points at programs next instruction).
In certain examples, we decrease by 4 bytes to get next instruction since it grows upwards.
Calling Convention
Calling convention is an implementation-level scheme for how subroutines or functions receive parameters from their caller (via the stack).
ret
Return value for subroutine.
PROC and ENDP
Labels given at the start and end of a subroutine.
call
Calls function.
xchg eax, ebx
Swaps the data in these two registers around.
movzx
Used to transfer the first character somewhere:
movzx eax, byte ptr [ebx]
Moves the first character of ebx into eax.