
x86 Assembly Review and Instructions Overview
"Explore the essentials of x86 assembly language, including general purpose registers, more registers, arithmetic, logical, shifting, and conditional instructions, with detailed explanations and examples."
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
General Purpose Registers Stores return value (AL, AH, AX) EAX (BL, BH, BX) EBX Loop counter (CL, CH, CX) ECX Used with EAX in multiplication, division (DL, DH, DX) EDX 2
More General Purpose Registers ESI Source pointer EDI Destination pointer ESP Stack pointer EBP Base pointer 3
Other Registers Instruction pointer EIP Status register Zero Flag Carry Flag Overflow Flag EFLAGS ZF CF OF 4
MOV MOV EAX, EBX MOV EAX, 0x0 MOV EAX, [0x400000] MOV EAX, [EBX + ESI * 4] 5
LEA Load Effective Address Moves a pointer into a register, does not dereference LEA EAX, [EBX + 8] Puts EBX + 8 into EAX MOV EAX, [EBX + 8] Dereferences EBX + 8 and puts value into EAX 6
LEA vs MOV _start: mov ebx, message lea eax, [ebx] mov ecx, [ebx] section .data message: db "Hello, World", 10 7
Arithmetic Instructions ADD EAX, 0x10 SUB EAX, EBX INC EAX DEC EAX 8
More Arithmetic Instructions MOV upper 32 MUL 32 bits in EAX EAX, 0x2 Multiples EAX by 4, stores 0x4 bits in EDX and lower MOV stores MOV remainder in EDX DIV EDX, 0x0 Divides EDX:EAX by 3, EAX, 0x9 result in EAX and 0x3 9
Logical Operator Instructions XOR EAX, EAX AND EAX, 0xFF OR EAX, EBX 10
Bit Shifting Instructions SHL EAX, 0x2 SHR EAX, EBX ROL EAX, 0x4 ROR EAX, EBX 11
Conditional Instructions CMP EAX, EBX TEST EAX, 0x10 TEST EAX, EAX 12
Branching Instructions JMP JZ / JE JNZ / JNE JG / JA JL / JB JGE / JAE JLE / JBE LOC Unconditional jump Jump if ZF == 1 Jump if ZF == 0 Jump if DST > SRC Jump if DST < SRC Jump if DST >= SRC Jump if DST <= SRC LOC LOC LOC LOC LOC LOC 13
Rep Instructions REPE buffers CMPSB Compare ESI and EDI REP EDI buffer to the STOSB Initialize all bytes of value stored in AL REP MOVSB Copy ESI to EDI REPNE SCASB AL Search EDI for the byte in 14
PUSH in Assembly Language What does PUSH actually do? PUSH myVal Subtract 4 from the stack pointer ( make room on the stack) SUB ESP, 4 MOV [ESP], myVal Copy the value into that new space on the stack 15
POP in Assembly Language What does POP actually do? POP myRegister Copy the value off the stack into the register MOV myRegister, [ESP] ADD ESP, 4 Add 4 to the stack pointer (move the stack back up ) 16
CALL in Assembly Language What does CALL actually do? CALL myFunc Push the address in memory you ll want to return to PUSH &nextInstruction SUB ESP, 4 MOV [ESP], &nextInstruction JMP myFunc Jump to where the function you re calling resides in memory 17
RET in Assembly Language What does RET actually do? RET POP EIP Pop the return address into EIP Trusting that whatever s at the top of the stack is the return address When you execute the next instruction it looks at EIP to see what to do next 18
What is Cdecl? The calling convention for the C programming language Calling conventions determine Order in which parameters are placed onto the stack Which registers are used/preserved for the caller How the stack in general is handled 19
Simple Cdecl Example Code What actually happens on the stack when this program is run? int myFunc(char *par1, int par2) { char local1[64]; int local2; return 0; } What variables are allocated first? How does the stack grow? int main(int argc, char **argv) { myFunc(argv[1], atoi(argv[2])); return 0; } 20
Simple Cdecl Example Calling <- EBP Main s Stack Frame PUSH par2 PUSH par1 CALL myFunc PUSH EBP MOV EBP, ESP SUB ESP, 0x68 <- ESP <- ESP par2 par1 <- ESP Return Address <- ESP <- ESP <- EBP Main s EBP local1 local2 <- ESP 21
Simple Cdecl Example Returning <- EBP Main s Stack Frame MOV ESP, EBP POP EBP RET par2 par1 <- ESP Return Address <- ESP Main s EBP <- ESP <- EBP local1 local2 <- ESP 22