Machine-Level Programming I: Introduction Jan. 22, 2008SynchronizationOutlineA Whitespace ProgramWhitespace “Explained”INTERCALThe language “M”A Program in MSlide 9M is “The Language of the Machines”Everything Else is IllusionIA32 Processorsx86 Evolution: Programmer’s View (Abbreviated)x86 Evolution: Programmer’s ViewNew Species: IA64X86 Evolution: ClonesIntel’s 64-Bit DilemmaOur CoverageAssembly Programmer’s ViewTurning C into Object CodeCompiling Into AssemblyAssembly CharacteristicsObject CodeMachine Instruction ExampleDisassembling Object CodeAlternate DisassemblyWhat Can be Disassembled?Moving Data: IA32movl Operand CombinationsSo Many Addressing Modes?Simple Addressing ModesSlide 32Using Simple Addressing ModesSlide 34Understanding SwapSlide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Indexed Addressing ModesAddress Computation ExamplesAddress Computation InstructionSome Arithmetic OperationsSlide 47Using leal for Arithmetic ExpressionsUnderstanding arithSlide 50Slide 51Slide 52Slide 53Slide 54Another ExampleSlide 56Slide 57Slide 58Data Representations: IA32 + x86-64x86-64 General Purpose RegistersSwap in 32-bit ModeSwap in 64-bit ModeSwap Long Ints in 64-bit ModeSummaryCreditsMachine-Level Programming I:IntroductionJan. 22, 2008TopicsAssembly Programmer’s Execution ModelAccessing InformationRegistersMemoryArithmetic operationsclass03.ppt15-213“The course that gives CMU its Zip!”15-213, S’08215-213, S’08SynchronizationLab 1Time roughly 50% doneMany have started early and made good progressGoodWarning to others...This isn't the same kind of thing you've done beforePlease don't leave it to the last minuteFish-machine log-insPlease let us know (staff mailing list) if you can't log in to any machine315-213, S’08OutlineSome computer languagesWhitespaceIntercalMSome discussion of x86, x86-64Warning: Chapter 3 doesn't compress well100 pages of discussion about machine language... after 75 pages of data representation in Chapter 2Please plan to spend time reading the text!Some computer languagesWhitespaceIntercalMSome discussion of x86, x86-64Warning: Chapter 3 doesn't compress well100 pages of discussion about machine language... after 75 pages of data representation in Chapter 2Please plan to spend time reading the text!415-213, S’08“Count from 1 to 10” (partial listing)A Whitespace ProgramFeatures of WhitespaceOnly space, tab, and line-feed encode program statementsAll other characters (A-Z, a-z, 0-9, etc.) encode commentsSimple stack-based language515-213, S’08Whitespace “Explained” Statement Meaning[Space][Space][Space][Tab][LF]Push 1 onto stack[LF][Space][Space][Space][Tab][Space][Space][Space][Space][Tab][Tab][LF]Set a label at this point[Space][LF][Space] Duplicate the top stack item[Tab][LF][Space][Tab] Output the current value... ...615-213, S’08INTERCALFeatures of INTERCALDesigned late one night in 1972 by two Princeton studentsDeliberately obfuscated languageVariables16-bit integers, .1 through .6553532-bit integers, :1 through :65535OperatorsBinary: “mingle”, “select”Unary: AND, OR, XORHow are those unary???Simple: AND and's together adjacent bits in a wordSimplest way to put 65536 in a 32-bit variable?DO :1 <- #0¢#256715-213, S’08The language “M”Features of MAlso designed in the 1970'sMore widely used than Whitespace, INTERCALVariables32-bit integer variables: A, B, C, D, DI, F, S, SIOne array, M[]Valid subscripts range from near zero to a large numberBut most subscripts in that range will crash your program!StatementsLots of arithmetic and logical operationsInput and output use a special statement called OUCH!815-213, S’08A Program in MC Codeint sum(int x, int y){ int t = x+y; return t;}Msum:A = M[S+4]A += M[S+8]DONE915-213, S’08A Program in MC Codeint sum(int x, int y){ int t = x+y; return t;}Msum:A = M[S+4]A += M[S+8]DONEHad enough of M?Too bad! We'll study it for much of the semester!Why???1015-213, S’08M is “The Language of the Machines”1115-213, S’08Everything Else is Illusion1215-213, S’08IA32 ProcessorsTotally Dominate Computer MarketEvolutionary DesignStarting in 1978 with 8086Added more features as time goes onStill support old features, although obsoleteComplex 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!1315-213, S’08x86 Evolution: Programmer’s View(Abbreviated)Name Date Transistors8086 1978 29K16-bit processor. Basis for IBM PC & DOSLimited to 1MB address space. DOS only gives you 640K386 1985 275KExtended to 32 bits. Added “flat addressing”Capable of running UnixReferred to as “IA32”32-bit Linux/gcc uses no instructions introduced in later models1415-213, S’08x86 Evolution: Programmer’s ViewMachine Evolution486 1989 1.9MPentium 1993 3.1MPentium/MMX 1997 4.5MPentiumPro 1995 6.5MPentium III 1999 8.2MPentium 4 2001 42MAdded FeaturesInstructions to support multimedia operationsParallel operations on 1, 2, and 4-byte data, both integer & FPInstructions to enable more efficient conditional operationsLinux/GCC EvolutionNone!1515-213, S’08New Species: IA64Name Date TransistorsItanium 2001 10MExtends to IA64, a 64-bit architectureRadically new instruction set designed for high performanceCan run existing IA32 programsOn-board “x86 engine”Joint project with Hewlett-PackardItanium 2 2002 221MBig performance boostItanium 2 Dual-Core 2006 1.7BItanium has not taken off in marketplaceLack of backward compatibility1615-213, S’08X86 Evolution: ClonesAdvanced Micro Devices (AMD)HistoricallyAMD has followed just behind IntelA little bit slower, a lot cheaperRecentlyRecruited top circuit designers from Digital Equipment Corp. and other downward trending companiesExploited fact that Intel distracted by IA64Now are close competitors to IntelDeveloped x86-64, its own extension to 64 bits Started eating into Intel’s high-end server market1715-213, S’08Intel’s 64-Bit DilemmaIntel Attempted Radical Shift from IA32 to IA64Totally different architectureExecutes IA32 code only as legacyPerformance disappointingAMD Stepped in with Evolutionary
View Full Document