X86 Assembly Review.

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
COMP 2003: Assembly Language and Digital Logic
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Introduction to X86 assembly by Istvan Haller
Practical Session 3 Computer Architecture and Assembly Language.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Accessing parameters from the stack and calling functions.
Flow Control Instructions
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
COSC 456 Lesson 8 Cool Codes ADD AL,SIAL AL + SI ADD AL,[SI]AL AL + [SI] INC BXBX BX + 1 INC [BX]Ambiguity error INC BYTE PTR [BX][BX] [BX] + 1 INC WORD.
Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Arithmetic Flags and Instructions
CNIT 127: Exploit Development Ch 1: Before you begin.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Compiler Construction Code Generation Activation Records
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Computer Architecture and Assembly Language
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
1 Assembly Language: Function Calls Jennifer Rexford.
Assembly Language Wei Gao. Assembler language Instructions.
Practical Session 3 Computer Architecture and Assembly Language.
Precept 7: Introduction to IA-32 Assembly Language Programming
Assembly function call convention
Reading Condition Codes (Cont.)
Machine-Level Programming 2 Control Flow
Computer Architecture and Assembly Language
Computer Architecture CST 250
Homework Reading Lab with your assigned section starts next week
C function call conventions and the stack
Chapter Nov-2010
Aaron Miller David Cohen Spring 2011
Introduction to Compilers Tim Teitelbaum
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
Basic Microprocessor Architecture
Assembly IA-32.
INSTRUCTION SET.
Assembly Language Programming Part 2
# include < stdio.h > v oid main(void) { long NUM1[5]; long SUM; long N; NUM1[0] = 17; NUM1[1] = 3; NUM1[2] =  51; NUM1[3] = 242; NUM1[4] = 113; SUM =
Homework Reading Continue work on mp1
اصول اساسی برنامه نویسی به زبان اسمبلی
CS 301 Fall 2002 Assembly Instructions
Y86 Processor State Program Registers
BIC 10503: COMPUTER ARCHITECTURE
Assembly Language: IA-32 Instructions
8086 Registers Module M14.2 Sections 9.2, 10.1.
Machine-Level Programming 2 Control Flow
Fundamentals of Computer Organisation & Architecture
Practical Session 4.
Shift & Rotate Instructions)
Machine-Level Programming 2 Control Flow
Multi-modules programming
Computer Architecture CST 250
Computer Architecture and System Programming Laboratory
UNIT-II Assembly Language Programs Involving Logical
CNET 315 Microprocessor & Assembly Language
CSC 497/583 Advanced Topics in Computer Security
Chapter 8: Instruction Set 8086 CPU Architecture
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

x86 Assembly Review

General Purpose Registers EAX EBX ECX EDX (AL, AH, AX) (BL, BH, BX) (CL, CH, CX) (DL, DH, DX) Stores return value Loop counter Used with EAX in multiplication, division

More General Purpose Registers ESI EDI ESP EBP Source pointer Destination pointer Stack pointer Base pointer

Other Registers EIP EFLAGS Instruction pointer Status register

MOV MOV EAX, EBX MOV EAX, 0x0 MOV EAX, [0x400000] MOV EAX, [EBX + ESI * 4]

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

Arithmetic Instructions ADD EAX, 0x10 SUB EAX, EBX INC EAX DEC EAX

More Arithmetic Instructions MOV EAX, 0x2 Multiples EAX by 4, stores upper 32 MUL 0x4 bits in EDX and lower 32 bits in EAX MOV EDX, 0x0 Divides EDX:EAX by 3, stores MOV EAX, 0x9 result in EAX and remainder in EDX DIV 0x3

Logical Operator Instructions XOR EAX, EAX AND EAX, 0xFF OR EAX, EBX

Bit Shifting Instructions SHL EAX, 0x2 SHR EAX, EBX ROL EAX, 0x4 ROR EAX, EBX

Conditional Instructions CMP EAX, EBX TEST EAX, 0x10 TEST EAX, EAX

Branching Instructions JMP LOC Unconditional jump JZ / JE LOC Jump if ZF == 1 JNZ / JNE LOC Jump if ZF == 0 JG / JA LOC Jump if DST > SRC JL / JB LOC Jump if DST < SRC JGE / JAE LOC Jump if DST >= SRC JLE / JBE LOC Jump if DST <= SRC

Rep Instructions REPE CMPSB Compare ESI and EDI buffers REP STOSB Initialize all bytes of EDI buffer to the value stored in AL REP MOVSB Copy ESI to EDI REPNE SCASB Search EDI for the byte in AL

PUSH in Assembly Language What does PUSH actually do? PUSH myVal SUB ESP, 4 MOV [ESP], myVal Subtract 4 from the stack pointer (“make room” on the stack) Copy the value into that new space on the stack

POP in Assembly Language What does POP actually do? POP myRegister MOV myRegister, [ESP] ADD ESP, 4 Copy the value off the stack into the register Add 4 to the stack pointer (move the stack back “up”)

CALL in Assembly Language What does CALL actually do? CALL myFunc PUSH &nextInstruction SUB ESP, 4 MOV [ESP], &nextInstruction JMP myFunc Push the address in memory you’ll want to return to Jump to where the function you’re calling resides in memory

RET in Assembly Language What does RET actually do? RET POP 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 Pop the return address into EIP

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

Simple Cdecl Example – Code What actually happens on the stack when this program is run? What variables are allocated first? How does the stack grow? int myFunc(char *par1, int par2) { char local1[64]; int local2; return 0; } int main(int argc, char **argv) myFunc(argv[1], atoi(argv[2]);

Simple Cdecl Example – Calling <- EBP PUSH par2 PUSH par1 CALL myFunc PUSH EBP MOV EBP, ESP SUB ESP, 68 Main’s Stack Frame <- ESP par2 par1 Return Address Main’s EBP local1 local2

Simple Cdecl Example – Returning MOV ESP, EBP POP EBP RET Main’s Stack Frame par2 par1 Return Address Main’s EBP <- EBP local1 local2 <- ESP