Machine-Level Programming I: Introduction Jan. 23, 2003IA32 ProcessorsX86 Evolution: Programmer’s ViewSlide 4Slide 5X86 Evolution: ClonesSlide 7New Species: IA64Assembly Programmer’s ViewTurning C into Object CodeCompiling Into AssemblyAssembly CharacteristicsObject CodeMachine Instruction ExampleDisassembling Object CodeAlternate DisassemblyWhat Can be Disassembled?Moving Datamovl Operand CombinationsSimple Addressing ModesUsing Simple Addressing ModesUnderstanding SwapSlide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Indexed Addressing ModesAddress Computation ExamplesAddress Computation InstructionSome Arithmetic OperationsSlide 34Using leal for Arithmetic ExpressionsUnderstanding arithSlide 37Another ExampleCISC PropertiesSummary: Abstract MachinesPentium Pro (P6)PentiumPro Block DiagramPentiumPro OperationWhose Assembler?Machine-Level Programming I:IntroductionJan. 23, 2003Machine-Level Programming I:IntroductionJan. 23, 2003TopicsTopicsAssembly Programmer’s Execution ModelAccessing InformationRegistersMemoryArithmetic operationsclass05.ppt15-213“The course that gives CMU its Zip!”– 2 –15-213, S’03IA32 ProcessorsIA32 ProcessorsTotally Dominate Computer MarketTotally Dominate Computer MarketEvolutionary DesignEvolutionary DesignStarting in 1978 with 8086Added more features as time goes onStill support old features, although obsoleteComplex Instruction Set Computer (CISC)Complex Instruction Set Computer (CISC)Many different instructions with many different formatsBut, only small subset encountered with Linux programsHard to match performance of Reduced Instruction Set Computers (RISC)But, Intel has done just that!– 3 –15-213, S’03X86 Evolution: Programmer’s ViewX86 Evolution: Programmer’s ViewNameNameDateDateTransistorsTransistors808680861978197829K29K16-bit processor. Basis for IBM PC & DOSLimited to 1MB address space. DOS only gives you 640K802868028619821982134K134KAdded elaborate, but not very useful, addressing schemeBasis for IBM PC-AT and Windows38638619851985275K275KExtended to 32 bits. Added “flat addressing”Capable of running UnixLinux/gcc uses no instructions introduced in later models– 4 –15-213, S’03X86 Evolution: Programmer’s ViewX86 Evolution: Programmer’s ViewNameNameDateDateTransistorsTransistors486486198919891.9M1.9MPentiumPentium199319933.1M3.1MPentium/MMXPentium/MMX199719974.5M4.5MAdded special collection of instructions for operating on 64-bit vectors of 1, 2, or 4 byte integer dataPentiumProPentiumPro199519956.5M6.5MAdded conditional move instructionsBig change in underlying microarchitecture– 5 –15-213, S’03X86 Evolution: Programmer’s ViewX86 Evolution: Programmer’s ViewNameNameDateDateTransistorsTransistorsPentium IIIPentium III199919998.2M8.2MAdded “streaming SIMD” instructions for operating on 128-bit vectors of 1, 2, or 4 byte integer or floating point dataOur fish machinesPentium 4Pentium 42001200142M42MAdded 8-byte formats and 144 new instructions for streaming SIMD mode– 6 –15-213, S’03X86 Evolution: ClonesX86 Evolution: ClonesAdvanced Micro Devices (AMD)Advanced Micro Devices (AMD)HistoricallyAMD has followed just behind IntelA little bit slower, a lot cheaperRecentlyRecruited top circuit designers from Digital Equipment Corp.Exploited fact that Intel distracted by IA64Now are close competitors to IntelDeveloping own extension to 64 bits– 7 –15-213, S’03X86 Evolution: ClonesX86 Evolution: ClonesTransmetaTransmetaRecent start-upEmployer of Linus TorvaldsRadically different approach to implementationTranslates x86 code into “Very Long Instruction Word” (VLIW) codeHigh degree of parallelismShooting for low-power market– 8 –15-213, S’03New Species: IA64New Species: IA64NameNameDateDateTransistorsTransistorsItaniumItanium2001200110M10MExtends to IA64, a 64-bit architectureRadically new instruction set designed for high performanceWill be able to run existing IA32 programsOn-board “x86 engine”Joint project with Hewlett-PackardItanium 2Itanium 220022002221M221MBig performance boost– 9 –15-213, S’03Assembly Programmer’s ViewAssembly Programmer’s ViewProgrammer-Visible StateProgrammer-Visible StateEIP Program CounterAddress of next instructionRegister FileHeavily used program dataCondition CodesStore status information about most recent arithmetic operationUsed for conditional branchingEIPRegistersCPUMemoryObject CodeProgram DataOS DataAddressesDataInstructionsStackConditionCodesMemoryByte addressable arrayCode, user data, (some) OS dataIncludes stack used to support procedures– 10 –15-213, S’03texttextbinarybinaryCompiler (gcc -S)Assembler (gcc or as)Linker (gcc or ld)C program (p1.c p2.c)Asm program (p1.s p2.s)Object program (p1.o p2.o)Executable program (p)Static libraries (.a)Turning C into Object CodeTurning C into Object CodeCode in files p1.c p2.cCompile with command: gcc -O p1.c p2.c -o pUse optimizations (-O)Put resulting binary in file p– 11 –15-213, S’03Compiling Into AssemblyCompiling Into AssemblyC CodeC Codeint sum(int x, int y){ int t = x+y; return t;}Generated Assembly_sum:pushl %ebpmovl %esp,%ebpmovl 12(%ebp),%eaxaddl 8(%ebp),%eaxmovl %ebp,%esppopl %ebpretObtain with commandgcc -O -S code.cProduces file code.s– 12 –15-213, S’03Assembly CharacteristicsAssembly CharacteristicsMinimal Data TypesMinimal Data Types“Integer” data of 1, 2, or 4 bytesData valuesAddresses (untyped pointers)Floating point data of 4, 8, or 10 bytesNo aggregate types such as arrays or structuresJust contiguously allocated bytes in memoryPrimitive OperationsPrimitive OperationsPerform arithmetic function on register or memory dataTransfer data between memory and registerLoad data from memory into registerStore register data into memoryTransfer controlUnconditional jumps to/from proceduresConditional branches– 13 –15-213, S’03Code for sum0x401040 <sum>:0x550x890xe50x8b0x450x0c0x030x450x080x890xec0x5d0xc3Object CodeObject CodeAssemblerAssemblerTranslates .s into .oBinary encoding of each instructionNearly-complete image of executable codeMissing linkages between code in different filesLinkerLinkerResolves references between filesCombines with static run-time librariesE.g., code for malloc, printfSome
View Full Document