Ch2a- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Taking orders A computer does what you tell it to do Not necessarily what.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

CENG 311 Decisions in C/Assembly Language
Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
ISA Issues; Performance Considerations. Testing / System Verilog: ECE385.
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
1 Warning! Unlike the previous lessons, for today's lesson you will have to listen, think and even understand (for the exam, of course). Individuals with.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
CPSC CPSC 3615 Computer Architecture Chapter 3 Instructions and Addressing (Text Book: Chapter 5)
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Feb 18, 2009 Lecture 4-1 instruction set architecture (Part II of [Parhami]) MIPS assembly language instructions MIPS assembly programming.
1 Today  Finish-up procedures/stack  strlen example  Machine language, the binary representation for instructions. —We’ll see how it is designed for.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Topic IIa Instruction Set Architecture and MIPS
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
Ch2b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
CDA 3101 Spring 2016 Introduction to Computer Organization
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
Morgan Kaufmann Publishers
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
3.
COMS 361 Computer Organization
COMS 361 Computer Organization
Instructions in Machine Language
MIPS Coding Continued.
Presentation transcript:

Ch2a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Taking orders A computer does what you tell it to do Not necessarily what you want it to do... We give computers orders by means of instructions Instructions tell the computer what it should be doing, right now Arithmetic Logic Data movement Control

Ch2a- 3 EE/CS/CPE Computer Organization  Seattle Pacific University Binary review Binary representations of numbers consist of only 1’s and 0’s = = = Unsigned (always positive) binary numbers 2 10 = 1024 = 1K  1, = 1,048,576 = 1M  1,000, = 1,073,741,824 = 1G  1,000,000,000 Being fluent in binary is highly underrated on the dating scene 2 10 = 1024 = 1K  1, = 1,048,576 = 1M  1,000, = 1,073,741,824 = 1G  1,000,000,000 Being fluent in binary is highly underrated on the dating scene Binary Facts:

Ch2a- 4 EE/CS/CPE Computer Organization  Seattle Pacific University Converting between binary and hex Binary Group bits together in groups of 4 Assign the appropriate hex digit to each group Done > > C 8 7 = 232C87 16 Hexadecimal A B C D E F

Ch2a- 5 EE/CS/CPE Computer Organization  Seattle Pacific University The Translation Process Computers speak in binary. We don’t. (Exception: Geeks) A = B + C add$1, $2, $ Compiler Assembler High-level language Assembly language Machine language Compilers and Assemblers translate from one language to another.

Ch2a- 6 EE/CS/CPE Computer Organization  Seattle Pacific University MIPS Instructions addA, B, C Operation Destination Sources A = B + C subD, A, B D = A - B In MIPS, All register-to-register arithmetic instructions have three operands. In MIPS, All register-to-register arithmetic instructions have three operands.

Ch2a- 7 EE/CS/CPE Computer Organization  Seattle Pacific University Operands addA, B, C What are A, B, and C? The operands of arithmetic instructions are always registers add$17, $18, $19 Add contents of registers 18 and 19 and put result in register 17 sub $19, $19, $18 Subtract $19 - $18 and put the result back in $19

Ch2a- 8 EE/CS/CPE Computer Organization  Seattle Pacific University Registering MIPS has 32 general-purpose registers $0 through $31 47 $2 Each register holds 32 bits 0 to (4 billion) if unsigned to (-2 billion to +2 billion) if signed Most registers can hold any value, for any purpose Exception: $0 is always zero!

Ch2a- 9 EE/CS/CPE Computer Organization  Seattle Pacific University Register Naming and Conventions In MIPS, all registers (except $0) can be used for any purpose desired However, there are standard use conventions that make it easier to write software #NamePurpose $0$zeroConstant zero $1$atReserved for assembler $2$v0Function return value $3$v1 $4$a0Function parameter $5$a1 $6$a2 $7$a3 $8$t0Temporary – Caller-saved $9$t1 $10$t2 $11$t3 $12$t4 $13$t5 $14$t6 $15$t7 #NamePurpose $16$s0Temporary – Callee-saved $17$s1 $18$s2 $19$s3 $20$s4 $21$s5 $22$s6 $23$s7 $24$t8Temporary – Caller-saved $25$t9 $26$k0Reserved for OS $27$k1 $28$gpGlobal pointer $29$spStack pointer $30$fpFrame pointer $31$raFunction return address

Ch2a- 10 EE/CS/CPE Computer Organization  Seattle Pacific University Reflections on Registers Registers are just “special” memory locations A small number of registers, as opposed to a huge number of memory locations Because there are a small number of registers, accessing them is fast Principle: Smaller is usually faster. Trade-offs More registers --> More data in fast memory --> Faster execution Fewer registers --> Registers are faster --> Faster execution Compromise: 16 to 32 registers works well

Ch2a- 11 EE/CS/CPE Computer Organization  Seattle Pacific University Complicated arithmetic F = (A + B) - (C + D) Assume: A is in $8 B is in $9 C is in $10 D is in $11 F is in $12 Note: Typically, the compiler assigns variables to registers Note: Typically, the compiler assigns variables to registers $12 = ($8 + $9) - ($10 + $11) We don’t have a 5-operand add/subtract instruction! Use temporary variables to solve the problem. add$13, $8, $9# $13 <-- A + B add$14, $10, $11 # $14 <-- C + D sub$12, $13, $14# F <-- (A+B) - (C+D) $13 and $14 are temporary variables

Ch2a- 12 EE/CS/CPE Computer Organization  Seattle Pacific University Getting to the bits of it all We’ve looked at assembly language (briefly) The CPU wants bits. add$13, $8, $9 Assembler Opcode RS RT RD ShAmt Function 6 bits5 bits 6 bits 0 = Add$8$9$13032=Add 32 bits, total R-Type Instruction

Ch2a- 13 EE/CS/CPE Computer Organization  Seattle Pacific University Staying Regular R-Type instructions all have the same format: Add has an opcode of ‘0’, a function of ‘32’ The instructions differ only in one bit! Regularity: Similar functions should be similar in format. Regularity is a key to high-performance Opcode RS RT RD ShAmt Function 6 bits5 bits 6 bits Subtract has an opcode of ‘0’, a function of ‘34’ add $13,$8,$9: sub $13,$8,$9:

Ch2a- 14 EE/CS/CPE Computer Organization  Seattle Pacific University Constants Many times, an instruction needs to use a constant value Multiply by 4 Add 3 I-Type instructions all have the same format: Opcode RS RT Immediate Data 6 bits5 bits 16 bits I-Type Instruction add immediate Instructions with constant data in them are called immediate instructions addi $12, $10, 4 # Reg. 12 <-- Reg

Ch2a- 15 EE/CS/CPE Computer Organization  Seattle Pacific University Doing Double Duty You desire to copy the value in register $8 to $10 Called a “move” in computer terms move $10, $8 #copy register $8 to $10 Doesn’t exist in MIPS assembly language! add $10, $8, $0 # adds zero and $8, result in $10 Does the same thing as a move Allows the add instruction to serve double duty! Many instructions have double/triple functions sub $8, $0, $8 # negate $8 addi $12, $0, 4 # load register $12 with value 4

Ch2a- 16 EE/CS/CPE Computer Organization  Seattle Pacific University Boooooring Straight-line code is nice, but boring Just arithmetic and loads/stores based on a predetermined sequence A = B+C D = B+F M[18]=D D = B+F D>23? M[22] = D C = B+A Y N Decision-making elements add some spice to the equation Control allows programs to make decisions based on their current state The most common control structure is the branch

Ch2a- 17 EE/CS/CPE Computer Organization  Seattle Pacific University Going places Consider the lowly GoTo if (x == y) q = 13; if (x != y) GoTo Next; q = 13; Next:... while (y < 2) y = y+1; Loop:if (y >=2) GoTo End; y = y+1; GoTo Loop; End:... if (p > q) r = 3; else r=2; if (p>q) GoTo R3; r = 2; GoTo Next; R3:r = 3; Next:... if (condition) GoTo location and GoTo location are all we need if (condition) GoTo location and GoTo location are all we need

Ch2a- 18 EE/CS/CPE Computer Organization  Seattle Pacific University Branching out if ($9 == $10) GoTo Label; beq$9, $10, Label if ($7 != $13) GoTo Next; bne$7, $13, Next beq - Branch if EQual bne - Branch if Not Equal Branches need: Opcode Two registers to compare Location to go to Opcode RS RT Immediate Data 6 bits5 bits 16 bits I-Type Instruction More details on specifying the branch target in immediate data later

Ch2a- 19 EE/CS/CPE Computer Organization  Seattle Pacific University Unconditional branches - Jumps GoTo Exit; jExit j - Jump (unconditionally) Opcode Immediate Data 6 bits26 bits J-Type Instruction Jumps need only an opcode and data - There is a lot more room for the data... More details on specifying the jump target in immediate data later

Ch2a- 20 EE/CS/CPE Computer Organization  Seattle Pacific University IF-Then Structures if $x == $y then S1 S2 S1 should be executed if $x == $y is True If $x != $y, or after S1 is executed, S2 is executed bne $x, $y, False # if $x != $y, skip S1 S1# $x == $y, execute S1 False:S2# either way we get here, execute S2 beq $x, $y, True # if $x == $y, then execute S1 jFalse# $x != $y, so exit True:S1# $x == $y, execute S1 False:S2# either way we get here, execute S2 If you can’t express the condition as a negative, try this:

Ch2a- 21 EE/CS/CPE Computer Organization  Seattle Pacific University IF-Then-Else Structures if $x == $y then S1 else S2 S3 S1 should be executed if $x == $y S2 should be executed if $x != $y After executing S1 or S2, execute S3 beq$x, $y, IF# if $x == $y, goto S1, skip S2 S2 # $x != $y, execute S2 jFinish# now execute S3 IF:S1 # $x == $y, so execute S1 Finish:S3# either way, we do S3 afterwards

Ch2a- 22 EE/CS/CPE Computer Organization  Seattle Pacific University While Loops while $x == $y do S1 Execute S1 repeatedly as long as $x == $y is true Repeat:bne$x,$y, Exit# exit if $x != $y is False S1# execute body of loop jRepeat# do it all over again Exit:# end of the loop Repeat:S1# execute body of loop beq$x,$y, Repeat# do it again if $x == $y Exit:# end of the loop Warning: The following loop always executes at least once, no matter what $x and $y are:

Ch2a- 23 EE/CS/CPE Computer Organization  Seattle Pacific University For Loops for i = $start to $finish {S1} S2 Execute S1 for all values from $start to $finish (step of 1) add$t0, $start, $0# copy start to i ($t0) Loop:bgt$t0, $finish, done# if i > finish, then we’re done - do S2 S1# execute S1 addi$t0, $t0, 1# increment count jLoop# go again done:S2 Use temporary, $t0 to hold i Note: bgt doesn’t really exist - more on that next...

Ch2a- 24 EE/CS/CPE Computer Organization  Seattle Pacific University Other conditions slt$4, $10, $11 Set $4 = 1 if ($10 < $11), otherwise $4 = 0 if ($7 < $8) then $15 = 3; slt$1, $7, $8# $1 <-- ($7 < $8) beq$1, $0, GoOn# If not less than, go on addi$15, $0, 3# ($7 < $8), so $15 <-- 3 GoOn: Set on Less Than if ($12 >= $3) then $4 = $2; slt$1, $12, $3# $1 <-- ($12 < $3) bne$1, $0, GoOn# If less than, go on add$4, $2, $0# ($12 >= $13), so $4 = $2 GoOn: Example: $7=4, $8=9 $1 = 1 ( $7 < $8) $1  0, Don’t branch Set $15 to 3 Example: $7=4, $8=2 $1 = 0 ( $7 > $8) $1 == 0, Branch GoOn ($15 not changed) Example: $12=4, $3=2 $1 = 0 ( $12 > $3) $1 == 0, Don’t branch Set $4 to 2