IA32 Processors 15 213 Totally Dominate Computer Market The course that gives CMU its Zip Machine Level Programming I Introduction Sept 10 2002 Topics n n Evolutionary Design n Starting in 1978 with 8086 n Added more features as time goes on n Still support old features although obsolete Complex Instruction Set Computer CISC Assembly Programmer s Execution Model n l But only small subset encountered with Linux programs Accessing Information l Registers n Hard to match performance of Reduced Instruction Set Computers RISC n But Intel has done just that l Memory n Arithmetic operations X86 Evolution Programmer s View 8086 Transistors 1978 29K n Limited to 1MB address space DOS only gives you 640K 1982 134K n Added elaborate but not very useful addressing scheme n Basis for IBM PC AT and Windows n 1985 X86 Evolution Programmer s View Name 16 bit processor Basis for IBM PC DOS 386 3 Date n 80286 15 213 F 02 2 class05 ppt Name Many different instructions with many different formats Date Transistors 486 1989 1 9M Pentium 1993 3 1M Pentium MMX 1997 4 5M n Added special collection of instructions for operating on 64bit vectors of 1 2 or 4 byte integer data PentiumPro 275K Extended to 32 bits Added flat addressing n Capable of running Unix n Linux gcc uses no instructions introduced in later models 15 213 F 02 4 1995 6 5M n Added conditional move instructions n Big change in underlying microarchitecture 15 213 F 02 X86 Evolution Programmer s View Name Pentium III Date Transistors 1999 8 2M Advanced Micro Devices AMD n n Added streaming SIMD instructions for operating on 128 bit vectors of 1 2 or 4 byte integer or floating point data n Our fish machines Pentium 4 n 2001 Historically l AMD has followed just behind Intel l A little bit slower a lot cheaper n Recently l Recruited top circuit designers from Digital Equipment Corp l Exploited fact that Intel distracted by IA64 42M l Now are close competitors to Intel Added 8 byte formats and 144 new instructions for streaming SIMD mode 15 213 F 02 5 X86 Evolution Clones Clones n Developing own extension to 64 bits 15 213 F 02 6 New Species IA64 Transmeta n X86 Evolution Clones Clones Name Date Transistors Itanium 2001 10M Recent start up l Employer of Linus Torvalds n Radically different approach to implementation l Translates x86 code into Very Long Instruction Word VLIW code l High degree of parallelism n Shooting for low power market n Extends to IA64 a 64 bit architecture n Radically new instruction set designed for high performance n Will be able to run existing IA32 programs l On board x86 engine n Joint project with Hewlett Packard Itanium 2 n 7 15 213 F 02 8 2002 221M Big performance boost 15 213 F 02 Assembly Programmer s View CPU Memory Addresses Registers E I P Data Condition Codes Turning C into into Object Object Code Code n Code in files p1 c p2 c n Compile with command gcc O p1 c p2 c o p Object Code Program Data OS Data l Use optimizations O l Put resulting binary in file p Instructions text C program p1 c p2 c Compiler gcc S Stack Programmer Visible State n EIP text Asm program p1 s p2 s Program Counter Assembler gcc or as l Address of next instruction n Register File l Heavily used program data n Condition Codes l Store status information about most recent arithmetic operation 9 l Used for conditional branching n Memory binary l Byte addressable array Compiling Into Assembly Assembly C Code int sum int x int y int t x y return t Static libraries a Linker gcc or ld l Code user data some OS data l Includes stack used to support procedures 15 213 F 02 Object program p1 o p2 o binary Executable program p 15 213 F 02 10 Assembly Characteristics Generated Assembly Minimal Data Types n sum pushl ebp movl esp ebp movl 12 ebp eax addl 8 ebp eax movl ebp esp popl ebp ret Integer data of 1 2 or 4 bytes l Data values l Addresses untyped pointers n Floating point data of 4 8 or 10 bytes n No aggregate types such as arrays or structures l Just contiguously allocated bytes in memory Primitive Operations Obtain with command gcc O S code c n Perform arithmetic function on register or memory data n Transfer data between memory and register l Load data from memory into register Produces file code s l Store register data into memory n Transfer control l Unconditional jumps to from procedures l Conditional branches 11 15 213 F 02 12 15 213 F 02 Object Code Code for sum Machine Instruction Instruction Example Example Assembler n Translates s into o 0x401040 sum n Binary encoding of each instruction 0x55 Total of 13 0x89 n Nearly complete image of executable bytes 0xe5 code Each 0x8b instruction 1 n Missing linkages between code in 0x45 2 or 3 bytes different files 0x0c Starts at 0x03 address Linker 0x45 0x401040 0x08 n Resolves references between files 0x89 n Combines with static run time 0xec libraries 0x5d l E g code for malloc printf 0xc3 n C Code int t x y Some libraries are dynamically linked l Linking occurs when program begins n Assembly n addl 8 ebp eax l Same instruction whether signed or unsigned n 0x401046 03 45 08 Disassembled Object ebp esp ebp 0xc ebp eax 0x8 ebp eax ebp esp ebp 0x0 esi esi objdump d p n Useful tool for examining object code n Analyzes bit pattern of series of instructions n Produces approximate rendition of assembly code Can be run on either a out complete executable or o file n 15 213 F 02 Alternate Disassembly Disassembler 15 3 byte instruction Stored at address 0x401046 14 Disassembled push mov mov add mov pop ret lea Register eax Memory M ebp 8 Register eax Return function value in eax Object Code n Disassembling Object Object Code Code 00401040 sum 0 55 1 89 e5 3 8b 45 0c 6 03 45 08 9 89 ec b 5d c c3 d 8d 76 00 Operands x y t n 15 213 F 02 Add 2 4 byte integers l Long words in GCC parlance Similar to expression x y execution 13 Add two signed integers 0x401040 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x08 0x89 0xec 0x5d 0xc3 0x401040 0x401041 0x401043 0x401046 0x401049 0x40104b 0x40104c 0x40104d sum sum 1 sum 3 sum 6 sum 9 sum 11 sum 12 sum 13 push mov mov add mov pop ret lea ebp esp ebp 0xc ebp eax 0x8 ebp eax ebp esp ebp 0x0 esi esi Within gdb Debugger gdb p disassemble sum Disassemble procedure x 13b sum n 15 213 F 02 n 16 Examine the 13 bytes starting at sum 15 213 F 02 What Can be Disassembled Disassembled Moving Data Data eax edx objdump d WINWORD EXE WINWORD EXE Moving Data file format pei i386 No symbols in WINWORD EXE …
View Full Document