# EE108B Lecture 3. MIPS Assembly Language II

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 EE108B Lecture 3 MIPS Assembly Language II Christos Kozyrakis Stanford University 1

2 Announcements Urgent: sign up at EEclass and say if you are taking 3 or 4 units Homework #1 is available Due on Tue 1/23, 5pm outside Gates 310 Lab #1 is available Due on Tuesday 1/30, midnight Lab orientation after the class at Packard Hall Programming assignment #1 will be available on Thursday EE108B Review Session Friday: 2:15pm-3:05pm in Thornton 102 2

3 Review of MIPS Assembly Language I Instruction Set Architecture (ISA) HW/SW interface Multiple HW implementations of same interface Introduction to MIPS ISA and assembly programming Register-register or load-store or RISC ISA Arithmetic (ALU) operations Register & immediate operands add, sub, addu, subu addi, addiu Quick reminders What is the difference between add and addu? What is the difference between addi and addu? Why don t we have subi or subiu instructions? 3

4 Review of MIPS Assembly Language I Memory data transfer displacement based addressing mode lw, sw 4

5 Today s Menu Finish Memory data transfer Stores Data alignment Memory mapped I/O Control transfer instructions Branches and jumps Machine language design Binary encoding of assembly instructions 3 MIPS instruction formats 5

6 Storing Data Storing data is just the reverse and the instruction is nearly identical Use the sw instruction to copy a word from the source register to an address in memory sw src, offset(base) Offset value is signed 6

7 Storing Data Example Consider the example *a = b + c; Use the sw instruction to store add \$t0, \$s1, \$s2 sw \$t0, 0(\$s0) # \$t0 = b + c # Memory[s0] = b + c 7

8 Storing to an Array Consider the example a[3] = b + c; Use the sw instruction offset add \$t0, \$s1, \$s2 sw \$t0, 12(\$s0) # \$t0 = b + c # Memory[a[3]] = b + c 8

9 Complex Array Storage Consider the example a[i] = b + c; Use the sw instruction offset add \$t0, \$s1, \$s2 # \$t0 = b + c sll \$t1, \$s3, 2 # \$t1 = 4 * i add \$t2, \$s0, \$t1 # \$t2 = a + 4*i sw \$t0, 0(\$t2) # Memory[a[i]] = b + c 9

10 A short Array Example ANSI C requires a short to be at least 16 bits and no longer than an int, but does not define the exact size For our purposes, treat a short as 2 bytes So, with a short array c[7] is at c + 7 * 2, shift left by c[ 7] c[ 6] c[ 5] c[ 4] c[ 3] c[ 2] 1002 c[ 1] 1000 c[ 0] 2 bytes c 10

12 Alignment Restrictions In MIPS, data is required to fall on addresses that are even multiples of the data size Aligned c d e f a b memory Not Aligned Consider word (4 byte) memory access register

13 Alignment Restrictions (cont) C Example struct foo { What is the size of this structure? char sm; short med; char sm1; int lrg; /*1 Byte*/ /*2 Byte*/ /*1 Byte*/ /* 4 Bytes*/ } Byte offset sm X med sm1 X Historically Early machines (IBM 360 in 1964) required alignment Removed in 1970s to reduce impact on programmers (e.g IBM 370, Intel x86) Reintroduced by RISC to improve performance Also introduces challenges with memory organization with virtual memory, etc. lrg 13

14 Memory Mapped I/O Data transfer instructions can be used to move data to and from I/O device registers A load operation moves data from a an I/O device register to a CPU register and a store operation moves data from a CPU register to a I/O device register address (8) CPU data (8) Memory 2 7 Bytes I/O register I/O register at address 0x80 (128) 14

15 Changing Control Flow One of the distinguishing characteristics of computers is the ability to evaluate conditions and change control flow If-then-else Loops Case statements Control flow instructions Conditional branch instructions are known as branches Unconditional changes in the control flow are called jumps The target of the branch/jump is a label 15

16 Conditional: Equality The simplest conditional test is the beq instruction for equality beq reg1, reg2, label Consider the code if (a == b) goto L1; // Do something L1: // Continue Use the beq instruction beq \$s0, \$s1, L1 # Do something #... L1: # Continue 16

17 Conditional: Not Equal The bne instruction for not equal bne reg1, reg2, label Consider the code if (a!= b) goto L1; // Do something L1: // Continue Use the bne instruction bne \$s0, \$s1, L1 # Do something L1: # Continue 17

18 Unconditional: Jumps The j instruction jumps to a label j label 18

19 If-then-else Example Consider the code if (i == j) f = g + h; else f = g h; (true) i == j f=g+h i == j? f=g-h (false) i!= j Exit 19

20 If-then-else Solution Create labels and use equality instruction beq \$s3, \$s4, True # Branch if i == j False: subu \$s0, \$s1, \$s2 # f = g h j Exit True: add \$s0, \$s1, \$s2 Exit: # Go to Exit # f = g + h 20

21 Other Comparisons Other conditional arithmetic operators are useful in evaluating conditional expressions using <, >, <=, >= Use compare instruction to set register to 1 when condition met Consider the following C code if (f < g) goto Less; Solution slt \$t0, \$s0, \$s1 # \$t0 = 1 if \$s0 < \$s1 bne \$t0, \$zero, Less # Goto Less if \$t0!= 0 21

22 MIPS Comparisons Instruction Example Meaning Comments set less than slt \$1, \$2, \$3 \$1 = (\$2 < \$3) comp less than signed set less than imm slti \$1, \$2, 100 \$1 = (\$2 < 100) comp w/const signed set less than uns sltu \$1, \$2, \$3 \$1 = (\$2 < \$3) comp < unsigned set l.t. imm. uns sltiu \$1, \$2, 100 \$1 = (\$2 < 100) comp < const unsigned C if (a < 8) Assembly slti \$v0,\$a0,8 # \$v0 = a < 8 beq \$v0,\$zero, Exceed # goto Exceed if \$v0 == 0 22

23 C Example 1:int sum_pow2(int b, int c) 2:{ 3: int pow2 [8] = {1, 2, 4, 8, 16, 32, 64, 128}; 4: int a, ret; 5: a = b + c; 6: if (a < 8) 7: ret = pow2[a]; 8: else 9: ret = 0; 10: return(ret); 11:} 23

24 sum_pow2: # \$a0 = b, \$a1 = c addu \$a0,\$a0,\$a1 # a = b + c, \$a0 = a slti \$v0,\$a0,8 # \$v0 = a < 8 beq \$v0,\$zero, Exceed # goto Exceed if \$v0 == 0 addiu\$v1,\$sp,8 # \$v1 = pow2 address sll \$v0,\$a0,2 # \$v0 = a*4 addu \$v0,\$v0,\$v1 # \$v0 = pow2 + a*4 lw \$v0,0(\$v0) # \$v0 = pow2[a] j Return # goto Return Exceed: addu \$v0,\$zero,\$zero # \$v0 = 0 Return: jr ra # return sum_pow2 24

25 C Example Revised 1:int sum_pow2(int b, int c) 2:{ 3: int pow2 [8] = {1, 2, 4, 8, 16, 32, 64, 128}; 4: int a, ret; 5: a = b + c; 6: if (a >= 0 && a < 8) 7: ret = pow2[a]; 8: else 9: ret = 0; 10: return(ret); 11:} 25

26 sum_pow2: # \$a0 = b, \$a1 = c addu \$a0,\$a0,\$a1 # a = b + c, \$a0 = a bltz \$a0, Exceed # goto Exceed if \$v0 < 0 slti \$v0,\$a0,8 # \$v0 = a < 8 beq \$v0,\$zero, Exceed # goto Exceed if \$v0 == 0 addiu \$v1,\$sp,8 # \$v1 = pow2 address sll \$v0,\$a0,2 # \$v0 = a*4 addu \$v0,\$v0,\$v1 # \$v0 = pow2 + a*4 lw \$v0,0(\$v0) # \$v0 = pow2[a] j Return # goto Return Exceed: addu \$v0,\$zero,\$zero # \$v0 = 0 Return: jr ra # return sum_pow2 26

27 MIPS Jumps & Branches Instruction Example Meaning jump j L goto L jump register jr \$1 goto value in \$1 jump and link jal L goto L and set \$ra jump and link register jalr \$1 goto \$1 and set \$ra branch equal beq \$1, \$2, L if (\$1 == \$s2) goto L branch not eq bne \$1, \$2, L if (\$1!= \$2) goto L branch l.t. 0 bltz \$1, L if (\$1 < 0) goto L branch l.t./eq 0 blez \$1, L if (\$1 <= 0) goto L branch g.t. 0 bgtz \$1, L if (\$1 > 0) goto L branch g.t./eq 0 bgez \$1, L if (\$1 >= 0) goto L 27

28 Support for Simple Branches Only Notice that there is no branch less than instruction for comparing two registers? The reason is that such an instruction would be too complicated and might require a longer clock cycle time Therefore, conditionals that do not compare against zero take at least two instructions where the first is a set and the second is a conditional branch As we ll see later, this is a design trade-off Less time per instruction Vs. fewer instructions How do you decide what to do? Other RISC ISAs made a different choice (e.g. HP s PA-RISC) 28

29 Consider a whileloop while (A[i] == k) i = i + j; While loop in C Assembly loop Assume i = \$s0, j = \$s1, k = \$s2 Loop: sll \$t0, \$s0, 2 # \$t0 = 4 * i addu \$t1, \$t0, \$s3 # \$t1 = &(A[i]) lw \$t2, 0(\$t1) # \$t2 = A[i] bne \$t2, \$s2, Exit # goto Exit if!= addu \$s0, \$s0, \$s1 # i = i + j j Loop # goto Loop Exit: Basic block : Maximal sequence of instructions with out branches or branch targets 29

30 Improve Loop Efficiency Code uses two branches/iteration: Better structure: Cond? Body of loop Body of loop Cond? 30

31 Improved Loop Solution Remove extra jump from loop body j Cond Loop: addu \$s0, \$s0, \$s1 Cond: sll \$t0, \$s0, 2 Exit: addu \$t1, \$t0, \$s3 lw \$t2, 0(\$t1) # goto Cond # i = i + j # \$t0 = 4 * i # \$t1 = &(A[i]) # \$t2 = A[i] beq \$t2, \$s2, Loop # goto Loop if == Reduced loop from 6 to 5 instructions Even small improvements important if loop executes many times 31

32 Machine Language Representation Instructions are represented as binary data in memory Stored program - Von Neumann Simplicity One memory system Same addresses used for branches, procedures, data, etc. The only difference is how bits are interpreted What are the risks of this decision? Binary compatibility (backwards) Commercial software relies on ability to work on next generation hardware This leads to a very long life for an ISA 32

33 MIPS Instruction Encoding MIPS Instructions are encoded in different forms, depending upon the arguments R-format, I-format, J-format MIPS architecture has three instruction formats, all 32 bits in length Regularity is simpler and improves performance A 6 bit opcode appears at the beginning of each instruction Control logic based on decoded instruction type See green card and Page 103 for a list 33

34 R-Format Used by ALU instructions Uses three registers: one for destination and two for source Bits OP=0 rs rt rd sa funct First Source Register Second Source Register Result Register Shift Amount Function Code Function code specifies which operation 34

35 Consider the addu instruction addu \$t0, \$s1, \$s2 Fill in each of the fields R-Format Example Bits OP= First Source Register Second Source Register Result Register Shift Amount Function Code

36 R-Format Limitations The R-Format works well for ALU-type operations, but does not work well for some of the other instructions types Consider for example the lw instruction that takes an offset in addition to two registers R-format would provide 5 bits for the offset Offsets of only 32 are not all that useful! 36

37 I-Format The immediate instruction format Uses different opcodes for each instruction Immediate field is signed (positive/negative constants) Used for loads and stores as well as other instructions with immediates (addi, lui, etc.) Also used for branches Bits OP rs rt imm First Source Register Second Source Register or dest Immediate 37

38 I-Format Example Consider the addi instruction addi \$t0, \$t1, 1 # \$t0 = \$t1 + 1 Fill in each of the fields Bits First Source Register Second Source Register Immediate

39 Another I-Format Example Consider the while loop Loop: addu \$t0, \$s0, \$s0 Exit: addu \$t0, \$t0, \$t0 add \$t1, \$t0, \$s3 lw \$t2, 0(\$t1) # \$t0 = 2 * i # \$t0 = 4 * i # \$t1 = &(A[i]) # \$t2 = A[i] bne \$t2, \$s2, Exit # goto Exit if!= addu \$s0, \$s0, \$s1 j Loop # i = i + j # goto Loop Pretend the first instruction is located at address

40 I-Format Example (Incorrect) Consider the bne instruction bne \$t2, \$s2, Exit # goto Exit if \$t2!= \$s2 Fill in each of the fields Bits First Source Register Second Source Register Immediate This is not the optimum encoding 40

41 PC Relative Addressing How can we improve our use of immediate addresses when branching? Since instructions are always 32 bits long and word addressing requires alignment, every address must be a multiple of 4 bytes Therefore, we actually branch to the address that is PC immediate 41

42 I-Format Example Re-consider the bne instruction bne \$t2, \$s2, Exit # goto Exit if \$t2!= \$s2 Use PC-Relative addressing for the immediate Bits First Source Register Second Source Register Immediate

43 I-Format Example: Load/Store Consider the lw instruction lw \$t2, 0(\$t1) # \$t2 = Mem[\$t1] Fill in each of the fields Bits First Source Register Second Source Register Immediate

44 Branching Far Away If the target is greater than to words away, then the compiler inverts the condition and inserts an unconditional jump Consider the example where L1 is far away beq \$s0, \$s1, L1 # goto L1 if S\$0=\$s1 Can be rewritten as bne \$s0, \$s1, L2 L2: j L1 # Inverted # Unconditional jump Compiler must be careful not to cross 256 MB boundaries with jump instructions 44

45 J-Format The jump instruction format Different opcodes for each instruction Examples include j and jal instructions Absolute addressing since long jumps are common Based on word addressing (target 4) Pseudodirect addressing where 28 bits from target, and remaining 4 bits come from upper bits of PC Bits 6 26 OP target Jump Target Address Jump PC = PC target 00 45

46 Complete Example Now we can write the complete example for our while loop

47 MIPS Machine Instruction Review: Instruction Format Summary 47

48 sum_pow2: # \$a0 = b, \$a1 = c addu \$a0,\$a0,\$a1 # a = b + c, \$a0 = a bltz \$a0, Exceed # goto Exceed if \$a0 < 0 slti \$v0,\$a0,8 # \$v0 = a < 8 beq \$v0,\$zero, Exceed # goto Exceed if \$v0 == 0 addiu \$v1,\$sp,8 # \$v1 = pow2 address sll \$v0,\$a0,2 # \$v0 = a*4 addu \$v0,\$v0,\$v1 # \$v0 = pow2 + a*4 lw \$v0,0(\$v0) # \$v0 = pow2[a] b Return # goto Return Exceed: addu \$v0,zero,zero # \$v0 = 0 Return: jr ra # return sum_pow2 48

49 sum_pow2 Revised Machine and DisAssembly sum_pow2: 0x400a98: addu a0,a0,a1 0x400a9c: bltz a0,0x400abc 0x400aa0: slti v0,a0,6 0x400aa4: beq v0,zero,0x400abc 0x400aa8: 27 a addiu v1,sp,8 0x400aac: sll v0,a0,2 0x400ab0: addu v0,v0,v1 0x400ab4: 8c lw v0,0(v0) 0x400ab8: j 0x400ac0 0x400abc: addu v0,zero,zero 0x400ac0: 03 e jr ra 49

50 Addressing Modes Summary Register addressing Operand is a register (e.g. ALU) Base/displacement addressing (ex. load/store) Operand is at the memory location that is the sum of a base register + a constant Immediate addressing (e.g. constants) Operand is a constant within the instruction itself PC-relative addressing (e.g. branch) Address is the sum of PC and constant in instruction (e.g. branch) Pseudo-direct addressing (e.g. jump) Target address is concatenation of field in instruction and the PC 50

51 Addressing Modes Summary 1. Immediate addressing op rs rt Immediate 2. Register addressing op rs rt rd... funct Registers Register 3. Base addressing op rs rt Address Memory Register + Byte Halfword Word 4. PC-relative addressing op rs rt Address Memory PC + Word 5. Pseudodirect addressing op Address Memory PC Word 51

52 Logical Operators Bitwise operators often useful for bit manipulation bits 17 bits 6 bits sll \$t0, \$t3, 9 # shift \$t3 left by 9, store in \$t0 srl \$t0, \$t0, 15 # shift \$t0 right by 15 Always operate unsigned except for arithmetic shifts 52

53 MIPS Logical Instructions Instruction Example Meaning Comments and and \$1, \$2, \$3 \$1 = \$2 & \$3 Logical AND or or \$1, \$2, \$3 \$1 = \$2 \$3 Logical OR xor xor \$1, \$2, \$3 \$1 = \$2 \$3 Logical XOR nor nor \$1, \$2, \$3 \$1 = ~(\$2 \$3) Logical NOR and immediate andi \$1, \$2, 10 \$1 = \$2 & 10 Logical AND w. constant or immediate ori \$1, \$2, 10 \$1 = \$2 10 Logical OR w. constant xor immediate xori \$1, \$2, 10 \$1 = ~\$2 & ~10 Logical XOR w. constant shift left log sll \$1, \$2, 10 \$1 = \$2 << 10 Shift left by constant shift right log srl \$1, \$2, 10 \$1 = \$2 >> 10 Shift right by constant shift rt. Arith sra \$1, \$2, 10 \$1 = \$2 >> 10 Shift rt. (sign extend) shift left var sllv \$1, \$2, \$3 \$1 = \$2 << \$3 Shift left by variable shift right var srlv \$1, \$2, \$3 \$1 = \$2 >> \$3 Shift right by variable shift rt. arith srav \$1, \$2, \$3 \$1 = \$2 >> \$3 Shift right arith. var load upper imm lui \$1, 40 \$1 = 40 << 16 Places imm in upper 16b 53

54 Loading a 32 bit Constant MIPS only has 16 bits of immediate value Could load from memory but still have to generate memory address Use lui and ori to load 0xdeadbeef into \$a0 lui \$a0, 0xdead # \$a0 = dead0000 ori \$a0, \$a0, 0xbeef # \$a0 = deadbeef 54

### Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary

Announcements EE108B Lecture MIPS Assembly Language III Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b PA1 available, due on Thursday 2/8 Work on you own (no groups) Homework

### Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B

Anne Bracy CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, and Sirer. See P&H Chapter: 2.16-2.20, 4.1-4.4,

### Mips Code Examples Peter Rounce

Mips Code Examples Peter Rounce P.Rounce@cs.ucl.ac.uk Some C Examples Assignment : int j = 10 ; // space must be allocated to variable j Possibility 1: j is stored in a register, i.e. register \$2 then

### A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

A Processor Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University See: P&H Chapter 2.16-20, 4.1-3 Let s build a MIPS CPU but using Harvard architecture Basic Computer System Registers ALU

### MIPS Reference Guide

MIPS Reference Guide Free at PushingButtons.net 2 Table of Contents I. Data Registers 3 II. Instruction Register Formats 4 III. MIPS Instruction Set 5 IV. MIPS Instruction Set (Extended) 6 V. SPIM Programming

### Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Today s Lecture Homework #2 Midterm I Feb 22 (in class closed book) MIPS Assembly Language Computer Science 14 Lecture 6 Outline Assembly Programming Reading Chapter 2, Appendix B 2 Review: A Program Review:

### F. Appendix 6 MIPS Instruction Reference

F. Appendix 6 MIPS Instruction Reference Note: ALL immediate values should be sign extended. Exception: For logical operations immediate values should be zero extended. After extensions, you treat them

### CS 4200/5200 Computer Architecture I

CS 4200/5200 Computer Architecture I MIPS Instruction Set Architecture Dr. Xiaobo Zhou Department of Computer Science CS420/520 Lec3.1 UC. Colorado Springs Adapted from UCB97 & UCB03 Review: Organizational

### Digital System Design II

Digital System Design II 数字系统设计 II Peng Liu ( 刘鹏 ) Dept. of Info. Sci. & Elec. Engg. Zhejiang University liupeng@zju.edu.cn Lecture 2 MIPS Instruction Set Architecture 2 Textbook reading MIPS ISA 2.1-2.4

### MIPS Instruction Reference

Page 1 of 9 MIPS Instruction Reference This is a description of the MIPS instruction set, their meanings, syntax, semantics, and bit encodings. The syntax given for each instruction refers to the assembly

### A Processor! Hakim Weatherspoon CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

A Processor! Hakim Weatherspoon CS 3410, Spring 2010 Computer Science Cornell University See: P&H Chapter 2.16-20, 4.1-3 Announcements! HW2 available later today HW2 due in one week and a half Work alone

### Concocting an Instruction Set

Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Read: Chapter 2.1-2.7 L03 Instruction Set 1 A General-Purpose Computer The von

### A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

page 1 Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... A General-Purpose Computer The von Neumann Model Many architectural approaches

### CS 61c: Great Ideas in Computer Architecture

MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: \$s0-\$s7,\$t0-\$t9, \$0

### MIPS%Assembly% E155%

MIPS%Assembly% E155% Outline MIPS Architecture ISA Instruction types Machine codes Procedure call Stack 2 The MIPS Register Set Name Register Number Usage \$0 0 the constant value 0 \$at 1 assembler temporary

### MIPS Instruction Format

MIPS Instruction Format MIPS uses a 32-bit fixed-length instruction format. only three different instruction word formats: There are Register format Op-code Rs Rt Rd Function code 000000 sssss ttttt ddddd

### ECE232: Hardware Organization and Design. Computer Organization - Previously covered

ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization

### Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

2.9 Communication with People: Byte Data & Constants Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21 32: space 33:! 34: 35: #...

### ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2014 Sources: Computer

### Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

Today s topics CS/COE1541: Introduction to Computer Architecture MIPS operations and operands MIPS registers Memory view Instruction encoding A Review of MIPS ISA Sangyeun Cho Arithmetic operations Logic

### Week 10: Assembly Programming

Week 10: Assembly Programming Arithmetic instructions Instruction Opcode/Function Syntax Operation add 100000 \$d, \$s, \$t \$d = \$s + \$t addu 100001 \$d, \$s, \$t \$d = \$s + \$t addi 001000 \$t, \$s, i \$t = \$s +

### ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

ELEC 5200-001/6200-001 Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2) Victor P. Nelson, Professor & Asst. Chair Vishwani D. Agrawal, James J. Danaher Professor Department

### Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Computer Science 324 Computer Architecture Mount Holyoke College Fall 2009 Topic Notes: MIPS Instruction Set Architecture vonneumann Architecture Modern computers use the vonneumann architecture. Idea:

### Concocting an Instruction Set

Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Lab is posted. Do your prelab! Stay tuned for the first problem set. L04 Instruction

### Assembly Programming

Designing Computer Systems Assembly Programming 08:34:48 PM 23 August 2016 AP-1 Scott & Linda Wills Designing Computer Systems Assembly Programming In the early days of computers, assembly programming

### ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

### EE 109 Unit 8 MIPS Instruction Set

1 EE 109 Unit 8 MIPS Instruction Set 2 Architecting a vocabulary for the HW INSTRUCTION SET OVERVIEW 3 Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system

### ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5 MIPS/SPIM General Purpose Registers Powers of Two 0 \$zero all bits are zero 16 \$s0 local variable 1 \$at assembler temporary 17 \$s1 local

### CPS311 - COMPUTER ORGANIZATION. A bit of history

CPS311 - COMPUTER ORGANIZATION A Brief Introduction to the MIPS Architecture A bit of history The MIPS architecture grows out of an early 1980's research project at Stanford University. In 1984, MIPS computer

### Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

CSE 675.02: Introduction to Computer Architecture MIPS Processor Memory Instruction Set Architecture of MIPS Processor CPU Arithmetic Logic unit Registers \$0 \$31 Multiply divide Coprocessor 1 (FPU) Registers

### Computer Architecture

Computer Architecture Chapter 2 Instructions: Language of the Computer Fall 2005 Department of Computer Science Kent State University Assembly Language Encodes machine instructions using symbols and numbers

### MIPS PROJECT INSTRUCTION SET and FORMAT

ECE 312: Semester Project MIPS PROJECT INSTRUCTION SET FORMAT This is a description of the required MIPS instruction set, their meanings, syntax, semantics, bit encodings. The syntax given for each instruction

### ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

ICS 233 COMPUTER ARCHITECTURE MIPS Processor Design Multicycle Implementation Lecture 23 1 Add immediate unsigned Subtract unsigned And And immediate Or Or immediate Nor Shift left logical Shift right

### Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Assembly Language Programming CPSC 252 Computer Organization Ellen Walker, Hiram College Instruction Set Design Complex and powerful enough to enable any computation Simplicity of equipment MIPS Microprocessor

### Computer Architecture Experiment

Computer Architecture Experiment Jiang Xiaohong College of Computer Science & Engineering Zhejiang University Architecture Lab_jxh 1 Topics 0 Basic Knowledge 1 Warm up 2 simple 5-stage of pipeline CPU

### ECE Exam I February 19 th, :00 pm 4:25pm

ECE 3056 Exam I February 19 th, 2015 3:00 pm 4:25pm 1. The exam is closed, notes, closed text, and no calculators. 2. The Georgia Tech Honor Code governs this examination. 3. There are 4 questions and

### Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Stored Program Concept Instructions: Instructions are bits Programs are stored in memory to be read or written just like data Processor Memory memory for data, programs, compilers, editors, etc. Fetch

EE 352 Unit 3 MIPS ISA Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system Instruction set is the vocabulary the HW can understand and the SW is composed

### Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: MIPS Instruction Set Architecture vonneumann Architecture Modern computers use the vonneumann architecture. Idea:

### COMP MIPS instructions 2 Feb. 8, f = g + h i;

Register names (save, temporary, zero) From what I have said up to now, you will have the impression that you are free to use any of the 32 registers (\$0,..., \$31) in any instruction. This is not so, however.

### Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

### CS3350B Computer Architecture

CS3350B Computer Architecture Winter 2015 Lecture 4.1: MIPS ISA: Introduction Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted d from lectures on Computer Organization and Design, Patterson & Hennessy,

### MIPS (SPIM) Assembler Syntax

MIPS (SPIM) Assembler Syntax Comments begin with # Everything from # to the end of the line is ignored Identifiers are a sequence of alphanumeric characters, underbars (_), and dots () that do not begin

### ISA: The Hardware Software Interface

ISA: The Hardware Software Interface Instruction Set Architecture (ISA) is where software meets hardware In embedded systems, this boundary is often flexible Understanding of ISA design is therefore important

### Lecture 4: MIPS Instruction Set

Lecture 4: MIPS Instruction Set No class on Tuesday Today s topic: MIPS instructions Code examples 1 Instruction Set Understanding the language of the hardware is key to understanding the hardware/software

### SPIM Instruction Set

SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large

### CS 61C: Great Ideas in Computer Architecture RISC-V Instruction Formats

CS 61C: Great Ideas in Computer Architecture RISC-V Instruction Formats Instructors: Krste Asanović and Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 9/14/17 Fall 2017 - Lecture #7 1 Levels of

### Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Computer Organization MIPS Architecture Department of Computer Science Missouri University of Science & Technology hurson@mst.edu Computer Organization Note, this unit will be covered in three lectures.

### CS222: MIPS Instruction Set

CS222: MIPS Instruction Set Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati 1 Outline Previous Introduction to MIPS Instruction Set MIPS Arithmetic's Register Vs Memory, Registers

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures \$2M 3D camera Lecture 8 MIPS Instruction Representation I Instructor: Miki Lustig 2014-09-17 August 25: The final ISA showdown: Is ARM, x86, or

### Review of the Machine Cycle

MIPS Branch and Jump Instructions Cptr280 Dr Curtis Nelson Review of the Machine Cycle When a program is executing, its instructions are located in main memory. The address of an instruction is the address

### Chapter 2. Instruction Set Architecture (ISA)

Chapter 2 Instruction Set Architecture (ISA) MIPS arithmetic Design Principle: simplicity favors regularity. Why? Of course this complicates some things... C code: A = B + C + D; E = F - A; MIPS code:

### We will study the MIPS assembly language as an exemplar of the concept.

MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

### MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

MIPS ISA and MIPS Assembly CS301 Prof. Szajda Administrative HW #2 due Wednesday (9/11) at 5pm Lab #2 due Friday (9/13) 1:30pm Read Appendix B5, B6, B.9 and Chapter 2.5-2.9 (if you have not already done

### EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown

### CPU Design for Computer Integrated Experiment

CPU Design for Computer Integrated Experiment Shan Lu, Guangyao Li, Yijianan Wang CEIE, Tongji University, Shanghai, China Abstract - Considering the necessity and difficulty of designing a CPU for students,

### Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Department of Electrical and Computer Engineering University of Wisconsin Madison ECE 552 Introductions to Computer Architecture Homework #2 (Suggested Solution) 1. (10 points) MIPS and C program translations

### Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

Instructions (354 Review) Forecast Instructions are the words of a computer Instruction set architecture (ISA) is its vocabulary With a few other things, this defines the interface of computers But implementations

### Chapter 2. Instructions:

Chapter 2 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic Instructions We ll be working with

### ECE 154A Introduction to. Fall 2012

ECE 154A Introduction to Computer Architecture Fall 2012 Dmitri Strukov Lecture 4: Arithmetic and Data Transfer Instructions Agenda Review of last lecture Logic and shift instructions Load/store instructionsi

### CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats Instructors: Vladimir Stojanovic and Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Machine Interpretation Levels of Representation/Interpretation

### Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Computer Science and Engineering 331 Midterm Examination #1 Fall 2000 Name: Solutions S.S.#: 1 41 2 13 3 18 4 28 Total 100 Instructions: This exam contains 4 questions. It is closed book and notes. Calculators

### Chapter 2: Instructions:

Chapter 2: Instructions: Language of the Computer Computer Architecture CS-3511-2 1 Instructions: To command a computer s hardware you must speak it s language The computer s language is called instruction

### Lecture 2: RISC V Instruction Set Architecture. Housekeeping

S 17 L2 1 18 447 Lecture 2: RISC V Instruction Set Architecture James C. Hoe Department of ECE Carnegie Mellon University Housekeeping S 17 L2 2 Your goal today get bootstrapped on RISC V RV32I to start

### MIPS Assembly Programming

COMP 212 Computer Organization & Architecture COMP 212 Fall 2008 Lecture 8 Cache & Disk System Review MIPS Assembly Programming Comp 212 Computer Org & Arch 1 Z. Li, 2008 Comp 212 Computer Org & Arch 2

### Architecture II. Computer Systems Laboratory Sungkyunkwan University

MIPS Instruction ti Set Architecture II Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Making Decisions (1) Conditional operations Branch to a

### Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

Outline EEL-4713 Computer Architecture Multipliers and shifters Multiplication and shift registers Chapter 3, section 3.4 Next lecture Division, floating-point 3.5 3.6 EEL-4713 Ann Gordon-Ross.1 EEL-4713

### COMP 303 MIPS Processor Design Project 3: Simple Execution Loop

COMP 303 MIPS Processor Design Project 3: Simple Execution Loop Due date: November 20, 23:59 Overview: In the first three projects for COMP 303, you will design and implement a subset of the MIPS32 architecture

### Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Instructions: ti Language of the Computer Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn Computer Hierarchy Levels Language understood

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 14 Introduction to MIPS Instruction Representation II Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Are you P2P sharing fans? Two

### CS61C Machine Structures. Lecture 10 - MIPS Branch Instructions II. 2/8/2006 John Wawrzynek. (www.cs.berkeley.edu/~johnw)

CS61C Machine Structures Lecture 10 - MIPS Branch Instructions II 2/8/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L10 MIPS Branch II (1) Compiling C if into

### Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Stored Program Concept nstructions: nstructions are bits Programs are stored in memory to be read or written just like data Processor Memory memory for data, programs, compilers, editors, etc. Fetch &

### Architecture I. Computer Systems Laboratory Sungkyunkwan University

MIPS Instruction ti Set Architecture I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Architecture (1) the attributes of a system as seen by the

### All instructions have 3 operands Operand order is fixed (destination first)

Instruction Set Architecture for MIPS Processors Overview Dr. Arjan Durresi Louisiana State University Baton Rouge, LA 70803 durresi@csc.lsu.edu These slides are available at: http://www.csc.lsu.edu/~durresi/_07/

### CS152 Computer Architecture and Engineering. Lecture 1 Introduction & MIPS Review Dave Patterson. www-inst.eecs.berkeley.

CS152 Computer Architecture and Engineering Lecture 1 Introduction & MIPS Review 2003-08-26 Dave Patterson (www.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs152/ CS 152 L01 Introduction &

### Computer Architecture. Lecture 2 : Instructions

Computer Architecture Lecture 2 : Instructions 1 Components of a Computer Hierarchical Layers of Program Code 3 Instruction Set The repertoire of instructions of a computer 2.1 Intr roduction Different

### Lecture 2: RISC V Instruction Set Architecture. James C. Hoe Department of ECE Carnegie Mellon University

18 447 Lecture 2: RISC V Instruction Set Architecture James C. Hoe Department of ECE Carnegie Mellon University 18 447 S18 L02 S1, James C. Hoe, CMU/ECE/CALCM, 2018 Your goal today Housekeeping get bootstrapped

### CS 61c: Great Ideas in Computer Architecture

Introduction to Assembly Language June 30, 2014 Review C Memory Layout Local variables disappear because the stack changes Global variables don t disappear because they are in static data Dynamic memory

### Computer Architecture. Chapter 3: Arithmetic for Computers

182.092 Computer Architecture Chapter 3: Arithmetic for Computers Adapted from Computer Organization and Design, 4 th Edition, Patterson & Hennessy, 2008, Morgan Kaufmann Publishers and Mary Jane Irwin

### Lecture 6 Decision + Shift + I/O

Lecture 6 Decision + Shift + I/O Instructions so far MIPS C Program add, sub, addi, multi, div lw \$t0,12(\$s0) sw \$t0, 12(\$s0) beq \$s0, \$s1, L1 bne \$s0, \$s1, L1 j L1 (unconditional branch) slt reg1,reg2,reg3

### Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA)... the attributes of a [computing] system as seen by the programmer, i.e. the conceptual structure and functional behavior, as distinct from the organization of the data

### Lecture Topics. Branch Condition Options. Branch Conditions ECE 486/586. Computer Architecture. Lecture # 8. Instruction Set Principles.

ECE 486/586 Computer Architecture Lecture # 8 Spring 2015 Portland State University Instruction Set Principles MIPS Control flow instructions Dealing with constants IA-32 Fallacies and Pitfalls Reference:

### RISC, CISC, and Assemblers

RISC, CISC, and Assemblers Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H Appendix B.1 2, and Chapters 2.8 and 2.12; als 2.16 and 2.17 Big Picture: Understanding Tradeoffs

### ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

### Lab 3 (Sections 300, 301 and 302) Prelab: MIPS-Control Instructions

Lab 3 (Sections 300, 301 and 302) Prelab: MIPS-Control Instructions Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work

### Chapter 6. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 6 <1>

Chapter 6 Digital Design and Computer Architecture, 2 nd Edition David Money Harris and Sarah L. Harris Chapter 6 Chapter 6 :: Topics Introduction Assembly Language Machine Language Programming Addressing

### ECE410 Design Project Spring 2013 Design and Characterization of a CMOS 8-bit pipelined Microprocessor Data Path

ECE410 Design Project Spring 2013 Design and Characterization of a CMOS 8-bit pipelined Microprocessor Data Path Project Summary This project involves the schematic and layout design of an 8-bit microprocessor

### CHW 362 : Computer Architecture & Organization

CHW 362 : Computer Architecture & Organization Instructors: Dr Ahmed Shalaby Dr Mona Ali http://bu.edu.eg/staff/ahmedshalaby14# http://www.bu.edu.eg/staff/mona.abdelbaset Assignment What is the size of

### Lecture 3: Single Cycle Microarchitecture. James C. Hoe Department of ECE Carnegie Mellon University

8 447 Lecture 3: Single Cycle Microarchitecture James C. Hoe Department of ECE Carnegie Mellon University 8 447 S8 L03 S, James C. Hoe, CMU/ECE/CALCM, 208 Your goal today Housekeeping first try at implementing

### Chapter 3. Instructions:

Chapter 3 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic Instructions We ll be working with

Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection L5 Addressing Modes 1 Assembly Exercise Let s write some assembly language programs Program #1: Write a function

### CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

CS61C L1 MIPS Instruction Representation II, Floating Point I (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #1 Instruction Representation II, Floating Point I 25-1-3 There is one

### EC 413 Computer Organization

EC 413 Computer Organization Review I Prof. Michel A. Kinsy Computing: The Art of Abstraction Application Algorithm Programming Language Operating System/Virtual Machine Instruction Set Architecture (ISA)

### CS3350B Computer Architecture MIPS Procedures and Compilation

CS3350B Computer Architecture MIPS Procedures and Compilation Marc Moreno Maza http://www.csd.uwo.ca/~moreno/cs3350_moreno/index.html Department of Computer Science University of Western Ontario, Canada

### The MIPS R2000 Instruction Set

The MIPS R2000 Instruction Set Arithmetic and Logical Instructions In all instructions below, Src2 can either be a register or an immediate value (a 16 bit integer). The immediate forms of the instructions

### Processor (I) - datapath & control. Hwansoo Han

Processor (I) - datapath & control Hwansoo Han Introduction CPU performance factors Instruction count - Determined by ISA and compiler CPI and Cycle time - Determined by CPU hardware We will examine two

### Chapter 4. The Processor

Chapter 4 The Processor Introduction CPU performance factors Instruction count Determined by ISA and compiler CPI and Cycle time Determined by CPU hardware We will examine two MIPS implementations A simplified

### ECE/CS 552: Introduction To Computer Architecture 1. Instructor:Mikko H. Lipasti. University of Wisconsin-Madison. Basics Registers and ALU ops

ECE/CS 552: Instruction Sets Instructor:Mikko H. Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill. Instructions (354 Review) Instructions are