# Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Size: px
Start display at page:

## Transcription

1 Computer Organization and Structure Bing-Yu Chen National Taiwan University

2 Instructions: Language of the Computer 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 Communicating with People MIPS Addressing for 32-Bit Immediates and Addresses Translating and Starting a Program Arrays vs. Pointers 1

3 Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers had very simple instruction sets Simplified implementation Many modern computers also have simple instruction sets 2

4 The MIPS Instruction Set Used as the example throughout the book Stanford MIPS commercialized by MIPS Technologies ( Large share of embedded core market Applications in consumer electronics, network/storage equipment, cameras, printers, Typical of many modern ISAs See MIPS Reference Data tear-out card, and Appendixes B and E 3

5 Arithmetic Operations Add and Subtract, 3 operands 2 sources and 1 destination operand order is fixed destination first all arithmetic operations have this form Example: C code: MIPS code: a = b + c add a, b, c 4

6 Arithmetic Operations Design Principle 1: simplicity favors regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost 5

7 Arithmetic Examples compiling two C assignments into MIPS C code: a = b + c; d = a - e; MIPS code: add a, b, c sub d, a, e compiling a complex C assignment into MIPS C code: f = (g + h) (i + j) MIPS code: add \$t0, g, h # temp t0 = g + h add \$t1, i, j # temp t1 = i + j sub f, \$t0, \$t1 # f = t0 - t1 6

8 Register Operands Of course this complicates some things... C code: a = b + c + d; MIPS code: add a, b, c add a, a, d where a & b & c & d mean registers Arithmetic instructions use register operands operands must be registers 7

9 Register Operands MIPS has a bit register file Use for frequently accessed data Numbered 0 to bit data called a word Assembler names \$t0, \$t1,, \$t9 for temporary values \$s0, \$s1,, \$s7 for saved variables Design Principle 2: smaller is faster c.f. main memory: millions of locations 8

10 Register Operand Example C code: f = (g + h) (i + j) assume f,, j in \$s0,, \$s4 MIPS code: add \$t0, \$s1, \$s2 add \$t1, \$s3, \$s4 sub \$s0, \$t0, \$t1 9

11 Registers vs. Memory Arithmetic instructions operands must be registers only 32 registers provided Compiler associates variables with registers What about programs with lots of variables Control Datapath Memory Input Output processor I/O 10

12 Memory Operands Main memory used for composite data Arrays, structures, dynamic data To apply arithmetic operations Load values from memory into registers Store result from register to memory Memory is byte addressed Each address identifies an 8-bit byte Words are aligned in memory Address must be a multiple of 4 MIPS is Big Endian Most-Significant Byte at least address of a word c.f. Little Endian: Least-Significant Byte at least address 11

13 Big Endian vs. Little Endian A B C D Data a A a+1 B a+2 C a+3 D Memory Big Endianness a D a+1 C a+2 B a+3 A Memory Little Endianness 13

14 Load & Store Instructions C code: g = h + A[8]; g in \$s1, h in \$s2, base address of A in \$s3 MIPS code: lw \$t0, 32(\$s3) add \$s1, \$s2, \$t0 index 8 requires offset of 32 4 bytes per word can refer to registers by name (e.g., \$s2, \$t0) instead of number 16

15 Load & Store Instructions C code: A[12] = h + A[8]; h in \$s2, base address of A in \$s3 MIPS code: lw \$t0, 32(\$s3) add \$t0, \$s2, \$t0 sw \$t0, 48(\$s3) store word has destination last remember arithmetic operands are registers, not memory can t write: add 48(\$s3), \$s2, 32(\$s3) 17

16 Registers vs. Memory Registers are faster to access than memory Operating on memory data requires loads and stores More instructions to be executed Compiler must use registers for variables as much as possible Only spill to memory for less frequently used variables Register optimization is important! 18

17 Immediate Operands Constant data specified in an instruction addi \$s3, \$s3, 4 No subtract immediate* instruction Just use a negative constant addi \$s2, \$s1, -1 Design Principle 3: Make the common case fast Small constants are common Immediate operand avoids a load instruction *e.g. subi 20

18 The Constant Zero MIPS register 0 (\$zero) is the constant 0 Cannot be overwritten Useful for common operations add \$t2, \$s1, \$zero e.g., move between registers 21

19 Unsigned Binary Integers Given an n-bit number x x 2 x 2 x 2 x 2 n 1 n n 1 n Range: 0 to +2 n 1 Example = = = Using 32 bits 0 to +4,294,967,295 23

20 2 s-complement Signed Integers Given an n-bit number x x 2 x 2 x 2 x 2 n 1 n n 1 n Range: -2 n-1 to +2 n-1 1 Example = = 2,147,483, ,147,483,644 = 4 10 Using 32 bits 2,147,483,648 to +2,147,483,647 24

21 2 s-complement Signed Integers Bit 31 is sign bit 1 for negative numbers 0 for non-negative numbers ( 2 n 1 ) can t be represented Non-negative numbers have the same unsigned and 2 s-complement representation Some specific numbers 0: : Most-negative: Most-positive:

22 Signed Negation Complement and add 1 Complement means 1 0, 0 1 x x x 1 x 2 Example: negate = = = negate and complement are quite different!

23 Sign Extension Representing a number using more bits Preserve the numeric value In MIPS instruction set addi: extend immediate value lb, lh: extend loaded byte/halfword beq, bne: extend the displacement Replicate the sign bit to the left c.f. unsigned values: extend with 0s Examples: 8-bit to 16-bit +2: => : =>

24 Representing Instructions Instructions are encoded in binary Called machine code MIPS instructions Encoded as 32-bit instruction words Small number of formats encoding operation code (opcode), register numbers, Regularity! Register numbers \$t0 \$t7 are reg s 8 15 \$t8 \$t9 are reg s \$s0 \$s7 are reg s MIPS instruction MIPS register 28

25 MIPS R-format Instructions op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits op = operation code (opcode) basic operation of the instruction rs / rt / rd register source / destination operand shamt = shift amount for now funct = function code extends opcode 29

26 R-format Example op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits add \$t0, \$s1, \$s2 special \$s1 \$s2 \$t0 0 add =

27 Hexadecimal Base 16 Compact representation of bit strings 4 bits per hex digit c d a 1010 e b 1011 f 1111 Example: eca

28 MIPS I-format Instructions op rs rt constant or address 6 bits 5 bits 5 bits 16 bits Immediate arithmetic and load/store instructions rs / rt: source or destination register number Constant: 2 15 to Address: offset added to base address in rs Design Principle 4: Good design demands good compromises Different formats complicate decoding, but allow 32- bit instructions uniformly Keep formats as similar as possible 32

29 I-format Example op rs rt constant or address 6 bits 5 bits 5 bits 16 bits lw \$t0, 32(\$s2) lw \$s2 \$t

30 C / MIPS / Machine Languages C: A[300] = h + A[300] MIPS: lw \$t0, 1200(\$t1) add \$t0, \$s2, \$t0 sw \$t0, 1200(\$t1) Machine Language:

31 Stored Program Concept Instructions represented in binary, just like data Instructions and data stored in memory Programs can operate on programs Processor e.g., compilers, linkers, Binary compatibility allows compiled programs to work on different computers Standardized ISAs memory for data, programs, compilers, editors, etc. Memory Accounting program (machine code) Editor program (machine code) C compiler (machine code) Payroll data Book text C code for editor program 36

32 Logical Operations Instructions for bitwise manipulation Operation C MIPS Shift left << sll Shift right >> srl Bitwise AND & and, andi Bitwise OR or, ori Bitwise NOT ~ nor Useful for extracting and inserting groups of bits in a word 37

33 Shift Operations op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits shamt: how many positions to shift Shift left logical Shift left and fill with 0 bits sll by i bits multiplies by 2 i Shift right logical Shift right and fill with 0 bits srl by i bits divides by 2 i (unsigned only) 39

34 Shift Operations NOTICE shift left/right logical is not I-type Example: sll \$t2, \$s0, 4 Machine Language: op rs rt rd shamt funct special none \$s0 \$t2 4 sll

35 AND Operations Useful to mask bits in a word Select some bits, clear others to 0 and \$t0, \$t1, \$t2 \$t2 = \$t1 = \$t0 =

36 OR Operations Useful to include bits in a word Set some bits to 1, leave others unchanged or \$t0, \$t1, \$t2 \$t2 = \$t1 = \$t0 =

37 NOT Operations Useful to invert bits in a word Change 0 to 1, and 1 to 0 MIPS has NOR 3-operand instruction a NOR b == NOT ( a OR b ) nor \$t0, \$t1, \$zero \$t1 = \$t0 =

38 Conditional Operations Branch to a labeled instruction if a condition is true Otherwise, continue sequentially MIPS conditional branch instructions: bne \$t0, \$t1, Label beq \$t0, \$t1, Label Example: if (i==j) h = i + j; bne \$s0, \$s1, Label add \$s3, \$s0, \$s1 Label:... 44

39 Unconditional Operations MIPS unconditional branch instructions: j Label (Un-)Conditional Branch Example: if (i==j) bne \$s3, \$s4, Else f=g+h; add \$s0, \$s1, \$s2 else j Exit f=g-h; Else: sub \$s0, \$s1, \$s2 Exit:... Can you build a simple for / while loop? Assembler calculates addresses 45

40 Compiling Loop Statements C: while (save [i] == k) i += 1; assume i in \$s3, k in \$s5, address of save in \$s6 MIPS: Loop: sll \$t1, \$s3, 2 # \$t1=4*i add \$t1, \$t1, \$s6 # \$t1=addr. of save[i] lw \$t0, 0(\$t1) # \$t0=save[i] bne \$t0, \$s5, Exit # go to Exit if save[i]!=k addi \$s3, \$s3, 1 # i+=1 j Loop # go to Loop Exit: 46

41 Basic Blocks A basic block is a sequence of instructions with No embedded branches (except at end) No branch targets (except at beginning) A compiler identifies basic blocks for optimization An advanced processor can accelerate execution of basic blocks 47

42 More Conditional Operations set on less than: if (\$s3 < \$s4) slti \$t1, \$s3, \$s4 \$t1=1; else \$t1=0; can use this instruction to build blt \$s1, \$s2, Label can now build general control structures NOTE the assembler needs a register to do this, there are policy of use conventions for registers 48

43 Branch Instruction Design Why not blt, bge, etc? Hardware for <,, slower than =, Combining with branch involves more work per instruction, requiring a slower clock All instructions penalized! beq and bne are the common case This is a good design compromise 49

44 Signed vs. Unsigned Signed comparison: slt, slti Unsigned comparison: sltu, sltui Example \$s0 = \$s1 = slt \$t0, \$s0, \$s1 # signed 1 < +1 \$t0 = 1 sltu \$t0, \$s0, \$s1 # unsigned +4,294,967,295 > +1 \$t0 = 0 52

45 Procedure Calling Steps required Place parameters in registers Transfer control to procedure Acquire storage for procedure Perform procedure s operations Place result in register for caller Return to place of call 53

46 Register Usage Name Register No. Usage \$zero 0 the constant value 0 \$v0-\$v1 2-3 values for results & expression evaluation \$a0-\$a3 4-7 arguments \$t0-\$t temporaries (can be overwritten by callee) \$s0-\$s saved (must be saved/restored by callee) \$t8-\$t more temporaries \$gp 28 global pointer \$sp 29 stack pointer \$fp 30 frame pointer \$ra 31 return address Register 1 (\$at) reserved for assembler, for operating system 54

47 Procedure Call Instructions Procedure call: jump and link jal ProcedureLabel Address of following instruction put in \$ra Jumps to target address Procedure return: jump register jr \$ra Copies \$ra to program counter Can also be used for computed jumps e.g., for case/switch statements 55

48 Leaf Procedure Example int leaf_example (int g, int h, int i, int j) { int f; } f = (g+h)-(i+j); return f; Assume Arguments g,, j in \$a0,, \$a3 f in \$s0 (hence, need to save \$s0 on stack) Result in \$v0 56

49 Leaf Procedure Example addi \$sp, \$sp, -4 # adjust stack for saving \$s0 sw \$s0, 0(\$sp) add \$t0, \$a0, \$a1 # g+h add \$t1, \$a2, \$a3 # i+j sub \$s0, \$t0, \$t1 # (g+h)-(i+j) add \$v0, \$s0, \$zero # return f (\$v0=\$s0+0) lw \$s0, 0(\$sp) addi \$sp, \$sp, 4 # adjust stack again jr \$ra # jump back to calling routine 57

50 Non-Leaf Procedures Procedures that call other procedures For nested call, caller needs to save on the stack: Its return address Any arguments and temporaries needed after the call Restore from the stack after the call 59

51 Non-Leaf Procedure Example int fact (int n) { if (n < 1) return 1; else return (n * fact (n - 1)); } Assume Argument n in \$a0 Result in \$v0 60

53 Local Data on the Stack High address \$fp \$sp Low address Local data allocated by callee e.g., C automatic variables \$fp \$sp saved argument registers (if any) saved return address saved saved registers (if any) local arrays and structures (if any) Procedure frame (activation record) Used by some compilers to manage stack storage 62

54 Memory Layout Text: program code Static data: global variables e.g., static variables in C, constant arrays and strings \$gp initialized to address allowing ±offsets into this segment Dynamic data: heap E.g., malloc in C Stack: automatic storage \$sp 7fff fffc hex \$gp hex hex \$pc hex 0 Stack Dynamic data Static data Text Reserved 63

55 Character Data Byte-encoded character sets ASCII: 128 characters 95 graphic, 33 control Latin-1: 256 characters ASCII, +96 more graphic characters Unicode: 32-bit character set Used in C++ wide characters, Most of the world s alphabets, plus symbols UTF-8, UTF-16: variable-length encodings 64

56 Byte/Halfword Operations Could use bitwise operations MIPS byte/halfword load/store String processing is a common case lb rt, offset(rs) Sign extend to 32 bits in rt lbu rt, offset(rs) lh rt, offset(rs) Zero extend to 32 bits in rt sb rt, offset(rs) lhu rt, offset(rs) sh rt, offset(rs) Store just rightmost byte/halfword 65

57 String Copy Example void strcpy (char x[], char y []) { int i; } i = 0; while (x[i] = y[i]!= 0 ) { i = i + 1; } Assume Null-terminated string Addresses of x, y in \$a0, \$a1, i in \$s0 66

58 String Copy Example addi \$sp, \$sp, -4 sw \$s0, 0(\$sp) add \$s0, \$zero, \$zero # i = 0 L1:add \$t1, \$s0, \$a1 # address of y[i] in \$t1 lb \$t2, 0(\$t1) # \$t2 = y[i] add \$t3, \$s0, \$a0 # address of x[i] in \$t3 sb \$t2, 0(\$t3) # x[i] = y[i] beq \$t2, \$zero, L2 # if y[i] == 0, go to L2 addi \$s0, \$s0, 1 # i = i + 1 j L1 # go to L1 L2: lw \$s0, 0(\$sp) # restore old \$s0 addi \$sp, \$sp, 4 jr \$ra 67

59 32-bit Constants Most constants are small 16-bit immediate is sufficient For the occasional 32-bit constant lui rt, constant Copies 16-bit constant to left 16 bits of rt Clears right 16 bits of rt to 0 lui \$s0, 61 ori \$s0, \$s0,

60 Branch Addressing Instructions: bne \$s0,\$s1,l1 beq \$s0,\$s1,l2 Formats: I op rs rt 16 bit number Most branch targets are near branch Forward or backward PC-relative addressing Target address = PC + offset 4 PC already incremented by 4 by this time 69

61 Jump Addressing Instructions: j L1 jal L2 Formats: J op 26 bit number Jump targets could be anywhere in text segment Encode full address in instruction (Pseudo)Direct jump addressing Target address = PC : (address 4) 70

62 Target Addressing Example C: while (save [i] == k) i += 1; MIPS: Loop: sll \$t1, \$s3, 2 add \$t1, \$t1, \$s6 lw \$t0, 0(\$t1) bne \$t0, \$s5, Exit addi \$s3, \$s3, 1 j Loop Exit:

63 Branching Far Away If branch target is too far to encode with 16-bit offset, assembler rewrites the code Example L2:... beq \$s0,\$s1, L1 bne \$s0,\$s1, L2 j L1 72

64 Addressing Mode Summary Immediate addressing op rs rt immediate Register addressing op rs rt rd shamt funct Registers Register 73

65 Addressing Mode Summary Base addressing op rs rt address Register Memory Byte Halfword Word + 74

67 Decoding Machine Code What is the assembly language statement corresponding to this machine instruction? 00af8020 hex op = R-format rs = (a1)/ rt = (t7)/ rd = (s0) shamt = / funct = add add \$s0, \$a1, \$t7 MIPS instruction MIPS register 76

68 C Sort Example Illustrates use of assembly instructions for a C bubble sort function Swap procedure (leaf) void swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } v in \$a0, k in \$a1, temp in \$t0 86

69 The Procedure Swap swap: sll \$t1, \$a1, 2 # \$t1=k*4 add \$t1, \$a0, \$t1 # \$t1=v+(k*4) # (addr. of v[k]) lw \$t0, 0(\$t1) # \$t0=v[k] lw \$t2, 4(\$t1) # \$t2=v[k+1] sw \$t2, 0(\$t1) # v[k]=\$t2 sw \$t0, 4(\$t1) # v[k+1] = \$t0 jr \$ra # return to # calling routine 87

70 The Sort Procedure in C Non-leaf (calls swap) void sort (int v[], int n) { int i, j; for (i = 0; i < n; i += 1) { for (j = i 1; j >= 0 && v[j] > v[j + 1]; j -= 1) { swap(v,j); } } } v in \$a0, k in \$a1, i in \$s0, j in \$s1 88

71 The Procedure Body move \$s2, \$a0 # save \$a0 into \$s2 move \$s3, \$a1 # save \$a1 into \$s3 move \$s0, \$zero # i = 0 for1tst: slt \$t0, \$s0, \$s3 # \$t0 = 0 if \$s0 \$s3 (i n) beq \$t0, \$zero, exit1 # go to exit1 if \$s0 \$s3 (i n) addi \$s1, \$s0, 1 # j = i 1 for2tst: slti \$t0, \$s1, 0 # \$t0 = 1 if \$s1 < 0 (j < 0) bne \$t0, \$zero, exit2 # go to exit2 if \$s1 < 0 (j < 0) sll \$t1, \$s1, 2 # \$t1 = j * 4 add \$t2, \$s2, \$t1 # \$t2 = v + (j * 4) lw \$t3, 0(\$t2) # \$t3 = v[j] lw \$t4, 4(\$t2) # \$t4 = v[j + 1] slt \$t0, \$t4, \$t3 # \$t0 = 0 if \$t4 \$t3 beq \$t0, \$zero, exit2 # go to exit2 if \$t4 \$t3 move \$a0, \$s2 # 1st param of swap is v (old \$a0) move \$a1, \$s1 # 2nd param of swap is j jal swap # call swap procedure addi \$s1, \$s1, 1 # j = 1 j for2tst # jump to test of inner loop exit2: addi \$s0, \$s0, 1 # i += 1 j for1tst # jump to test of outer loop exit1: 89

72 The Full Procedure sort: addi \$sp,\$sp, 20 # make room on stack for 5 registers sw \$ra, 16(\$sp) # save \$ra on stack sw \$s3,12(\$sp) # save \$s3 on stack sw \$s2, 8(\$sp) # save \$s2 on stack sw \$s1, 4(\$sp) # save \$s1 on stack sw \$s0, 0(\$sp) # save \$s0 on stack # procedure body exit1: lw \$s0, 0(\$sp) # restore \$s0 from stack lw \$s1, 4(\$sp) # restore \$s1 from stack lw \$s2, 8(\$sp) # restore \$s2 from stack lw \$s3,12(\$sp) # restore \$s3 from stack lw \$ra,16(\$sp) # restore \$ra from stack addi \$sp,\$sp, 20 # restore stack pointer jr \$ra # return to calling routine 90

73 Arrays vs. Pointers Array indexing involves Multiplying index by element size Adding to array base address Pointers correspond directly to memory addresses Can avoid indexing complexity 91

74 Array vs. Pointers in C void clear1 (int array[], int size) { int i; for (i = 0; i < size; i += 1) array[i] = 0; } void clear2 (int *array, int size) { int *p; for (p = &array[0]; p < &array[size]; p += 1) *p = 0; } 92

75 Array Version of Clear in MIPS add \$t0, \$zero, \$zero loop1: sll \$t1, \$t0, 2 add \$t2, \$a0, \$t1 sw \$zero, 0(\$t2) addi \$t0, \$t0, 1 slt \$t3, \$t0, \$a1 bne \$t3, \$zero, loop1 93

76 Pointer Version of Clear in MIPS add \$t0, \$a0, \$zero loop2: sw \$zero, 0(\$t0) addi \$t0, \$t0, 4 sll \$t1, \$a1, 2 add \$t2, \$a0, \$t1 slt \$t3, \$t0, \$t2 bne \$t3, \$zero, loop2 94

77 New Pointer Version of Clear add \$t0, \$a0, \$zero sll \$t1, \$a1, 2 add \$t2, \$a0, \$t1 loop2: sw \$zero, 0(\$t0) addi \$t0, \$t0, 4 slt \$t3, \$t0, \$t2 bne \$t3, \$zero, loop2 95

78 Comparing the Two Versions add \$t0, \$zero, \$zero add \$t0, \$a0, \$zero lp1: sll \$t1, \$t0, 2 sll \$t1, \$a1, 2 add \$t2, \$a0, \$t1 add \$t2, \$a0, \$t1 sw \$zero, 0(\$t2) lp2 : sw \$zero, 0(\$t0) addi \$t0, \$t0, 1 addi \$t0, \$t0, 4 slt \$t3, \$t0, \$a1 slt \$t3, \$t0, \$t2 bne \$t3, \$zero, lp1 bne \$t3, \$zero, lp2 96

79 Comparison of Array vs. Pointer Multiply strength reduced to shift Array version requires shift to be inside loop Part of index calculation for incremented i c.f. incrementing pointer Compiler can achieve same effect as manual use of pointers Induction variable elimination Better to make program clearer and safer 97

### Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Chapter 2 Instructions: Language of the Computer Adapted by Paulo Lopes Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects

### COMPUTER ORGANIZATION AND DESIGN

COMPUTER ORGANIZATION AND DESIGN 5 th The Hardware/Software Interface Edition Chapter 2 Instructions: Language of the Computer 2.1 Introduction Instruction Set The repertoire of instructions of a computer

### Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Computer Organization and Structure Bing-Yu Chen National Taiwan University Instructions: Language of the Computer Operations and Operands of the Computer Hardware Signed and Unsigned Numbers Representing

### MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Representing Instructions Instructions are encoded in binary Called machine code MIPS instructions Encoded as 32-bit instruction words Small number of formats encoding operation code (opcode), register

### Chapter 2A Instructions: Language of the Computer

Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction

### Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Lecture 2 Instructions: Language of the Computer (Chapter 2 of the textbook) Instructions: tell computers what to do Chapter 2 Instructions: Language of the Computer 2 Introduction Chapter 2.1 Chapter

### Chapter 2. Instructions: Language of the Computer

Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers

### Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Introduction to the MIPS Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS The Microprocessor without Interlocked Pipeline Stages

Branch Addressing Branch instructions specify Opcode, two registers, target address Most branch targets are near branch Forward or backward op rs rt constant or address 6 bits 5 bits 5 bits 16 bits PC-relative

### MIPS Instruction Set Architecture (2)

MIPS Instruction Set Architecture (2) Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu

### Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Chapter 2 Computer Abstractions and Technology Lesson 4: MIPS (cont ) Logical Operations Instructions for bitwise manipulation Operation C Java MIPS Shift left >>> srl Bitwise

### Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Instructions: MIPS ISA Chapter 2 Instructions: Language of the Computer 1 PH Chapter 2 Pt A Instructions: MIPS ISA Based on Text: Patterson Henessey Publisher: Morgan Kaufmann Edited by Y.K. Malaiya for

### 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

### Thomas Polzer Institut für Technische Informatik

Thomas Polzer tpolzer@ecs.tuwien.ac.at Institut für Technische Informatik Branch to a labeled instruction if a condition is true Otherwise, continue sequentially beq rs, rt, L1 if (rs == rt) branch to

### Chapter 2. Baback Izadi Division of Engineering Programs

Chapter 2 Baback Izadi Division of Engineering Programs bai@engr.newpaltz.edu Instruction Set Language of the Machine The repertoire of instructions of a computer Different computers have different instruction

### Computer Architecture Computer Science & Engineering. Chapter 2. Instructions: Language of the Computer BK TP.HCM

Computer Architecture Computer Science & Engineering Chapter 2 Instructions: Language of the Computer Computer Component 25-Aug-16 Faculty of Computer Science & Engineering 2 Instruction execution process

### COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

COMPSCI 313 S2 2018 Computer Organization 7 MIPS Instruction Set Agenda & Reading MIPS instruction set MIPS I-format instructions MIPS R-format instructions 2 7.1 MIPS Instruction Set MIPS Instruction

### Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

Chapter 2 Instructions: Language of the Computer HW#1: 1.3 all, 1.4 all, 1.6.1, 1.14.4, 1.14.5, 1.14.6, 1.15.1, and 1.15.4 Due date: one week. Practice: 1.5 all, 1.6 all, 1.10 all, 1.11 all, 1.14 all,

### Chapter 2. Instructions: Language of the Computer

Chapter 2 Instructions: Language of the Computer Instruction Set The range of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers

### CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

CSCI 402: Computer Architectures Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI Recall Big endian, little endian Memory alignment Unsigned

### Computer Architecture

CS3350B Computer Architecture Winter 2015 Lecture 4.2: MIPS ISA -- Instruction Representation Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted from lectures on Computer Organization and Design,

### LECTURE 2: INSTRUCTIONS

LECTURE 2: INSTRUCTIONS Abridged version of Patterson & Hennessy (2013):Ch.2 Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many

### Machine Instructions - II. Hwansoo Han

Machine Instructions - II Hwansoo Han Conditional Operations Instructions for making decisions Alter the control flow - change the next instruction to be executed Branch to a labeled instruction if a condition

### Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions Computer Organization Architectures for Embedded Computing Thursday, 26 September 2013 Many slides adapted from: Computer Organization and Design, Patterson & Hennessy 4th Edition,

### Control Instructions

Control Instructions Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class Instruction Set

### CS3350B Computer Architecture MIPS Instruction Representation

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

### Instructions: Language of the Computer

Instructions: Language of the Computer Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class

### Procedure Call Instructions

Procedure Calling Steps required 1. Place parameters in registers x10 to x17 2. Transfer control to procedure 3. Acquire storage for procedure 4. Perform procedure s operations 5. Place result in register

### 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,

### Unsigned Binary Integers

Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

### Unsigned Binary Integers

Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

### Chapter 2. Instructions: Language of the Computer

Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers

### 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

### Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

182.690 Rechnerstrukturen Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many

### 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

### COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 2. Instructions: Language of the Computer

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers

### COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 2. Instructions: Language of the Computer

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers

### Instruction Set. The MIPS Instruction Set. Chapter 2

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition 1 Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers

### Chapter 2. Instructions: Language of the Computer

Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers

### Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

Chapter 1 Computer Abstractions and Technology Lesson 3: Understanding Performance Manufacturing ICs 1.7 Real Stuff: The AMD Opteron X4 Yield: proportion of working dies per wafer Chapter 1 Computer Abstractions

### Chapter 2. Instructions: Language of the Computer. Baback Izadi ECE Department

Chapter 2 Instructions: Language of the Computer Baback Izadi ECE Department bai@engr.newpaltz.edu Instruction Set Language of the Machine The repertoire of instructions of a computer Different computers

### Chapter 2. Instruction Set. The MIPS Instruction Set. Arithmetic Operations. Instructions: Language of the Computer

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition Chapter 2 Instructions: Language of the Computer

### Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

CSE2021 Computer Organization Chapter 2: Part 2 Procedure Calling Procedure (function) performs a specific task and return results to caller. Supporting Procedures Procedure Calling Calling program place

### ECE260: Fundamentals of Computer Engineering

Accessing and Addressing Memory James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy American

### CS3350B Computer Architecture MIPS Introduction

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

### 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

### 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

### Instructions: Language of the Computer. Euiseong Seo Computer Systems Laboratory Sungkyunkwan University

Instructions: Language of the Computer Euiseong Seo (euiseong@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Instruction Set The repertoire of instructions of a computer

### 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

### 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

### CENG3420 Lecture 03 Review

CENG3420 Lecture 03 Review Bei Yu byu@cse.cuhk.edu.hk 2017 Spring 1 / 38 CISC vs. RISC Complex Instruction Set Computer (CISC) Lots of instructions of variable size, very memory optimal, typically less

### Chapter 2. Instructions: Language of the Computer. Jiang Jiang

Chapter 2 Instructions: Language of the Computer Jiang Jiang jiangjiang@ic.sjtu.edu.cn [Adapted from Computer Organization and Design, 4 th Edition, Patterson & Hennessy, 2008, MK] Chapter 2 Instructions:

### Computer Architecture

CS3350B Computer Architecture Winter 2015 Lecture 4.3: MIPS ISA -- Procedures, Compilation Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted from lectures on Computer Organization and Design, Patterson

### Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface RISC-V Edition Chapter 2 Instructions: Language of the Computer These slides are based on the slides by the authors. The slides doesn t

### 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

### Chapter 2. Instructions: Language of the Computer

Chapter 2 Instructions: Language g of the Computer Outlines Introduction to MIPS machine Operations of the Computer HW Operands of the Computer HW Representing instructions in the Computer Logical Operations

### 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

### 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

### EECS Computer Organization Fall Based on slides by the author and prof. Mary Jane Irwin of PSU.

EECS 2021 Computer Organization Fall 2015 Based on slides by the author and prof. Mary Jane Irwin of PSU. Chapter Summary Stored-program concept Assembly language Number representation Instruction representation

### 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/

### Computer Organization MIPS ISA

CPE 335 Computer Organization MIPS ISA Dr. Iyad Jafar Adapted from Dr. Gheith Abandah Slides http://www.abandah.com/gheith/courses/cpe335_s08/index.html CPE 232 MIPS ISA 1 (vonneumann) Processor Organization

### Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the machine. Reduced number of cycles needed per instruction.

### Lecture 5: Procedure Calls

Lecture 5: Procedure Calls Today s topics: Memory layout, numbers, control instructions Procedure calls 1 Memory Organization The space allocated on stack by a procedure is termed the activation record

### Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the ISA. RISC Goals RISC: Simplify ISA Simplify CPU Design Better CPU Performance Motivated by simplifying

### CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

CISC 662 Graduate Computer Architecture Lecture 4 - ISA MIPS ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

### 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

### 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

### CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CISC 662 Graduate Computer Architecture Lecture 4 - ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

### 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 &

### Computer Organization and Design

Computer Organization and Design The Hardware/Software Interface Chapter 2 - Introductions: Language of the Computer Dr. Feng Li fli@sdu.edu.cn https://funglee.github.io 1 Contents of Chapter 2 l 2.1 Introduction

### Chapter 2. Instructions: Language of the Computer

Chapter 2 Instructions: Language of the Computer Introduction Computer language Words: instructions Vocabulary: instruction set Similar for all, like regional dialect? Design goal of computer language

### EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets

EEM870 Embedded System and Experiment Lecture 4 ARM Instruction Sets Wen-Yen Lin, Ph.D. Department of Electrical Engineering Chang Gung University Email wylin@mail.cgu.edu.tw March 2014 Introduction Embedded

### Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

Computer Architecture Chapter 2-2 Instructions: Language of the Computer 1 Procedures A major program structuring mechanism Calling & returning from a procedure requires a protocol. The protocol is a sequence

### comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions Procedure Calls A procedure of a subroutine is like an agent which needs certain information to perform a

### Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

Instructions: Chapter 3 : MIPS Downloaded from: http://www.cs.umr.edu/~bsiever/cs234/ Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive

### 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

### CENG3420 L03: Instruction Set Architecture

CENG3420 L03: Instruction Set Architecture Bei Yu byu@cse.cuhk.edu.hk (Latest update: January 31, 2018) Spring 2018 1 / 49 Overview Introduction Arithmetic & Logical Instructions Data Transfer Instructions

### 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: #...

### Chapter 2. Instructions: Language of the Computer

Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers

### 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

### COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

### CSCI 402: Computer Architectures

CSCI 402: Computer Architectures Instructions: Language of the Computer (2) Fengguang Song Department of Computer & Information Science IUPUI Memory Operands Two tribes: Big Endian: Most-significant byte

Fall 2017 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture 2/4 Avinash Kodi Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701 E-mail: kodi@ohio.edu

### Computer Architecture. The Language of the Machine

Computer Architecture The Language of the Machine Instruction Sets Basic ISA Classes, Addressing, Format Administrative Matters Operations, Branching, Calling conventions Break Organization All computers

### 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:

### ECE369. Chapter 2 ECE369

Chapter 2 1 Instruction Set Architecture A very important abstraction interface between hardware and low-level software standardizes instructions, machine language bit patterns, etc. advantage: different

### Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

Chapter 3 MIPS Assembly Language Ó1998 Morgan Kaufmann Publishers 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive

### 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

### 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

### Two processors sharing an area of memory. P1 writes, then P2 reads Data race if P1 and P2 don t synchronize. Result depends of order of accesses

Synchronization Two processors sharing an area of memory P1 writes, then P2 reads Data race if P1 and P2 don t synchronize Result depends of order of accesses Hardware support required Atomic read/write

### EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2 Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown University

### CS/COE1541: Introduction to Computer Architecture

CS/COE1541: Introduction to Computer Architecture Dept. of Computer Science University of Pittsburgh http://www.cs.pitt.edu/~melhem/courses/1541p/index.html 1 Computer Architecture? Application pull Operating

### ECE260: Fundamentals of Computer Engineering

Accessing and Addressing Memory James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy American

### Lecture 7: Examples, MARS, Arithmetic

Lecture 7: Examples, MARS, Arithmetic Today s topics: More examples MARS intro Numerical representations 1 Dealing with Characters Instructions are also provided to deal with byte-sized and half-word quantities:

### 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 6: Assembly Programs

Lecture 6: Assembly Programs Today s topics: Procedures Examples Large constants The compilation process A full example 1 Procedures Local variables, AR, \$fp, \$sp Scratchpad and saves/restores, \$fp Arguments

### EEC 581 Computer Architecture Lecture 1 Review MIPS

EEC 581 Computer Architecture Lecture 1 Review MIPS 1 Supercomputing: Suddenly Fancy 2 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control

### Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Introduction to the MIPS ISA Overview Remember that the machine only understands very basic instructions (machine instructions) It is the compiler s job to translate your high-level (e.g. C program) into