Dept. Electronics Engineering, DEE 1050 Computer .

2y ago
16 Views
2 Downloads
352.15 KB
41 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Bennett Almond
Transcription

Dept. Electronics Engineering, National Chiao Tung UniversityDEE 1050 Computer OrganizationLecture 3 Instructions: Language of theComputerDr. Tian-Sheuan Changtschang@twins.ee.nctu.edu.twDept. Electronics EngineeringNational Chiao-Tung University

OutlineInstitute of Electronics, National Chiao Tung University Part I. Introduction Part II. Case study with MIPS instructions Part III. Tool chainDEE 1050 Lecture 2: Instructions1

OutlineInstitute of Electronics, National Chiao Tung University OperationsOperandsControl flowMIPS addressing modeDEE 1050 Lecture 2: Instructions2

IntroductionInstitute of Electronics, National Chiao Tung University Computer language– Words: instructions– Vocabulary: instruction set– Similar for all, like regional dialect ? Design goal of computer language– To find a language that makes it easy to build thehardware and the compiler while maximizingperformance and minimizing cost Reading list– COD3E: ch. 2DEE 1050 Lecture 2: Instructions3

Instructions: Difference with HLL Language of the MachineInstitute of Electronics, National Chiao Tung University– More primitive than higher level languagese.g., no sophisticated control flow– Very restrictivee.g., MIPS Arithmetic Instructions We’ll be working with the MIPS instruction set architecture– similar to other architectures developed since the 1980's– Almost 100 million MIPS processors manufactured in 2002– used by NEC, Nintendo, Cisco, Silicon Graphics, Sony, 14001300120011001000900800OtherSPARCHitachi SHPowerPCMotorola 68KMIPSIA-32ARM700600500400300200100DEE 1050 Lecture 2: Instructions019981999200020012002

How to Design the Instructions? OperationsInstitute of Electronics, National Chiao Tung University– Arithmetic– Logical– Datapath Operands– Datapath Control flow– Decision control– Procedures calls– ControlDEE 1050 Lecture 2: Instructionsint add5 (int a){int tmp a 5;return tmp;}void main (){int a 7;int c;if (a 7)c add5(a);}5

Operations: MIPS arithmeticInstitute of Electronics, National Chiao Tung University Each arithmetic instructions performs only one operationand have 3 operands Operand order is fixed (destination first)add a, b, c# a b ccommentsOne operationExact threeoperands“The natural number of operands for an operation likeaddition is three requiring every instruction to haveexactly three operands, no more and no less, conformsto the philosophy of keeping the hardware simple”DEE 1050 Lecture 2: Instructions6

MIPS arithmeticInstitute of Electronics, National Chiao Tung University Design Principle 1: simplicity favors regularity. Of course this complicates some things.C code:a b c d;MIPS code:add a, b, cadd a, a, dQ. Will variable no. of operands be faster?how about four or more operands in one instructionsDEE 1050 Lecture 2: Instructions

MIPS Logical Operations (Section 2.5) Why logical operationsInstitute of Electronics, National Chiao Tung University– Useful to operate on fields of bit or individual bits Q. Can some multiply by 2i ? Divide by 2i ? Invert?Q. Why “NOT” maps to “nor”?– A NOR 0 NOT (A OR 0) NOT (A) Q. Why not “nori” (nor immediate)?– Constant are rare for for NORoperationsc operatorsmipsshift leftshift rightbit-by-bit andbit-by-bit orbit-by-bit not & sllsrland, andior, orinorDEE 1050 Lecture 2: Instructions8

Institute of Electronics, National Chiao Tung University Intended to be blank9DEE 1050 Lecture 2: Instructions

Operands of the Computer Hardware (Section2.3)Institute of Electronics, National Chiao Tung University Difference with HLL like C– Limited number, why ?– Operands are restricted to hardware-built registers– Registers are primitive and visible to programmer MIPS operands– Operands must be registers, only 32 registersprovided– Each register contains 32 bits– Why 32? Design Principle 2: smaller is faster.DEE 1050 Lecture 2: Instructions10

Operand TypeInstitute of Electronics, National Chiao Tung University 3 Types– Register operands All arithmetic operations are in the register operands– Memory operands Array or structure Only load/store can access memory– Constant or immediate operands Small value will be in the instruction Large value will be stored separatelyDEE 1050 Lecture 2: Instructions11

Register Operand ExampleInstitute of Electronics, National Chiao Tung University Register representation– **, in MIPS s0, s1. Registers corresponding to the variables of C programs t0, t1 temporary registers need to compile the program– (this might be different in other assembly language)Translate the following C program into MIPSf (g h) – ( i j);Assume f, g, h, i, j uses s0, . s4Add t0, s1, s2Add t1, s3, s4Sub s0, t0 - t1DEE 1050 Lecture 2: Instructions12

HW/SW IF: How Compiler Use RegistersInstitute of Electronics, National Chiao Tung University Problem: more variables than available registers Solution– Keep the most frequently used variables in registers– Place the rest in memory (called spilling registers), useload and store to move variables between registers andmemory– Why? Register is faster but its size is small Compiler must use register efficientlyDEE 1050 Lecture 2: Instructions13

Memory Operands: Array and StructuresInstitute of Electronics, National Chiao Tung University Data are stored in memory “data transfer instructions”– Transfer data between memory and registers– Load lw: move data from memory to a register– Store st: move data from a register to memoryDEE 1050 Lecture 2: Instructions14

Array ExampleInstitute of Electronics, National Chiao Tung University Load format– lw register names, const offset(base register)g h a[8]offsetassume g, h s1, s2base address s3lw t0, 8( s3) #lw: load wordadd s1, 2, t0BaseaddressIf a[12] h a[8]Add one more instructionssw 12[ s3], s1DEE 1050 Lecture 2: Instructions15

Memory and Data SizesInstitute of Electronics, National Chiao Tung UniversitySo far, we’ve only talked about uniform data sizes. Actualdata come in many different sizes: Single bits: (“boolean” values, true or false) Bytes (8 bits): Characters (ASCII), very small integers Halfwords (16 bits): Characters (Unicode), short integers Words (32 bits): Long integers, floating-point (FP)numbers Double-words (64 bits): Very long integers, doubleprecision FP Quad-words (128 bits): Quad-precision floating-pointnumbersDEE 1050 Lecture 2: Instructions16

Different Data SizesInstitute of Electronics, National Chiao Tung UniversityHow do we handle different data sizes? Pick one size to be the unit stored in a single address Store larger datum in a set of contiguous memorylocations Store smaller datum in one location; use shift & mask opsToday, almost all machines (including MIPS) are “byteaddressable” – each addressable location in memoryholds 8 bits.DEE 1050 Lecture 2: Instructions17

Memory Organization – Byte AddressingInstitute of Electronics, National Chiao Tung University Viewed as a large, single-dimension array, withan address. A memory address is an index into the array "Byte addressing" means that the index pointsto a byte of memory.0123456.DEE 1050 Lecture 2: Instructions8 bits of data8 bits of data8 bits of data8 bits of data8 bits of data8 bits of data8 bits of data

Memory OrganizationInstitute of Electronics, National Chiao Tung University Bytes are nice, but most data items use larger "words" For MIPS, a word is 32 bits or 4 bytes.04812.32 bits of data32 bits of data32 bits of dataRegisters hold 32 bits of data32 bits of data 232 bytes with byte addresses from 0 to 232-1 230 words with byte addresses 0, 4, 8, . 232-4 Words are alignedi.e., what are the least 2 significant bits of a wordaddress? To select the byte Alignment restriction in MIPS– Words must start at addresses that are multiples of 4DEE 1050 Lecture 2: Instructions

Array Example for Real MIPS Memory AddressInstitute of Electronics, National Chiao Tung University Code for byte addressable memoryOriginala[12] h a[8]Updateda[12] h a[8]assume g, h s1, s2base address s3assume g, h s1, s2base address s3, word datalw t0, 8( s3)add s1, 2, t0sw 12( s3), s1lw t0, 32( s3)add s1, 2, t0sw 48( s3), s1Remember arithmetic operands are registers, not memory!Can’t write: add 48( s3), s2, 32( s3)DEE 1050 Lecture 2: Instructions20

Byte-Order (“Endianness”)Institute of Electronics, National Chiao Tung UniversityFor a multi-byte datum, which part goes in which byte? If 1 contains 1,000,000 (F4240H) and we store it intoaddress 80: On a “big-endian” machine, the “big” end goes intoaddress 80 7900800F814282408384 On a “little-endian” machine, it’s the other way around DEE 1050 Lecture 2: Instructions7940420F008081828384 21

Big-Endian vs. Little-EndianInstitute of Electronics, National Chiao Tung University Big-endian machines: MIPS, Sparc, 68000 Little-endian machines: most Intel processors,Alpha, VAX– No real reason one is better than the other – Compatibility problems transferring multi-byte databetween big-endian and little-endian machines –CAREFUL! Bi-endian machines: ARM, User’s choiceDEE 1050 Lecture 2: Instructions22

Registers Operands vs. Memory OperandsInstitute of Electronics, National Chiao Tung University Arithmetic instructions operands must beregisters,– only 32 registers provided– Compiler associates variables with registers What about programs with lots of variables ? Likearray and structures– Data structures are kept in memory– Data transfer instructions Load: lw copy data from memory to registers Store: sw copy data from registers to memory How: instruction supplies the memory addressDEE 1050 Lecture 2: Instructions

Constant or Immediate Operands Institute of Electronics, National Chiao Tung University Small constants are used quite frequently ( 50% of operands inSPEC2000 benchmark)e.g.,A A 5;B B 1;C C - 18;Solutions? Why not?– put 'constants' in memory and load them.– create hard-wired registers (like zero) for constants like one. MIPS Instructions:addi s1, s1, 5slti s2, s1, 10andi s1, s1, 6ori s1, s1, 4 Design Principle 3: Make the common case fast.Q: why only “addi” and no “subi”– Negative constantsDEE 1050 Lecture 2: Instructions

How about larger constants?Institute of Electronics, National Chiao Tung University We'd like to be able to load a 32 bit constant into a register Must use two instructions, new "load upper immediate"instructionlui t0, 1010101010101010filled with zeros10101010101010100000000000000000 Then must get the lower order bits right, i.e.,ori t0, t0, 010101010101010DEE 1050 Lecture 2: Instructions

So farMIPS operandsInstitute of Electronics, National Chiao Tung UniversityName32 registers230ExampleComments s0- s7, t0- t9,Fast locations for data. In MIPS, data must be in registers to perform zero, a0- a3, v0- arithmetic. MIPS register zero always equals 0. gp (28) is the global v1, gp, fp, sp, ra pointer, sp(29) is the stack pointer, fp (30) is the frame pointer, and ra(31) is the return address.Memory [0],Accessed only by data transfer instructions. MIPS uses byte addresses, somemory words Memory [4], ,sequential words differ by 4. Memory holds data structures, such as arrays,Memory[42949672920 and spilled register, such as those saved on procedure calls.MIPS assembly languageCategoryArithmeticData transferConditional branchUnconditional jumpInstructionaddsubtractload wordstore wordbranch on equalbranch on notequalset on less thanExampleadd s1, s2, s3sub s1, s2, s3lw s1,100 ( s2)sw s1,100 ( s2)beq s1, s2, Lbne s1, s2, LMeaning s1 s2 s3 s1 s2 - s3&s1 Memory [ s2 100]Memory [ s2 100] s1if ( s1 s2) go to Lif ( s1 ! s2) go to LCommentsThree operands; data in registersThree operands; data in registersData from memory to registerData from register to memoryEqual test and branchNot equal test and branchslt s1, s2, s3Compare less than: for beq, bnejumpjump registerjump and linkjjrjalif ( s2 s3) s1 1; else s1 0go to 10000go to ra ra PC 4; go to 1000DEE 1050 Lecture 2: Instructions2500 ra2500jump to target addressFor switch, procedure returnFor procedure call26

INFO: MIPS RegistersInstitute of Electronics, National Chiao Tung University 32 regs with R0 0 Reserved registers : R1, R26, R27. Special usage:––––R28:R29:R30:R31:DEE 1050 Lecture 2: Instructionspointer to global areastack pointerframe pointerreturn address27

INFO: Standard Register ConventionsInstitute of Electronics, National Chiao Tung University The 32 integer registers in the MIPS are “generalpurpose” – any can be used as an operand orresult of an arithmetic op But making different pieces of software worktogether is easier if certain conventions arefollowed concerning which registers are to beused for what purposes. These conventions are usually suggested by thevendor and supported by the compilersDEE 1050 Lecture 2: Instructions28

INFO: MIPS Registers and Usage ConventionInstitute of Electronics, National Chiao Tung UniversityName Register number0 zero2-3 v0- v14-7 a0- a38-15 t0- t716-23 s0- s724-25 t8- t928 gp29 sp30 fp31 raUsagethe constant value 0values for results and expression evaluationargumentstemporariessavedmore temporariesglobal pointerstack pointerframe pointerreturn addressRegister 1 ( at) reserved for assembler, 26-27 for operating systemDEE 1050 Lecture 2: Instructions29

INFO: MIPS Registers and Usage ConventionInstitute of Electronics, National Chiao Tung UniversityDEE 1050 Lecture 2: InstructionsRegister 171819202122232425262728293031UsageConstant 0Reserved for assemblerExpression evaluation and results of a functionExpression evaluation and results of a functionArgument 1Argument 2Argument 3Argument 4Temporary (not preserved aross call)Temporary (not preserved aross call)Temporary (not preserved aross call)Temporary (not preserved aross call)Temporary (not preserved aross call)Temporary (not preserved aross call)Temporary (not preserved aross call)Temporary (not preserved aross call)Saved temporary (preserved across call)Saved temporary (preserved across call)Saved temporary (preserved across call)Saved temporary (preserved across call)Saved temporary (preserved across call)Saved temporary (preserved across call)Saved temporary (preserved across call)Saved temporary (preserved across call)Temporary (not preserved aross call)Temporary (not preserved aross call)Reserved for OS kernelReserved for OS kernelPointer to global areaStack pointerFrame pointerReturn address (used by function call)30

Our First ExampleInstitute of Electronics, National Chiao Tung University Can we figure out the code?swap(int v[], int k);{ int temp;temp v[k]v[k] v[k 1];v[k 1] temp;}DEE 1050 Lecture 2: Instructionsswap:muli 2, 5, 4add 2, 4, 2lw 15, 0( 2)lw 16, 4( 2)sw 16, 0( 2)sw 15, 4( 2)jr 31

So far we’ve learned:Institute of Electronics, National Chiao Tung University MIPS— loading words but addressing bytes— arithmetic on registers only Instructionadd s1, s2, s3sub s1, s2, s3lw s1, 100( s2)sw s1, 100( s2)DEE 1050 Lecture 2: InstructionsMeaning s1 s2 s3 s1 s2 – s3 s1 Memory[ s2 100]Memory[ s2 100] s1

Institute of Electronics, National Chiao Tung University Intended to be blankDEE 1050 Lecture 2: Instructions33

Instruction Format (Section 2.4)Institute of Electronics, National Chiao Tung UniversityMIPS: 32-bit instruction and dataMIPS fields are given names to make them easier to discuss: (R-type)op6 bitsrsrt5 bits5 bitsrd5 bitsshamt5 bitsfunct6 bitsHere is the meaning of each name of the fields in MIPSinstructions: op:operation of the instruction, called the opcode rs:the first register source operand rt:the second register source operand rd:the register destination operand; it gets the result of the operation shamt: shift amount funct:function; this field selects the variant of the operation in the op fieldcalled function codeDEE 1050 Lecture 2: Instructions34

Instruction Format : Example Instructions, like registers and words of data, are also 32 bits longInstitute of Electronics, National Chiao Tung University– Example: add t1, s1, s2– registers have numbers, t1 9, s1 17, s2 18why? Instruction Format:000000 10001 10010 01000 00000opDEE 1050 Lecture 2: Instructionsrsrtrdshamt100000funct

What if Longer Field is Required? Consider the load-word and store-word instructionsInstitute of Electronics, National Chiao Tung University–––– Load word: two registers and a constantConstant 32 if any above 5-bit fields is usedWhat would the regularity principle have us do?Principle 4: Good design demands a compromiseIntroduce a new type of instruction format– I-type for immediate and data transfer instructions– other format was R-type for register Example: lw t0, 32( s2)3518932oprsrt16 bit numberWhere's the compromise?– Keep instruction the same length with different formats– Keep the formats similarDEE 1050 Lecture 2: Instructions

Data Transfer InstructionsInstitute of Electronics, National Chiao Tung University I-type (base 16 bit offsets)lwoprsrt6 bits5 bits5 bitsaddress16 bitst0, 8 ( s3) --- # Temporary reg t0 gets A[8]Note: s3 stores the start address of AAlso, rs is the base register, rt stores the destination register.DEE 1050 Lecture 2: Instructions37

Complete MIPS Instruction FormatsInstitute of Electronics, National Chiao Tung UniversityR-Formatop6 bitsrs5 bitsrt5 bitsI-Formatoprsrt6 bits5 bits5 bitsJ-Formatop6 bitsrd5 bitsshamt5 bitsfunct6 bitsaddress16 bitsaddress26 bitsSimple and regular formatDEE 1050 Lecture 2: Instructions38

Fields in MIPS InstructionsInstitute of Electronics, National Chiao Tung University op: Specifies the operation; tells which format touse rs: First source register rt: second source register (or dest. For load) rd: Destination register shamt: Shift amount funct: Further elaboration on opcode address: immediate constant, displacement, orbranch targetDEE 1050 Lecture 2: Instructions39

BIG PICTURE: Stored Program ConceptInstitute of Electronics, National Chiao Tung University Instructions are represented as numbers Programs are stored in memory— to be read or written just like dataProcessorMemorymemory for data, programs,compilers, editors, etc. Fetch & Execute Cycle– Instructions are fetched and put into a special register– Bits in the register "control" the subsequent actions– Fetch the “next” instruction and continue Consequence– Binary compatibility due to number representationDEE 1050 Lecture 2: Instructions

e.g., MIPS Arithmetic Instructions We’ll be working with the MIPS instruction set architecture – similar to other architectures developed since the 1980's – Almost 100 million MIPS processors manufactured in 2002 – used by NEC, Nintendo, Cisco, Silicon Graphics, Sony, 1400

Related Documents:

An old whip-poor-will, Singin’ songs in the twilight on Mockin’ Bird Hill. Tra-la-la twittle-dee-dee-dee it gives me a thrill to wake up in the mornin’ to the Mockin’ bird’s trill; Tra-la-la twittle-dee-dee-dee, there’s peace and good will; You’re welcome as the flowers on Mockin’ Bird Hill.

DEE 106 Fundamentals of Electrical Engineering 9. DME 117 Engg. Drawing-I 10. DEEM 201 Applied Mathematics-II 11. DEEP 202 Applied Physics 12. DME 203 Elements of Mechanical Engineering 13. DEE 204 Electrical Engineering Materials 14. DEL 206 Basic Electronics 15. DME 217 Workshop Practice 16. DEE 302 Measurements & Measuring Instruments 17.

Apr 11, 2007 · State Dept. of Education Dept of Children and Families Judicial Department Higher Education Community and Technical colleges Public Health Dept of Mental Health and Addiction Services Dept of Mental Retardation Dept t of Labor Dept of Transportation Dept of Corrections We do not have a

20767 Implementing a SQL Data Warehouse 5 1600 20768 Developing SQL Data Models 3 1050 20773 Analyzing Big Data with Microsoft R 3 1050 20775 Performing Data Engineering on Microsoft HD Insight 5 1600 20778 Analyzing Data with Power BI 3 1050 20779 Analyzing Data with Excel 3 1050 55153 Microsoft SQL AlwaysOn and High Availability 2 710 55246 .

LG Electronics V10 10 LG Electronics V20 10 LG Electronics V30 30 LG Electronics V40 ThinQ Dual SIM 80 LG Electronics V50 ThinQ 160 LG Electronics VELVET 4G 100 LG Electronics VELVET 5G 120 LG Electronics X Powe

TDLR/Texas Dept. of Licensing and Regulation Dee Meador IT Director Dee.meador@tdlr.texas.gov 512-463-3572. Scope of TDLR . Boilers 2 54,527 Continuing Education Providers & Courses 2 1,331 Air Conditioning & Refrigeration 4 50,929 Industrialized Housing & Buildings 6 504

2017 Jeep Grand Cherokee Ted 22,606 Mi. 35,998 Dee Motors 2017 Ford F-150 24,001 miles 34,750 Robert Allen Nissan 2017 Jeep Grand Cherokee Limited Edition Silver 33,998 Dee Motors 2017 GMC Terrain SLT Grey 12,745 Mi. 25,498 Dee Motors 2017 Mazda CX-5 15,299 miles 24,136 Robert Allen Nissan 2017 Kia Sedona Van Leather Loaded 22,995 Mile High Kia 2016 Ford F-250 29,273 miles 47,396 Robert .

mathematics at an advanced level, including articulation to university degree study. The Unit will provide learners with opportunities to develop the knowledge, understanding and skills to apply a range of differential and integral calculus techniques to the solution of mathematical problems. Outcomes On successful completion of the Unit the learner will be able to: 1 Use differentiation .