Machine-Level Programming Introduction

Similar documents
Machine-Level Programming I: Introduction Jan. 30, 2001

Machine-Level Programming Introduction

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008

The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, 2002

Page # CISC 360. Machine-Level Programming I: Introduction Sept. 18, IA32 Processors. X86 Evolution: Programmerʼs View.

IA32 Processors The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, X86 Evolution: Programmer s View

! Starting in 1978 with ! Added more features as time goes on. ! Still support old features, although obsolete

Instruction Set Architectures

Systems I. Machine-Level Programming I: Introduction

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

Giving credit where credit is due

X86 Assembly -Data II:1

Instruction Set Architectures

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

Assembly I: Basic Operations. Jo, Heeseung

Software. Hardware. x86 basics. ISA View. a brief history of x86 10/6/15. Program, Application. Programming Language. Compiler/Interpreter

The Hardware/Software Interface CSE351 Spring 2015

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

Machine- level Programming

Machine Programming 1: Introduction

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT

Carnegie Mellon. 5 th Lecture, Jan. 31, Instructors: Todd C. Mowry & Anthony Rowe

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Machine Level Programming I: Basics

Today: Machine Programming I: Basics

CS429: Computer Organization and Architecture

Sungkyunkwan University

MACHINE-LEVEL PROGRAMMING I: BASICS

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS241 Computer Organization Spring 2015 IA

Machine Level Programming I: Basics. Credits to Randy Bryant & Dave O Hallaron

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

CS241 Computer Organization Spring Addresses & Pointers

Last Time: Floating Point. Intel x86 Processors. Lecture 4: Machine Basics Computer Architecture and Systems Programming ( )

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

Today: Machine Programming I: Basics. Machine Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

CS241 Computer Organization Spring Introduction to Assembly

Questions about last homework? (Would more feedback be useful?) New reading assignment up: due next Monday

Machine Programming I: Basics

Machine-Level Programming I: Introduction

The von Neumann Machine

Machine-Level Programming II: Control and Arithmetic

+ Machine Level Programming: x86-64 History

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-Level Programming I Introduction

Credits and Disclaimers

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes

Process Layout and Function Calls

Credits to Randy Bryant & Dave O Hallaron

Machine-Level Programming I Introduction

Ge-ng at things on the chip you can t easily reach from C

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

Introduction to IA-32. Jo, Heeseung

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Machine Level Programming II: Arithmetic &Control

Machine Programming 3: Procedures

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

INTRODUCTION TO IA-32. Jo, Heeseung

The von Neumann Machine

Today: Machine Programming I: Basics. Machine-Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

CSC 8400: Computer Systems. Machine-Level Representation of Programs

Chapter 3 Machine-Level Programming I: Basics. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Today: Machine Programming I: Basics. Machine-Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

Credits and Disclaimers

ASSEMBLY III: PROCEDURES. Jo, Heeseung

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Assembly III: Procedures. Jo, Heeseung

Handout #2: Machine-Level Programs

Machine-level Programming (3)

Instruction Set Architecture

Instruction Set Architecture

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Machine-Level Programming I: Basics

Machine- Level Programming: Basics

Process Layout, Function Calls, and the Heap

CS213. Machine-Level Programming III: Procedures

The Hardware/Software Interface CSE351 Spring 2013

x86 Programming I CSE 351 Winter

Machine- Level Programming I: Basics

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

The Hardware/Software Interface CSE351 Spring 2015

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

CISC 360 Instruction Set Architecture

Instruction Set Architecture

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1

Compiler Construction D7011E

Sungkyunkwan University

An Experience Like No Other. Stack Discipline Aug. 30, 2006

CS , Fall 2001 Exam 1

Transcription:

Machine-Level Programming Introduction Today Assembly programmer s exec model Accessing information Arithmetic operations Next time More of the same Fabián E. Bustamante, Spring 2007

IA32 Processors Totally dominate computer market Evolutionary design Starting in 1978 with 8086 Added more features as time goes on Backward compatibility: able to run code for earlier version Complex Instruction Set Computer (CISC) Many different instructions with many different formats But, only small subset encountered with Linux programs Hard to match performance of Reduced Instruction Set Computers (RISC) But, Intel has done just that! X86 evolution clones: Advanced Micro Devices (AMD) Historically followed just behind Intel a little bit slower, a lot cheaper 2

X86 Evolution: Programmer s view Name Date Transistors Comments 8086 1978 29k 16-bit processor, basis for IBM PC & DOS; limited to 1MB address space 80286 1982 134K Added elaborate, but not very useful, addressing scheme; basis for IBM PC AT and Windows 386 1985 275K Extended to 32b, added flat addressing, capable of running Unix, Linux/gcc uses 486 1989 1.9M Improved performance; integrated FP unit into chip Pentium 1993 3.1M Improved performance PentiumPro (P6) Pentium/ MMX 1995 6.5M Added conditional move instructions; big change in underlying microarchitecture 1997 6.5M Added special set of instructions for 64-bit vectors of 1, 2, or 4 byte integer data Pentium II 1997 7M Merged Pentium/MMZ and PentiumPro implementing MMX instructions within P6 Pentium III 1999 8.2M Instructions for manipulating vectors of integers or floating point; later versions included Level2 cache Pentium 4 2001 42M 8 byte ints and floating point formats to vector instructions 3

X86 Evolution: Programmer s view Name Date Transistors Comments Pentium 4E 2004 125M Hyperthreading (execute 2 programs on one processor), EM64T 64-bit extension Core 2 2006 291M first multi-core; similar to P6; no hyperthreading Core i7 2008 781M multi-core with hyperthreading; 2 programs on each core, up to 4 cores per chip; 4

Assembly programmer s view %eip CPU Registers Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Stack Programmer-Visible State %eip Program Counter %rip in 64bit Address of next instruction Register file (8x32bit) Heavily used program data Condition codes Store status information about most recent arithmetic operation Used for conditional branching Floating point register file Memory Byte addressable array Code, user data, (some) OS data Includes stack used to support procedures 5

Turning C into object code Code in files p1.c p2.c Compile with command: gcc O2 p1.c p2.c -o p Use level 2 optimizations (-O2); put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm program (p1.s p2.s) Assembler (gcc or as) binary binary Object program (p1.o p2.o) Linker (gcc or ld) Executable program (p) Static libraries (.a) 6

Compiling into assembly code.c (C source) int sum(int x, int y) { int t = x+y; return t; } ordinary text file might see "leave" Text gcc -S code.c -O1 code.s (GAS Gnu Assembler) sum: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax addl 8(%ebp),%eax popl %ebp ret 7

Assembly characteristics gcc default target architecture: I386 (flat addressing) Minimal data types Integer data of 1, 2, or 4 bytes Data values or addresses Floating point data of 4, 8, or 10 bytes No aggregate types such as arrays or structures Just contiguously allocated bytes in memory Primitive operations Perform arithmetic function on register or memory data Transfer data between memory and register Load data from memory into register Store register data into memory Transfer control Unconditional jumps to/from procedures Conditional branches 8

Object code Code for sum 0x401040 <sum>: 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x08 0x89 0xec 0x5d 0xc3 0x55 gcc -c code.c -O1 Assembler Translates.s into.o Binary encoding of each instruction Nearly-complete image of exec code But unresolved linkages between code in different files, such as function calls Total of 13 bytes Each instruction 1, 2, or 3 bytes Starts at address 0x401040 9

Getting an executable To generate an executable requires the linker resolves references between files, e.g., function calls, including to library functions like printf() dynamic linking leaves references for resolution at run-time checks that there is one and only one main() function gcc -o code.o main.c -O1 int main() { return sum(1, 3); } 10

Machine instruction example int t = x+y; addl 8(%ebp),%eax Similar to C expression x += y 0x401046: 03 45 08 C Code Add two signed integers Assembly Add 2 4-byte integers Long words in GCC parlance Same instruction whether signed or unsigned Operands: x: Register %eax y: Memory M[%ebp+8] t: Register %eax Return function value in %eax Object code 3-byte instruction Stored at address 0x401046 11

Disassembling object code Disassembled 00401040 <_sum>: 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 8b 45 0c mov 0xc(%ebp),%eax 6: 03 45 08 add 0x8(%ebp),%eax 9: 89 ec mov %ebp,%esp b: 5d pop %ebp c: c3 ret d: 8d 76 00 lea 0x0(%esi),%esi Disassembler objdump -d code (otool -tv on MacOS X) Useful tool for examining object code Analyzes bit pattern of series of instructions Produces approximate rendition of assembly code Can be run on either a.out (complete executable) or.o file 12

Alternate disassembly Object 0x401040: 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x08 0x89 0xec 0x5d 0xc3 Disassembled 0x401040 <sum>: push %ebp 0x401041 <sum+1>: mov %esp,%ebp 0x401043 <sum+3>: mov 0xc(%ebp),%eax 0x401046 <sum+6>: add 0x8(%ebp),%eax 0x401049 <sum+9>: mov %ebp,%esp 0x40104b <sum+11>: pop %ebp 0x40104c <sum+12>: ret 0x40104d <sum+13>: lea 0x0(%esi),%esi Within gdb debugger Once you know the length of sum using the dissambler Examine the 13 bytes starting at sum gdb code.o x/13b sum 13

Data formats word (Intel) 16b data type (historical) 32b double word 64b quad words In GAS, operator suffix indicates word size involved. The overloading of l (long) OK because FP involves different operations & registers C decl Intel data type GAS suffix Size (bytes) char Byte b 1 short Word w 2 int, unsigned, long int, unsigned long, char * Double word l 4 float Single precision s 4 double Double precision l 8 long double Extended precision t 10/12 14

Registers Eight 32bit registers First six mostly general purpose Last two used for process stack First four also support access to low order bytes and words 15 Stack pointer 31 15 8 7 0 %eax %ecx %edx %ebx %esi %edi %esp %ax %ah %al %cx %ch %cl %dx %dh %dl %bx %bh %bl %si %di %sp Frame pointer %ebp %bp

Instruction formats Most instructions have 1 or 2 operands operator [source[, destination]] Operand types: Immediate constant, denoted with a $ in front Register either 8 or 16 or 32bit registers Memory location given by an effective address Source: constant or value from register or memory Destination: register or memory 16

Operand specifiers Operand forms Imm means a number E a means a register form, e.g., %eax s is 1, 2, 4 or 8 (called the scale factor) Memory form is the most general; subsets also work, e.g., Absolute: Imm M[Imm] Base + displacement: Imm(E b ) M[Imm + R[E b ]] Operand values R[E a ] means "value in register" M[loc] means "value in memory location loc" Type Form Operand value Name Immediate $Imm Imm Immediate Register E a R[E a ] Register Memory Imm (E b, E i, s) M[Imm + R[E b ] + R[E i ] * s] Scaled indexed 17

Operand specifiers Memory form has many subsets Don t confuse $Imm with Imm, or Ea with (Ea) Type Form Operand value Name Memory Imm M[Imm] Absolute Memory (E a ) M[R[E b ]] Indirect Memory Imm (E b ) M[Imm + R[E b ]] Base + displacement Memory (E b, E i ) M[R[E b ] + R[E i ]] Indexed Memory Imm (E b, E i ) M[Imm + R[E b ] + R[E i ]] Indexed Memory (, E i, s) M[R[E i ] * s] Scaled indexed Memory Imm (, E i, s) M[Imm + R[E i ] * s] Scaled indexed Memory (E b, E i, s) M[R[E b ] + R[E i ] * s] Scaled indexed Memory Imm (E b, E i, s) M[Imm + R[E b ] + R[E i ] * s] Scaled indexed 18

Checkpoint

Moving data Among the most common instructions IA32 restriction cannot move from one memory location to another with one instruction Note the differences between movb, movsbl and movzbl Last two work with the stack pushl %ebp = subl $4, %esp movl %ebp, (%esp) Since stack is part of program mem, you can really access all Instruction Effect Description mov{l,w,b} S,D D S Move double word, word or byte movsbl S,D D SignExtend(S) Move sign-extended byte movzbl S,D D ZeroExtend(S) Move zero-extended byte pushl S R[%esp] R[%esp] 4; M[R[%esp]] S Push S onto the stack popl D D M[R[%esp]] R[%esp] R[%esp] + 4; Pop S from the stack 20

movl operand combinations Source Destination C Analog Imm Reg Mem movl $0x4,%eax movl $-147,(%eax) temp = 0x4; *p = -147; movl Reg Reg Mem movl %eax,%edx movl %eax,(%edx) temp2 = temp1; *p = temp; Mem Reg movl (%eax),%edx temp = *p; 21

Using simple addressing modes void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; } *xp = t1; *yp = t0; Declares xp as being a pointer to an int Read value stored in location xp and store it in t0 swap: pushl %ebp movl %esp,%ebp pushl %ebx movl 8(%ebp),%edx movl 12(%ebp),%ecx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret Set Up Body Finish 22

Understanding swap void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } Register! %ecx %edx %eax %ebx Variable yp xp t1 t0 yp xp movl 12(%ebp),%ecx movl 8(%ebp),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) Offset 12 8 4 %ebp 0-4 123 456 Rtn adr Old %ebp Old %ebx Address 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 # ecx = yp # edx = xp # eax = *yp (t1) # ebx = *xp (t0) # *xp = eax # *yp = ebx 23

Understanding swap %eax %edx %ecx %ebx %esi %edi %esp %ebp Address 123 456 0x11c 0x118 yp xp Offset 12 8 4 Rtn adr 0x114 0x110 0x10c 0x108 %ebp 0-4 0x104 0x100 movl 12(%ebp),%ecx # ecx = yp 0x104 movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 24

Understanding swap %eax %edx %ecx %ebx %esi %edi %esp %ebp Address 123 456 0x11c 0x118 yp xp Offset 12 8 4 Rtn adr 0x114 0x110 0x10c 0x108 %ebp 0-4 0x104 0x100 movl 12(%ebp),%ecx # ecx = yp 0x104 movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 25

Understanding swap %eax %edx %ecx %ebx %esi %edi %esp %ebp Address 123 456 0x11c 0x118 yp xp Offset 12 8 4 Rtn adr 0x114 0x110 0x10c 0x108 %ebp 0-4 0x104 0x100 movl 12(%ebp),%ecx # ecx = yp 0x104 movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 26

Understanding swap %eax %edx %ecx %ebx %esi %edi %esp %ebp 456 Address 123 456 0x11c 0x118 yp xp Offset 12 8 4 Rtn adr 0x114 0x110 0x10c 0x108 %ebp 0-4 0x104 0x100 movl 12(%ebp),%ecx # ecx = yp 0x104 movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 27

Understanding swap %eax %edx %ecx %ebx %esi %edi %esp %ebp 456 123 Address 123 456 0x11c 0x118 yp xp Offset 12 8 4 Rtn adr 0x114 0x110 0x10c 0x108 %ebp 0-4 0x104 0x100 movl 12(%ebp),%ecx # ecx = yp 0x104 movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 28

Understanding swap %eax %edx %ecx %ebx %esi %edi %esp %ebp 456 123 Address 456 456 0x11c 0x118 yp xp Offset 12 8 4 Rtn adr 0x114 0x110 0x10c 0x108 %ebp 0-4 0x104 0x100 movl 12(%ebp),%ecx # ecx = yp 0x104 movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 29

Understanding swap %eax %edx %ecx %ebx %esi %edi %esp %ebp 456 123 Address 456 123 0x11c 0x118 yp xp Offset 12 8 4 Rtn adr 0x114 0x110 0x10c 0x108 %ebp 0-4 0x104 0x100 movl 12(%ebp),%ecx # ecx = yp 0x104 movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 30

Checkpoint

Address computation instruction leal S,D D &S leal = Load Effective Address S is address mode expression Set D to address denoted by expression Uses Computing address w/o doing memory reference E.g., translation of p = &x[i]; Computing arithmetic expressions of form x + k*y k = 1, 2, 4, or 8. leal 7(%edx,%edx,4), %eax when %edx=x, %eax becomes 5x+7 32

Checkpoint

Some arithmetic operations Instruction Effect Description incl D D D + 1 Increment decl D D D 1 Decrement negl D D -D Negate notl D D ~D Complement addl S,D D D + S Add subl S,D D D S Subtract imull S,D D D * S Multiply xorl S,D D D ^ S Exclusive or orl S,D D D S Or andl S,D D D & S And sall k,d D D << k Left shift, 0 k 31, Imm or %cl shll k,d D D << k Left shift (same as sall) sarl k,d D D >> k Arithmetic right shift shrl k,d D D >> k Logical right shift 34

Checkpoint

Using leal for arithmetic expressions int arith (int x, int y, int z) { int t1 = x+y; int t2 = z+t1; int t3 = x+4; int t4 = y * 48; int t5 = t3 + t4; int rval = t2 * t5; return rval; } arith: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax movl 12(%ebp),%edx leal (%edx,%eax),%ecx leal (%edx,%edx,2),%edx sall $4,%edx addl 16(%ebp),%ecx leal 4(%edx,%eax),%eax imull %ecx,%eax movl %ebp,%esp popl %ebp ret Set Up Body Finish 36

Understanding arith int arith (int x, int y, int z) { int t1 = x+y; int t2 = z+t1; int t3 = x+4; int t4 = y * 48; int t5 = t3 + t4; int rval = t2 * t5; return rval; } Offset 16 12 8 4 0 z y x Rtn adr Old %ebp Stack %ebp movl 8(%ebp),%eax # eax = x movl 12(%ebp),%edx # edx = y leal (%edx,%eax),%ecx # ecx = x+y (t1) leal (%edx,%edx,2),%edx # edx = 3*y sall $4,%edx # edx = 48*y (t4) addl 16(%ebp),%ecx # ecx = z+t1 (t2) leal 4(%edx,%eax),%eax # eax = 4+t4+x (t5) imull %ecx,%eax # eax = t5*t2 (rval) 37

Another example int logical(int x, int y) { int t1 = x^y; int t2 = t1 >> 17; int mask = (1<<13) - 7; int rval = t2 & mask; return rval; } mask 2 13 = 8192, 2 13 7 = 8185 logical: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax xorl 8(%ebp),%eax sarl $17,%eax andl $8185,%eax movl %ebp,%esp popl %ebp ret Set Up Body Finish movl 8(%ebp),%eax eax = x xorl 12(%ebp),%eax eax = x^y (t1) sarl $17,%eax eax = t1>>17 (t2) andl $8185,%eax eax = t2 & 8185 38

CISC Properties Instruction can reference different operand types Immediate, register, memory Arithmetic operations can read/write memory Memory reference can involve complex computation Rb + S*Ri + D Useful for arithmetic expressions, too Instructions can have varying lengths IA32 instructions can range from 1 to 15 bytes 39

Whose assembler? Intel/Microsoft Format lea eax,[ecx+ecx*2] sub esp,8 cmp dword ptr [ebp-8],0 mov eax,dword ptr [eax*4+100h] GAS/Gnu Format leal (%ecx,%ecx,2),%eax subl $8,%esp cmpl $0,-8(%ebp) movl $0x100(,%eax,4),%eax Intel/Microsoft Differs from GAS Operands listed in opposite order mov Dest, Src movl Src, Dest Constants not preceded by $, Denote hex with h at end 100h $0x100 Operand size indicated by operands rather than operator suffix sub subl Addressing format shows effective address computation [eax*4+100h] $0x100(,%eax,4) 40