Machine-Level Programming I:IntroductionJan. 22, 2008TopicsAssembly Programmer’s Execution ModelAccessing InformationRegistersMemoryArithmetic operationsclass04.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 Solutionx86-64 (now called “AMD64”)Intel Felt Obligated to Focus on IA64Hard to admit mistake or that AMD is better2004: Intel Announces EM64T extension to IA32Extended Memory 64-bit TechnologyAlmost identical to x86-64!Our Saltwater fish machines1815-213, S’08Our CoverageIA32The traditional x86x86-64The emerging standardPresentationBook has IA32Handout has x86-64Lecture will cover bothLabsLab #2 x86-64Lab #3 IA321915-213, S’08Assembly Programmer’s ViewProgrammer-Visible StatePC Program CounterAddress of next instructionCalled “EIP” (IA32) or “RIP” (x86-64)Register FileHeavily used program dataCondition CodesStore status information about most recent arithmetic operationUsed for conditional branchingPCRegistersCPU MemoryObject CodeProgram DataOS DataAddressesDataInstructionsStackConditionCodesMemoryByte addressable arrayCode, user data, (some) OS dataIncludes stack used to support procedures2015-213, S’08texttextbinarybinaryCompiler (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 CodeCode in
View Full Document