SlideShare a Scribd company logo
1 of 5
Ch.2 Hennessy 1
Ch.2 (Henn): Instructions – Language of the Computer
Supplement(s): HennessyChapter 2 Supplement, Hennessy Chapter 2 – Formulae, Examples and Exercises
Objectives:
 Introduction
 Operations and operands of the Computer Hardware,
 Signed and Unsigned Numbers
 Representing Instructions in the Computer
 Logical Operations, Instructions for Making Decisions
 Supporting Procedures in Computer Hardware
 MIPS Addressing for 32-Bit Immediates and Addresses
 Parallelism and Instructions: Synchronization
 Translating and Starting a Program
 A C Sort Example to Put It All Together
 Arrays versus Pointers
 Real Stuff: ARM Instructions
 Real Stuff: x86 Instructions
 Fallacies and Pitfalls
 Concluding Remarks
 To commanda computer’s hardware, you must speakits language. The words of a computer’s language are calledinstructions, andits
vocabularyis calledan instructionset. In this chapter, you will see the instruction set of a real computer, both in the form written bypeople
and inthe form read bythe computer. We introduce instructions ina top-downfashion. Startingfrom a notationthat looks like a restricted
programminglanguage, we refine it step-by-stepuntil you see the real language ofa real computer. Chapter 3 continues our downward
descent, unveilingthe hardware for arithmetic andthe representation offloating-point numbers.
 You might thinkthat the languagesof computers wouldbe as diverse as those ofpeople, but inrealitycomputer languages are quite similar,
more like regional dialects thanlike independent languages. Hence, once you learnone, it is easyto pickupothers. This similarityoccurs
because all computers are constructedfromhardware technologies based onsimilar underlying principles andbecause there are a few basic
operations that allcomputers must provide. Moreover, computer designers have a common goal:to finda language that makesit easyto
buildthe hardware andthe compiler while maximizing performance andminimizing cost andpower.
 It is easyto see byformal-logicalmethods that there exist certain[instruction sets]that are in abstract adequate to control andcause the
executionof anysequence of operations . . . . The reallydecisive considerations from the present point of view, inselecting an[instruction
set], are more ofa practicalnature:simplicityof the equipment demandedbythe [instruction set], and the clarityof its a pplicationto the
actuallyimportant problems together withthe speedof its handling of those problems.— Burks,Goldstine,andvon Neumann,1947
 The “simplicityof the equipment” is as valuable a considerationfor today’s computers as it was for those ofthe 1950s. The goalof this
chapter is to teach aninstructionset that follows thisadvice, showing both howit is represented in hardware andthe relationshipbetween
high-level programming languages andthis more primitive one. Our examplesare inthe Cprogramming language; Section2.15 on the CD
shows how these wouldchange for an object-oriented language like Java.
 By learninghowto represent instructions, you will alsodiscover the secret ofcomputing:the stored-program concept (The ideathat
instructions and data of manytypes can be storedin memoryas numbers, leading to the storedprogram skills bywritingprograms inthe
language of the computer andrunning them onthe simulator that comeswith this book. You will alsosee the impact of programming
languages andcompiler optimizationonperformance. We conclude with a lookat the historical evolutionof instructionsets andanoverview
of other computer dialects.
 The chosen instructionset comes fromMIPS Technologies, whichis anelegant example of the instructionsets designedsince the 1980s.
Later, we will take a quick lookat two other popular instructionsets. ARMis quite similar to MIPS. The other example is the popular Intel
x86.
Operations of the Computer Hardware
 The MIPS assemblylanguage notation add a, b, c instructs a computer to add the twovariables b and c andto put their sumin a. This
notationis rigidinthat each MIPS arithmetic instructionperforms onlyone operationandmust always have exactlythree variables. For
example, suppose we want to place the sumof four variables b, c, d, and e intovariable a. The followingsequence ofinstructions adds the
four variables (Thus, it takesthree instructions to sumthe four variables):
Ch.2 Hennessy 2
The words to the right ofthe sharpsymbol (#) on eachline above a re comments for the humanreader, andthe computer ignoresthem.
Note that unlike other programming languages, eachline ofthis language can contain at most one instruction. Another difference fromCis
that comments always terminate at the endof a line.
 The natural number of operands for anoperationlike additionis three:the two numbers being addedtogether anda place to p ut the sum.
Requiring everyinstructionto have exactlythree operands, conforms to the philosophyof keeping the hardware simple: hardware for a
variable number of operands is more complicatedthanhardware for a fixednumber. This situationillustrates the first of four underlying
principles of hardware design: -> DesignPrinciple 1: Simplicity favors regularity. We can nowshow, in the twoexamples that follow, the
relationshipof programs writtenin higher-level programming languages to programs inthismore primitive notation.
 Compiling Two C Assignment Statements into MIPS: This is done bythe compiler, andthe below are the CandMIPS codes:
Ch.2 Hennessy 3
 Compiling a Complex C Assignment into MIPS: f = (g + h) – (i + j);
OPERANDS OF THE COMPUTER HARDWARE
 Unlike programs inhigh-level languages, the operands ofarithmetic instructions are restricted;theymust be from a limitednumber of
speciallocations built directlyinhardware calledregisters. Registers are primitives usedin hardware design. The size of a register in the MIPS
architecture is 32 bits;groups of32 bits occur sofrequentlythat theyare giventhe name word in the MIPSarchitecture. A word is the
natural unit of access in a computer, usuallya groupof 32 bits;corresponds to the size ofa register in the MIPS architecture.
 One major difference betweenthe variablesof a programming language and registers is the limited number of registers, typically32 on
current computers, like MIPS. In thissection, we have addedthe restrictionthat the three operands ofMIPS arithmetic instructions must
each be chosen from one of the 32 32-bit registers.
 The reason for the limit of32 registers maybe foundinthe secondof our four underlying designprinciples ofhardware technology: Design
Principle 2 – Smalleris faster. A very large number of registers mayincrease the clockcycle time simplybecause it takes electronic signals
longer whentheymust travel farther. In this case, the designer must balance the craving ofprograms for more registers with the
designer’s desire to keep the clock cycle fast. Another reason for not usingmore than32 is the number ofbits it wouldtake inthe
instruction format, as Section2.5 demonstrates.
 Chapter 4 shows the central role that registers playinhardware construction;as we shall see inthischapter, effective use ofregisters is
critical to programperformance. Although we couldsimplywrite instructions usingnumbers for registers, from 0 to 31, the MIPS convention
is to use two-character names following a dollar signto represent a register. Section2.8 willexplainthe reasons behindthese names. For
now, we will use $s0, $s1, . . . for registers that correspondto variablesinCandJava programs and$t0, $t1, . . . for temp oraryregisters
neededto compile the programintoMIPS instructions.
 Compiling a CAssignment Using Registers: It is the compiler’s job to associate programvariableswith registers. Take, for instance, the
assignment statement fromour earlier example: f = (g + h) – (i + j);The variables f, g, h, i, andj are assignedto the registers $s0, $s1, $s2,
$s3, and $s4, respectively. The compiledMIPS program is verysimilar to the prior example, except we replace the variableswiththe register
names mentioned above plus two temporaryregisters, $t0 and$t1, which correspondto the temporaryvariables above.
 Memory Operands: Programming languages have simple variables that containsingle data elements, as inthese examples, but theyalso
have more complex data structures—arrays andstructures. These complex data structures cancontainmanymore data elements than there
are registers in a computer. The processor can keeponlya smallamount of data inregisters, but computer memorycontains billions of data
elements. Hence, data structures (arrays andstructures) are kept in memory.
 As explained above, arithmetic operations occur onlyon
registers inMIPS instructions;thus, MIPS must include instructions
that transfer data betweenmemoryandregisters. Such instructions
are calleddata transfer instructions. To accessa word in memory,
the instruction must supplythe memoryaddress. Memoryis just a
large, single-dimensionalarray, with the addressacting as the index
to that array, startingat 0. (MIPS usesbyte-addressing, not word-
addressing). The data transfer instruction that copiesdata from
memoryto a register is traditionallycalledload. The format of the
loadinstruction is the name of the operation followedbythe
register to be loaded, thena constant and register usedto access
memory. The sumof the constant portionof the instructionand
the contents ofthe secondregister forms the memoryaddress. The
actual MIPSname for this instruction is lw, standingfor load word.
E.g.:
lw $t0,8($s3) # Temporary reg $t0 gets A[8]
 In addition to associatingvariableswithregisters, the
compiler allocates data structures like arrays andstructures to
Ch.2 Hennessy 4
locations in memory. The compiler canthenplace the proper starting address into the data transfer instructions.
 The address ofa wordmatches the address of one of the 4 bytes withinthe word, andaddresses ofsequential words differ by4.InMIPS,
words must start at addresses that are multiples of 4. This requirement is called analignment restriction(alignment restriction is a
requirement that data be alignedinmemoryon natural boundaries), andmanyarchitectures have it. Chapter 4 suggests whyalignment
leads to faster data transfers.)
 Computers divide intothose that use the addressof the leftmost or “big end” byte as the word addressversus those that use the rightmost
or “little end” byte. MIPS is inthe big-endian camp. (Appendix B, shows the two options to number bytes in a word.) Byte addressing also
affects the arrayindex. To get the proper byte address inthe code above, the offset to be added to the base register $s3 must be 4 × 8, or
32, so that the load addresswill select A[8] andnot A[8/4]. (See the relatedpitfall onpage 175 of Section 2.18.)
 The instruction complementaryto load is traditionallycalledstore; it copiesdata froma register to memory. The format of a store is similar
to that of a load:the name ofthe operation, followed bythe register to be stored, thenoffset to select the arrayelement, and finallythe
base register. Once again, the MIPS addressis specified inpart bya constant and inpart bythe contents of a register. The actual MIPS name
is sw, standing for store word.
 Manyprograms have more variablesthan computers
have registers. Consequently, the compiler tries to keepthe most
frequentlyusedvariablesinregisters andplaces the rest in
memory, using loads andstores to move variablesbetween
registers andmemory. The process of putting less commonlyused
variables (or those neededlater) intomemoryis called spilling
registers.
 Data accesses are faster ifdata is inregisters insteadof
memory. Moreover, data is more useful whenina register. A MIPS
arithmetic instructioncan read tworegisters, operate on them, and
write the result. A MIPS data transfer instructiononlyreads one
operandor writesone operand, without operating onit. Thus,
registers take less time to access andhave higher throughput than
memory, makingdata in registers bothfaster to accessandsimpler
to use. Accessing registers alsouseslessenergythan accessing
memory. To achieve highest performance and conserve energy,
compilers must use registers efficiently.

 Constant or Immediate Operands: Manytimes a programwill use a constant inan operation—for example, incrementinganindex to point
to the next element of anarray. Infact, more than half ofthe MIPSarithmetic instructions have a constant as anoperandwhenrunning th e
SPEC CPU2006 benchmarks. Using onlythe instructions we have seensofar, we would have to loada constant from memoryto use one.
(The constants would have beenplacedin memorywhen the programwas loaded.) For example, to addthe constant 4 to register $s3, we
could use the code
lw $t0, AddrConstant4($s1) # $t0 = constant 4
add $s3,$s3,$t0 # $s3 = $s3 + $t0 ($t0 == 4) assumingthat $s1 + AddrConstant4 is the memoryaddressof the constant 4.
 An alternative that avoids the load instructionis to offer versions of the arithmetic instructions in whichone operand is a constant. This quick
add instructionwithone constant operand is calledaddimmediate or addi. To add 4 to register $s3, we just write addi $s3,$s3,4 # $s3 =
$s3 + 4
 Immediate instructions illustrate the thirdhardware design principle, DesignPrinciple 3: Make the common case fast.
 Registerzero: The constant zerohas another role, whichis to simplifythe instructionset byoffering useful variations. For example, the move
operationis just an add instructionwhere one operandis zero. Hence, MIPSdedicates a register $zero to be hardwired to the value zero. (As
you might expect, it is register number 0.)
 Although the MIPSregisters inthisbook are 32 bits wide, there is a 64-bit version of the MIPSinstruction set with 32 64-bit registers. To keep
them straight, theyare officiallycalledMIPS-32 and MIPS-64. Inthis chapter, we use a subset of MIPS-32.
 Since MIPSsupports negative constants, there is noneedfor subtract immediate in MIPS.
Ch.2 Hennessy 5
ASSOCIATED CONTENT
 To increase portability, Java was originallyenvisionedas relying ona software interpreter. The instruction set of thisinterpreter is calledJava
bytecodes (see Section2.15 on the CD), whichis quite different fromthe MIPS instruction set. To get performance close to the equivalent C
program, Java systems todaytypicallycompile Java bytecodes into the native instructionsets like MIPS. Because thiscompilationis normally
done muchlater thanfor Cprograms, suchJava compilers are oftencalled Just I nTime (JIT) compilers. Section2.12 shows howJITs are used
later than Ccompilers inthe start-up process, andSection 2.13 shows the performance consequences ofcompiling versus interpreting Java
programs.
 The register inthe data transfer instructions was originallyinventedto hold anindex ofanarraywith the offset used for the starting address
of an array. Thus, the base register is also calledthe index register. Today’s memoriesare muchlarger andthe software model of data
allocationis more sophisticated, sothe base addressof the arrayis normallypassed ina register since it won’t fit inthe offset, as we shall
see.

More Related Content

What's hot

ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...
ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...
ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...ijnlc
 
data compression technique
data compression techniquedata compression technique
data compression techniqueCHINMOY PAUL
 
A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...
A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...
A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...IJMERJOURNAL
 
Data Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length EncodingData Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length EncodingMANISH T I
 
Dictionary Based Compression
Dictionary Based CompressionDictionary Based Compression
Dictionary Based Compressionanithabalaprabhu
 
3 mathematical priliminaries DATA compression
3 mathematical priliminaries DATA compression3 mathematical priliminaries DATA compression
3 mathematical priliminaries DATA compressionShubham Jain
 
Chapter 2 Part2 A
Chapter 2 Part2 AChapter 2 Part2 A
Chapter 2 Part2 Aececourse
 
Chapter 5 - Data Compression
Chapter 5 - Data CompressionChapter 5 - Data Compression
Chapter 5 - Data CompressionPratik Pradhan
 
Chapter 21 c language
Chapter 21 c languageChapter 21 c language
Chapter 21 c languageHareem Aslam
 
Pauls klein 2011-lm_paper(3)
Pauls klein 2011-lm_paper(3)Pauls klein 2011-lm_paper(3)
Pauls klein 2011-lm_paper(3)Red Over
 
A new algorithm for data compression technique using vlsi
A new algorithm for data compression technique using vlsiA new algorithm for data compression technique using vlsi
A new algorithm for data compression technique using vlsiTejeswar Tej
 
Data compression techniques
Data compression techniquesData compression techniques
Data compression techniquesDeep Bhatt
 
Reflective and Refractive Variables: A Model for Effective and Maintainable A...
Reflective and Refractive Variables: A Model for Effective and Maintainable A...Reflective and Refractive Variables: A Model for Effective and Maintainable A...
Reflective and Refractive Variables: A Model for Effective and Maintainable A...Vincenzo De Florio
 
Chapter 1 computer abstractions and technology
Chapter 1 computer abstractions and technologyChapter 1 computer abstractions and technology
Chapter 1 computer abstractions and technologyBATMUNHMUNHZAYA
 

What's hot (20)

lecture on data compression
lecture on data compressionlecture on data compression
lecture on data compression
 
Data compression
Data compression Data compression
Data compression
 
ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...
ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...
ANALYZING ARCHITECTURES FOR NEURAL MACHINE TRANSLATION USING LOW COMPUTATIONA...
 
data compression technique
data compression techniquedata compression technique
data compression technique
 
A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...
A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...
A Compression & Encryption Algorithms on DNA Sequences Using R 2 P & Selectiv...
 
Data compression
Data compressionData compression
Data compression
 
Data Compression
Data CompressionData Compression
Data Compression
 
Data Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length EncodingData Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length Encoding
 
Dictionary Based Compression
Dictionary Based CompressionDictionary Based Compression
Dictionary Based Compression
 
3 mathematical priliminaries DATA compression
3 mathematical priliminaries DATA compression3 mathematical priliminaries DATA compression
3 mathematical priliminaries DATA compression
 
Chapter 2 Part2 A
Chapter 2 Part2 AChapter 2 Part2 A
Chapter 2 Part2 A
 
Chapter 5 - Data Compression
Chapter 5 - Data CompressionChapter 5 - Data Compression
Chapter 5 - Data Compression
 
Chapter 21 c language
Chapter 21 c languageChapter 21 c language
Chapter 21 c language
 
Pauls klein 2011-lm_paper(3)
Pauls klein 2011-lm_paper(3)Pauls klein 2011-lm_paper(3)
Pauls klein 2011-lm_paper(3)
 
Text compression
Text compressionText compression
Text compression
 
Data compression
Data compressionData compression
Data compression
 
A new algorithm for data compression technique using vlsi
A new algorithm for data compression technique using vlsiA new algorithm for data compression technique using vlsi
A new algorithm for data compression technique using vlsi
 
Data compression techniques
Data compression techniquesData compression techniques
Data compression techniques
 
Reflective and Refractive Variables: A Model for Effective and Maintainable A...
Reflective and Refractive Variables: A Model for Effective and Maintainable A...Reflective and Refractive Variables: A Model for Effective and Maintainable A...
Reflective and Refractive Variables: A Model for Effective and Maintainable A...
 
Chapter 1 computer abstractions and technology
Chapter 1 computer abstractions and technologyChapter 1 computer abstractions and technology
Chapter 1 computer abstractions and technology
 

Similar to Hennch2nts 160526114335-160526184116-160527121537

Chapter 02 instructions language of the computer
Chapter 02   instructions language of the computerChapter 02   instructions language of the computer
Chapter 02 instructions language of the computerBảo Hoang
 
UNIT 2_ESD.pdf
UNIT 2_ESD.pdfUNIT 2_ESD.pdf
UNIT 2_ESD.pdfSaralaT3
 
number system understand
number system  understandnumber system  understand
number system understandrickypatel151
 
Risc processors all syllabus5
Risc processors all syllabus5Risc processors all syllabus5
Risc processors all syllabus5faiyaz_vt
 
Computer architecture is made up of two main components the Instruct.docx
Computer architecture is made up of two main components the Instruct.docxComputer architecture is made up of two main components the Instruct.docx
Computer architecture is made up of two main components the Instruct.docxbrownliecarmella
 
mano-m-m-computer-system-architecture.pdf
mano-m-m-computer-system-architecture.pdfmano-m-m-computer-system-architecture.pdf
mano-m-m-computer-system-architecture.pdfTayachewSisay
 
Computer System Architecture-Morris Mano third edition ( PDFDrive ).pdf
Computer System Architecture-Morris Mano third edition ( PDFDrive ).pdfComputer System Architecture-Morris Mano third edition ( PDFDrive ).pdf
Computer System Architecture-Morris Mano third edition ( PDFDrive ).pdfedwinmoyo3
 
computerprogramminglanguages-201216152310.pptx
computerprogramminglanguages-201216152310.pptxcomputerprogramminglanguages-201216152310.pptx
computerprogramminglanguages-201216152310.pptxSubramanian Mani
 
ASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptxASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptxEdFeranil
 
Ass#1 ramirez.cv (cs3112 os)
Ass#1 ramirez.cv (cs3112 os)Ass#1 ramirez.cv (cs3112 os)
Ass#1 ramirez.cv (cs3112 os)charize
 
Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)myanddy
 
Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)myanddy
 
Assignment#1 Mapacpac, F M P (Cs3112 Os)
Assignment#1 Mapacpac, F M P  (Cs3112 Os)Assignment#1 Mapacpac, F M P  (Cs3112 Os)
Assignment#1 Mapacpac, F M P (Cs3112 Os)dyandmy
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formatsMazin Alwaaly
 
Lesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsLesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsPVS-Studio
 

Similar to Hennch2nts 160526114335-160526184116-160527121537 (20)

Chapter 02 instructions language of the computer
Chapter 02   instructions language of the computerChapter 02   instructions language of the computer
Chapter 02 instructions language of the computer
 
UNIT 2_ESD.pdf
UNIT 2_ESD.pdfUNIT 2_ESD.pdf
UNIT 2_ESD.pdf
 
number system understand
number system  understandnumber system  understand
number system understand
 
Mips architecture
Mips architectureMips architecture
Mips architecture
 
Risc processors all syllabus5
Risc processors all syllabus5Risc processors all syllabus5
Risc processors all syllabus5
 
Computer architecture is made up of two main components the Instruct.docx
Computer architecture is made up of two main components the Instruct.docxComputer architecture is made up of two main components the Instruct.docx
Computer architecture is made up of two main components the Instruct.docx
 
mano-m-m-computer-system-architecture.pdf
mano-m-m-computer-system-architecture.pdfmano-m-m-computer-system-architecture.pdf
mano-m-m-computer-system-architecture.pdf
 
Computer System Architecture-Morris Mano third edition ( PDFDrive ).pdf
Computer System Architecture-Morris Mano third edition ( PDFDrive ).pdfComputer System Architecture-Morris Mano third edition ( PDFDrive ).pdf
Computer System Architecture-Morris Mano third edition ( PDFDrive ).pdf
 
computerprogramminglanguages-201216152310.pptx
computerprogramminglanguages-201216152310.pptxcomputerprogramminglanguages-201216152310.pptx
computerprogramminglanguages-201216152310.pptx
 
ASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptxASSEMBLY LANGUAGE.pptx
ASSEMBLY LANGUAGE.pptx
 
Ass#1 ramirez.cv (cs3112 os)
Ass#1 ramirez.cv (cs3112 os)Ass#1 ramirez.cv (cs3112 os)
Ass#1 ramirez.cv (cs3112 os)
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)
 
Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)Assignment#1 lograbo, s.f. (cs3112-os)
Assignment#1 lograbo, s.f. (cs3112-os)
 
Assignment#1 Mapacpac, F M P (Cs3112 Os)
Assignment#1 Mapacpac, F M P  (Cs3112 Os)Assignment#1 Mapacpac, F M P  (Cs3112 Os)
Assignment#1 Mapacpac, F M P (Cs3112 Os)
 
Computer programming languages
Computer programming languagesComputer programming languages
Computer programming languages
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
 
Lesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsLesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programs
 
Parallel computation
Parallel computationParallel computation
Parallel computation
 
6272 cnote
6272 cnote6272 cnote
6272 cnote
 

More from marangburu42

Hennchthree 161102111515
Hennchthree 161102111515Hennchthree 161102111515
Hennchthree 161102111515marangburu42
 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuitsmarangburu42
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuitsmarangburu42
 
Hennchthree 160912095304
Hennchthree 160912095304Hennchthree 160912095304
Hennchthree 160912095304marangburu42
 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuitsmarangburu42
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuitsmarangburu42
 
Karnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuitsKarnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuitsmarangburu42
 
Aac boolean formulae
Aac   boolean formulaeAac   boolean formulae
Aac boolean formulaemarangburu42
 
Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858marangburu42
 
File system interfacefinal
File system interfacefinalFile system interfacefinal
File system interfacefinalmarangburu42
 
File systemimplementationfinal
File systemimplementationfinalFile systemimplementationfinal
File systemimplementationfinalmarangburu42
 
Mass storage structurefinal
Mass storage structurefinalMass storage structurefinal
Mass storage structurefinalmarangburu42
 
All aboutcircuits karnaugh maps
All aboutcircuits karnaugh mapsAll aboutcircuits karnaugh maps
All aboutcircuits karnaugh mapsmarangburu42
 
Virtual memoryfinal
Virtual memoryfinalVirtual memoryfinal
Virtual memoryfinalmarangburu42
 
Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029marangburu42
 

More from marangburu42 (20)

Hol
HolHol
Hol
 
Write miss
Write missWrite miss
Write miss
 
Hennchthree 161102111515
Hennchthree 161102111515Hennchthree 161102111515
Hennchthree 161102111515
 
Hennchthree
HennchthreeHennchthree
Hennchthree
 
Hennchthree
HennchthreeHennchthree
Hennchthree
 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuits
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
 
Hennchthree 160912095304
Hennchthree 160912095304Hennchthree 160912095304
Hennchthree 160912095304
 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuits
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
 
Karnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuitsKarnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuits
 
Aac boolean formulae
Aac   boolean formulaeAac   boolean formulae
Aac boolean formulae
 
Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858
 
Io systems final
Io systems finalIo systems final
Io systems final
 
File system interfacefinal
File system interfacefinalFile system interfacefinal
File system interfacefinal
 
File systemimplementationfinal
File systemimplementationfinalFile systemimplementationfinal
File systemimplementationfinal
 
Mass storage structurefinal
Mass storage structurefinalMass storage structurefinal
Mass storage structurefinal
 
All aboutcircuits karnaugh maps
All aboutcircuits karnaugh mapsAll aboutcircuits karnaugh maps
All aboutcircuits karnaugh maps
 
Virtual memoryfinal
Virtual memoryfinalVirtual memoryfinal
Virtual memoryfinal
 
Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029
 

Recently uploaded

Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...
Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...
Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...akbard9823
 
Top Rated Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...tanu pandey
 
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCyLet Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCystephieert
 
Pesticide Calculation Review 2013 post.pptx
Pesticide Calculation Review 2013 post.pptxPesticide Calculation Review 2013 post.pptx
Pesticide Calculation Review 2013 post.pptxalfordglenn
 
VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...
VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...
VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...Suhani Kapoor
 
VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...
VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...
VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...Suhani Kapoor
 
The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1davew9
 
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Roomdivyansh0kumar0
 
Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)Mohamed Miyir
 
Booking open Available Pune Call Girls Sanaswadi 6297143586 Call Hot Indian ...
Booking open Available Pune Call Girls Sanaswadi  6297143586 Call Hot Indian ...Booking open Available Pune Call Girls Sanaswadi  6297143586 Call Hot Indian ...
Booking open Available Pune Call Girls Sanaswadi 6297143586 Call Hot Indian ...Call Girls in Nagpur High Profile
 
VIP Call Girls In Singar Nagar ( Lucknow ) 🔝 8923113531 🔝 Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment Avai...VIP Call Girls In Singar Nagar ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow ) 🔝 8923113531 🔝 Cash Payment Avai...anilsa9823
 
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...
VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...
VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...Suhani Kapoor
 
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130
VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130
VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130Suhani Kapoor
 
Top Rated Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...
Top Rated  Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...Top Rated  Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...
Top Rated Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...Call Girls in Nagpur High Profile
 
Call Girls Dubai &ubble O525547819 Call Girls In Dubai Blastcum
Call Girls Dubai &ubble O525547819 Call Girls In Dubai BlastcumCall Girls Dubai &ubble O525547819 Call Girls In Dubai Blastcum
Call Girls Dubai &ubble O525547819 Call Girls In Dubai Blastcumkojalkojal131
 

Recently uploaded (20)

Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...
Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...
Vikas Nagar #Dating Call Girls Lucknow Get 50% Off On VIP Escorts Service 🍇 8...
 
Top Rated Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Baner ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
 
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCyLet Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
 
Pesticide Calculation Review 2013 post.pptx
Pesticide Calculation Review 2013 post.pptxPesticide Calculation Review 2013 post.pptx
Pesticide Calculation Review 2013 post.pptx
 
VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...
VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...
VIP Russian Call Girls Gorakhpur Chhaya 8250192130 Independent Escort Service...
 
VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...
VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...
VIP Russian Call Girls in Cuttack Deepika 8250192130 Independent Escort Servi...
 
The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1
 
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Room
 
Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)
 
Booking open Available Pune Call Girls Sanaswadi 6297143586 Call Hot Indian ...
Booking open Available Pune Call Girls Sanaswadi  6297143586 Call Hot Indian ...Booking open Available Pune Call Girls Sanaswadi  6297143586 Call Hot Indian ...
Booking open Available Pune Call Girls Sanaswadi 6297143586 Call Hot Indian ...
 
Call Girls In Tilak Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In  Tilak Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In  Tilak Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Tilak Nagar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
VIP Call Girls In Singar Nagar ( Lucknow ) 🔝 8923113531 🔝 Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment Avai...VIP Call Girls In Singar Nagar ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow ) 🔝 8923113531 🔝 Cash Payment Avai...
 
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
 
VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...
VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...
VIP Russian Call Girls in Noida Deepika 8250192130 Independent Escort Service...
 
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130
VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130
VIP Call Girls Service Shamshabad Hyderabad Call +91-8250192130
 
Top Rated Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...
Top Rated  Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...Top Rated  Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...
Top Rated Pune Call Girls Yashwant Nagar ⟟ 6297143586 ⟟ Call Me For Genuine ...
 
Call Girls Dubai &ubble O525547819 Call Girls In Dubai Blastcum
Call Girls Dubai &ubble O525547819 Call Girls In Dubai BlastcumCall Girls Dubai &ubble O525547819 Call Girls In Dubai Blastcum
Call Girls Dubai &ubble O525547819 Call Girls In Dubai Blastcum
 

Hennch2nts 160526114335-160526184116-160527121537

  • 1. Ch.2 Hennessy 1 Ch.2 (Henn): Instructions – Language of the Computer Supplement(s): HennessyChapter 2 Supplement, Hennessy Chapter 2 – Formulae, Examples and Exercises Objectives:  Introduction  Operations and operands of the Computer Hardware,  Signed and Unsigned Numbers  Representing Instructions in the Computer  Logical Operations, Instructions for Making Decisions  Supporting Procedures in Computer Hardware  MIPS Addressing for 32-Bit Immediates and Addresses  Parallelism and Instructions: Synchronization  Translating and Starting a Program  A C Sort Example to Put It All Together  Arrays versus Pointers  Real Stuff: ARM Instructions  Real Stuff: x86 Instructions  Fallacies and Pitfalls  Concluding Remarks  To commanda computer’s hardware, you must speakits language. The words of a computer’s language are calledinstructions, andits vocabularyis calledan instructionset. In this chapter, you will see the instruction set of a real computer, both in the form written bypeople and inthe form read bythe computer. We introduce instructions ina top-downfashion. Startingfrom a notationthat looks like a restricted programminglanguage, we refine it step-by-stepuntil you see the real language ofa real computer. Chapter 3 continues our downward descent, unveilingthe hardware for arithmetic andthe representation offloating-point numbers.  You might thinkthat the languagesof computers wouldbe as diverse as those ofpeople, but inrealitycomputer languages are quite similar, more like regional dialects thanlike independent languages. Hence, once you learnone, it is easyto pickupothers. This similarityoccurs because all computers are constructedfromhardware technologies based onsimilar underlying principles andbecause there are a few basic operations that allcomputers must provide. Moreover, computer designers have a common goal:to finda language that makesit easyto buildthe hardware andthe compiler while maximizing performance andminimizing cost andpower.  It is easyto see byformal-logicalmethods that there exist certain[instruction sets]that are in abstract adequate to control andcause the executionof anysequence of operations . . . . The reallydecisive considerations from the present point of view, inselecting an[instruction set], are more ofa practicalnature:simplicityof the equipment demandedbythe [instruction set], and the clarityof its a pplicationto the actuallyimportant problems together withthe speedof its handling of those problems.— Burks,Goldstine,andvon Neumann,1947  The “simplicityof the equipment” is as valuable a considerationfor today’s computers as it was for those ofthe 1950s. The goalof this chapter is to teach aninstructionset that follows thisadvice, showing both howit is represented in hardware andthe relationshipbetween high-level programming languages andthis more primitive one. Our examplesare inthe Cprogramming language; Section2.15 on the CD shows how these wouldchange for an object-oriented language like Java.  By learninghowto represent instructions, you will alsodiscover the secret ofcomputing:the stored-program concept (The ideathat instructions and data of manytypes can be storedin memoryas numbers, leading to the storedprogram skills bywritingprograms inthe language of the computer andrunning them onthe simulator that comeswith this book. You will alsosee the impact of programming languages andcompiler optimizationonperformance. We conclude with a lookat the historical evolutionof instructionsets andanoverview of other computer dialects.  The chosen instructionset comes fromMIPS Technologies, whichis anelegant example of the instructionsets designedsince the 1980s. Later, we will take a quick lookat two other popular instructionsets. ARMis quite similar to MIPS. The other example is the popular Intel x86. Operations of the Computer Hardware  The MIPS assemblylanguage notation add a, b, c instructs a computer to add the twovariables b and c andto put their sumin a. This notationis rigidinthat each MIPS arithmetic instructionperforms onlyone operationandmust always have exactlythree variables. For example, suppose we want to place the sumof four variables b, c, d, and e intovariable a. The followingsequence ofinstructions adds the four variables (Thus, it takesthree instructions to sumthe four variables):
  • 2. Ch.2 Hennessy 2 The words to the right ofthe sharpsymbol (#) on eachline above a re comments for the humanreader, andthe computer ignoresthem. Note that unlike other programming languages, eachline ofthis language can contain at most one instruction. Another difference fromCis that comments always terminate at the endof a line.  The natural number of operands for anoperationlike additionis three:the two numbers being addedtogether anda place to p ut the sum. Requiring everyinstructionto have exactlythree operands, conforms to the philosophyof keeping the hardware simple: hardware for a variable number of operands is more complicatedthanhardware for a fixednumber. This situationillustrates the first of four underlying principles of hardware design: -> DesignPrinciple 1: Simplicity favors regularity. We can nowshow, in the twoexamples that follow, the relationshipof programs writtenin higher-level programming languages to programs inthismore primitive notation.  Compiling Two C Assignment Statements into MIPS: This is done bythe compiler, andthe below are the CandMIPS codes:
  • 3. Ch.2 Hennessy 3  Compiling a Complex C Assignment into MIPS: f = (g + h) – (i + j); OPERANDS OF THE COMPUTER HARDWARE  Unlike programs inhigh-level languages, the operands ofarithmetic instructions are restricted;theymust be from a limitednumber of speciallocations built directlyinhardware calledregisters. Registers are primitives usedin hardware design. The size of a register in the MIPS architecture is 32 bits;groups of32 bits occur sofrequentlythat theyare giventhe name word in the MIPSarchitecture. A word is the natural unit of access in a computer, usuallya groupof 32 bits;corresponds to the size ofa register in the MIPS architecture.  One major difference betweenthe variablesof a programming language and registers is the limited number of registers, typically32 on current computers, like MIPS. In thissection, we have addedthe restrictionthat the three operands ofMIPS arithmetic instructions must each be chosen from one of the 32 32-bit registers.  The reason for the limit of32 registers maybe foundinthe secondof our four underlying designprinciples ofhardware technology: Design Principle 2 – Smalleris faster. A very large number of registers mayincrease the clockcycle time simplybecause it takes electronic signals longer whentheymust travel farther. In this case, the designer must balance the craving ofprograms for more registers with the designer’s desire to keep the clock cycle fast. Another reason for not usingmore than32 is the number ofbits it wouldtake inthe instruction format, as Section2.5 demonstrates.  Chapter 4 shows the central role that registers playinhardware construction;as we shall see inthischapter, effective use ofregisters is critical to programperformance. Although we couldsimplywrite instructions usingnumbers for registers, from 0 to 31, the MIPS convention is to use two-character names following a dollar signto represent a register. Section2.8 willexplainthe reasons behindthese names. For now, we will use $s0, $s1, . . . for registers that correspondto variablesinCandJava programs and$t0, $t1, . . . for temp oraryregisters neededto compile the programintoMIPS instructions.  Compiling a CAssignment Using Registers: It is the compiler’s job to associate programvariableswith registers. Take, for instance, the assignment statement fromour earlier example: f = (g + h) – (i + j);The variables f, g, h, i, andj are assignedto the registers $s0, $s1, $s2, $s3, and $s4, respectively. The compiledMIPS program is verysimilar to the prior example, except we replace the variableswiththe register names mentioned above plus two temporaryregisters, $t0 and$t1, which correspondto the temporaryvariables above.  Memory Operands: Programming languages have simple variables that containsingle data elements, as inthese examples, but theyalso have more complex data structures—arrays andstructures. These complex data structures cancontainmanymore data elements than there are registers in a computer. The processor can keeponlya smallamount of data inregisters, but computer memorycontains billions of data elements. Hence, data structures (arrays andstructures) are kept in memory.  As explained above, arithmetic operations occur onlyon registers inMIPS instructions;thus, MIPS must include instructions that transfer data betweenmemoryandregisters. Such instructions are calleddata transfer instructions. To accessa word in memory, the instruction must supplythe memoryaddress. Memoryis just a large, single-dimensionalarray, with the addressacting as the index to that array, startingat 0. (MIPS usesbyte-addressing, not word- addressing). The data transfer instruction that copiesdata from memoryto a register is traditionallycalledload. The format of the loadinstruction is the name of the operation followedbythe register to be loaded, thena constant and register usedto access memory. The sumof the constant portionof the instructionand the contents ofthe secondregister forms the memoryaddress. The actual MIPSname for this instruction is lw, standingfor load word. E.g.: lw $t0,8($s3) # Temporary reg $t0 gets A[8]  In addition to associatingvariableswithregisters, the compiler allocates data structures like arrays andstructures to
  • 4. Ch.2 Hennessy 4 locations in memory. The compiler canthenplace the proper starting address into the data transfer instructions.  The address ofa wordmatches the address of one of the 4 bytes withinthe word, andaddresses ofsequential words differ by4.InMIPS, words must start at addresses that are multiples of 4. This requirement is called analignment restriction(alignment restriction is a requirement that data be alignedinmemoryon natural boundaries), andmanyarchitectures have it. Chapter 4 suggests whyalignment leads to faster data transfers.)  Computers divide intothose that use the addressof the leftmost or “big end” byte as the word addressversus those that use the rightmost or “little end” byte. MIPS is inthe big-endian camp. (Appendix B, shows the two options to number bytes in a word.) Byte addressing also affects the arrayindex. To get the proper byte address inthe code above, the offset to be added to the base register $s3 must be 4 × 8, or 32, so that the load addresswill select A[8] andnot A[8/4]. (See the relatedpitfall onpage 175 of Section 2.18.)  The instruction complementaryto load is traditionallycalledstore; it copiesdata froma register to memory. The format of a store is similar to that of a load:the name ofthe operation, followed bythe register to be stored, thenoffset to select the arrayelement, and finallythe base register. Once again, the MIPS addressis specified inpart bya constant and inpart bythe contents of a register. The actual MIPS name is sw, standing for store word.  Manyprograms have more variablesthan computers have registers. Consequently, the compiler tries to keepthe most frequentlyusedvariablesinregisters andplaces the rest in memory, using loads andstores to move variablesbetween registers andmemory. The process of putting less commonlyused variables (or those neededlater) intomemoryis called spilling registers.  Data accesses are faster ifdata is inregisters insteadof memory. Moreover, data is more useful whenina register. A MIPS arithmetic instructioncan read tworegisters, operate on them, and write the result. A MIPS data transfer instructiononlyreads one operandor writesone operand, without operating onit. Thus, registers take less time to access andhave higher throughput than memory, makingdata in registers bothfaster to accessandsimpler to use. Accessing registers alsouseslessenergythan accessing memory. To achieve highest performance and conserve energy, compilers must use registers efficiently.   Constant or Immediate Operands: Manytimes a programwill use a constant inan operation—for example, incrementinganindex to point to the next element of anarray. Infact, more than half ofthe MIPSarithmetic instructions have a constant as anoperandwhenrunning th e SPEC CPU2006 benchmarks. Using onlythe instructions we have seensofar, we would have to loada constant from memoryto use one. (The constants would have beenplacedin memorywhen the programwas loaded.) For example, to addthe constant 4 to register $s3, we could use the code lw $t0, AddrConstant4($s1) # $t0 = constant 4 add $s3,$s3,$t0 # $s3 = $s3 + $t0 ($t0 == 4) assumingthat $s1 + AddrConstant4 is the memoryaddressof the constant 4.  An alternative that avoids the load instructionis to offer versions of the arithmetic instructions in whichone operand is a constant. This quick add instructionwithone constant operand is calledaddimmediate or addi. To add 4 to register $s3, we just write addi $s3,$s3,4 # $s3 = $s3 + 4  Immediate instructions illustrate the thirdhardware design principle, DesignPrinciple 3: Make the common case fast.  Registerzero: The constant zerohas another role, whichis to simplifythe instructionset byoffering useful variations. For example, the move operationis just an add instructionwhere one operandis zero. Hence, MIPSdedicates a register $zero to be hardwired to the value zero. (As you might expect, it is register number 0.)  Although the MIPSregisters inthisbook are 32 bits wide, there is a 64-bit version of the MIPSinstruction set with 32 64-bit registers. To keep them straight, theyare officiallycalledMIPS-32 and MIPS-64. Inthis chapter, we use a subset of MIPS-32.  Since MIPSsupports negative constants, there is noneedfor subtract immediate in MIPS.
  • 5. Ch.2 Hennessy 5 ASSOCIATED CONTENT  To increase portability, Java was originallyenvisionedas relying ona software interpreter. The instruction set of thisinterpreter is calledJava bytecodes (see Section2.15 on the CD), whichis quite different fromthe MIPS instruction set. To get performance close to the equivalent C program, Java systems todaytypicallycompile Java bytecodes into the native instructionsets like MIPS. Because thiscompilationis normally done muchlater thanfor Cprograms, suchJava compilers are oftencalled Just I nTime (JIT) compilers. Section2.12 shows howJITs are used later than Ccompilers inthe start-up process, andSection 2.13 shows the performance consequences ofcompiling versus interpreting Java programs.  The register inthe data transfer instructions was originallyinventedto hold anindex ofanarraywith the offset used for the starting address of an array. Thus, the base register is also calledthe index register. Today’s memoriesare muchlarger andthe software model of data allocationis more sophisticated, sothe base addressof the arrayis normallypassed ina register since it won’t fit inthe offset, as we shall see.