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

Similar documents
CS/COE0447: Computer Organization

Five classic components

Five classic components

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

CS222: MIPS Instruction Set

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

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

Reduced Instruction Set Computer (RISC)

syscall takes a service ID (number) in $v0 Read integer $v0=5, after syscall, $v0 holds the integer read from keyboard

Reduced Instruction Set Computer (RISC)

MIPS%Assembly% E155%

Chapter 2A Instructions: Language of the Computer

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

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

CS/COE1541: Introduction to Computer Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

EEC 581 Computer Architecture Lecture 1 Review MIPS

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

ECE232: Hardware Organization and Design

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

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

Chapter 2. Instruction Set Architecture (ISA)

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

Lecture 4: MIPS Instruction Set

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

Computer Architecture

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

Computer Architecture

Lecture 5: Procedure Calls

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

CENG3420 Lecture 03 Review

Computer Architecture. MIPS Instruction Set Architecture

CS3350B Computer Architecture MIPS Instruction Representation

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

Chapter 2. Instructions:

Computer Organization MIPS ISA

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

CS3350B Computer Architecture MIPS Introduction

Unsigned Binary Integers

Unsigned Binary Integers

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

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

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

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

Instructions: Language of the Computer

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Computer Architecture. The Language of the Machine

Instructions: Language of the Computer

Instruction Set Architecture. "Speaking with the computer"

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

ECE 154A Introduction to. Fall 2012

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

CS3350B Computer Architecture

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

Computer Organization and Components

ECE369. Chapter 2 ECE369

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

Topic Notes: MIPS Instruction Set Architecture

COMPUTER ORGANIZATION AND DESIGN

Chapter 2: Instructions:

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

Control Instructions

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

Instruction Set Architectures Part I: From C to MIPS. Readings:

Course Administration

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

Lectures 3-4: MIPS instructions

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

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

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

CSEE 3827: Fundamentals of Computer Systems

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

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

Chapter 3. Instructions:

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

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

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

CS 61c: Great Ideas in Computer Architecture

MACHINE LANGUAGE. To work with the machine, we need a translator.

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Instructions: Assembly Language

Levels of Programming. Registers

Computer Architecture. Lecture 2 : Instructions

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

Chapter 4. The Processor. Computer Architecture and IC Design Lab

Architecture I. Computer Systems Laboratory Sungkyunkwan University

CMPE324 Computer Architecture Lecture 2

The MIPS Instruction Set Architecture

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

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Transcription:

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 operations Memory access operations Computer Science Department MIPS operations and operands MIPS arithmetic Operation specifies what function to perform by the instruction Operand specifies with what a specific function is to be performed by the instruction MIPS operations Arithmetic (integer/floating-point) Logical Shift Compare Load/store Branch/jump System control and coprocessor MIPS operands Registers Fixed registers (e.g., HI/LO) Memory location Immediate value <op> <r target > <r source1 > <r source2 > All arithmetic instructions have 3 operands Operand order in notation is fixed; target first Two source registers and one target or destination register Examples add r1, r2, r3 sub r4, r5, r6 # r1 r2 + r3 # r4 r5 r6

MIPS registers General-purpose registers (GPRs) $zero $at $v $v1 $a $a1 $a2 $a3 $t $t1 $t2 $t3 $t4 $t5 $t6 $t7 32 bits 32 bits 32 bits r r1 r2 r3 r4 r5 r6 r7 r8 r9 r1 r11 r12 r13 r14 r15 r16 r17 r18 r19 r2 r21 r22 r23 r24 r25 r26 r27 r28 r29 r3 r31 General-Purpose Registers $s $s1 $s2 $s3 $s4 $s5 $s6 $s7 $t8 $t9 $k $k1 $gp $sp $fp $ra HI LO PC Special-Purpose Registers The name GPR implies that all these registers can be used as operands in instructions Still, conventions and limitations exist to keep GPRs from being used arbitrarily r, termed $zero, always has a value of r31, termed $ra (return address), is reserved for storing the return address for subroutine call/return Register usage and related software conventions are typically summarized in application binary interface (ABI) important when writing system software such as an assembler or a compiler 32 GPRs in MIPS Are they sufficient? Special-purpose registers Instruction encoding HI/LO registers are used for storing result from multiplication operations PC (program counter) Always keeps the pointer to the current program execution point; instruction fetching occurs at the address in PC Not directly visible and manipulated by programmers in MIPS Other architectures May not have HI/LO; use GPRs to store the result of multiplication May allow storing to PC to make a jump Instructions are encoded in binary numbers Assembler translates assembly programs into binary numbers Machine (processor) decodes binary numbers to figure out what the original instruction is MIPS has a fixed, 32-bit instruction encoding Encoding should be done in a way that decoding is easy MIPS instruction formats R-format: arithmetic instructions I-format: data transfer/arithmetic/jump instructions J-format: jump instruction format (FI-/FR-format: floating-point instruction format)

MIPS instruction formats Instruction encoding example Instruction Format op rs rt rd shamt funct address Field Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits All MIPS instructions 32 bits add R reg reg reg 1 NA R-format op rs rt rd shamt funct Arithmetic/logic instruction format sub R reg reg reg 11 NA I-format op rs rt address/immediate Data transfer, branch, immediate format addi (add immediate) lw (load word) I 1 reg reg NA NA NA constant I 111 reg reg NA NA NA address J-format op target address Jump instruction format sw (store word) I 1111 reg reg NA NA NA address Logic instructions Dealing with immediate R-format op rs rt rd shamt funct Logic instruction format I-format op rs rt 16-bit immediate Transfer, branch, immediate format Bit-wise logic operations <op> <r target > <r source1 > <r source2 > Examples and r3, r2, r1 or r3, r2, r1 # r3 r2 & r1 # r3 r2 r1 nor r3, r2, r1 # r3 ~(r2 r1) xor r3, r2, r1 # r3 r2 ^ r1 Many operations involve small immediate value a = a + 1 b = b 4 c = d x4 Some frequently used arithmetic/logic instruction shave their immediate version addi r3, r2, 16 # r3 r2 + 16 andi r5, r4, xfffe # r5 r4 & 111111111111111b ori r4, r4, 4 # r4 r4 1b xori r7, r6, 16 # r7 r6 ^ 1b There is no subi ; why?

Handling long immediate number Sometimes we need a long immediate value, e.g., 32 bits Do we need an instruction to load a 32-bit constant value to a register? MIPS requires that we use two instructions lui r3, 11111111b r3 11111111 Then we fill the low-order 16 bits ori r3, r3, 11111111b r3 11111111 11111111 Memory transfer instructions Also called memory access instructions Only two types of instructions Load: move data from memory to register e.g., lw r5, 4(r6) # r5 memory[r6 + 4] Store: move data from register to memory e.g., sw r7, 16(r3) # memory[r3+16] r7 In MIPS (32-bit architecture) there are memory transfer instructions for 32-bit word: int type in C 16-bit half-word: short type in C 8-bit byte: char type in C Address calculation Memory view Memory address is specified with a (register, constant) pair Register to keep the base address Constant field to keep the offset from the base address Address is, then, (register + offset) The offset can be positive or negative MIPS uses this simple address calculation method; other architectures such as PowerPC and x86 support different methods Memory is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is an index into the array 1 2 3 4 5 BYTE # BYTE #1 BYTE #2 BYTE #3 BYTE #4 BYTE #5

Memory organization More on alignment 32-bit byte address 2 32 bytes with byte addresses from to 2 32 1 2 3 words with byte addresses, 4, 8,, 2 32 4 Words are aligned 2 least significant bits (LSBs) of an address are s Half words are aligned LSB of an address is Addressing within a word Which byte appears first and which byte the last? Big-endian vs. little-endian 4 8 12 16 2 MSB LSB MSB 1 2 3 LSB 3 2 1 A misaligned access lw $r4, 3(r) How do we define a word at address? Data in byte, 1, 2, 3 If you meant this, use the address, not 3 Data in byte 3, 4, 5, 6 If you meant this, it is indeed misaligned! Certain hardware implementation may support this; usually not If you still want to obtain a word starting from the address 3 get a byte from address 3, a word from address 4 and manipulate the two data to get what you want Alignment issue does not exist for byte access 1 2 3 4 4 5 6 7 8 8 9 1 11 Shift instructions Control R-format op NOT USED rt rd shamt funct shamt is shift amount Bits change their positions inside a word <op> <r target > <r source > <shift_amount> Examples sll r3, r4, 4 # r3 r4 << 4 srl r6, r5, 6 # r6 r5 >> 6 Shift amount can be in a register (in that case shamt is not used) Shirt right arithmetic (sra) keeps the sign of a number sra r7, r8, 4 Instruction that potentially changes the flow of program execution MIPS conditional branch instructions bne r4, r3, LABEL beq r4, r3, LABEL Example h=i+j; if (i == h) h =i+j; YES (i == h)? NO LABEL: bne r5, r6, LABEL add r6, r6, r4 LABEL:

Control MIPS addressing modes MIPS unconditional branch instruction (i.e., jump) j LABEL Example f, g, and h are in registers r5, r6, r7 Immediate addressing (I-format) op rs rt immediate Register addressing (R-/I-format) op rs rt rd shamt funct if (i == h) f=g+h; else f=g h; YES (i == h)? NO bne r8, r7, ELSE add r5, r6, r7 j EXIT ELSE: sub r5, r6, r7 EXIT: op rs rt immediate Base addressing (load/store) [register + offset] op rs rt offset PC-relative addressing (beq/bne) [PC + 4 + offset] op rs rt offset f=g+h; f=g h Pseudo-direct addressing (j) [concatenation w/ PC] EXIT op 26-bit address Register usage convention Stack and frame pointers NAME REG. NUMBER USAGE $zero zero $at 1 reserved for assembler usage $v~$v1 2~3 values for results and expression eval. $a~$a3 4~7 arguments $t~$t7 8~15 temporaries $s~$s7 16~23 temporaries, saved $t8~$t9 24~25 more temporaries $k~$k1 26~27 reserved for OS kernel $gp 28 global pointer $sp 29 stack pointer $fp 3 frame pointer $ra 31 return address Stack pointer ($sp) Keeps the address to the top of the stack $29 is reserved for this purpose Stack grows from high address to low Typical stack operations are push/pop Procedure frame Contains saved registers and local variables Activation record Frame pointer ($fp) Points to the first word of a frame Offers a stable reference pointer $3 is reserved for this Some compilers don t use $fp

C program down to numbers Producing a binary swap: muli $2, $5, 4 add $2, $4, $2 lw $15, ($2) lw $16, 4($2) sw $16, ($2) sw $15, 4($2) jr $31 void swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } 111 11 111111 11111111 111111111 1111111 11111 source file.asm/.s source file.asm/.s source file.asm/.s assembler assembler assembler object file.obj/.o object file.obj/.o object file.obj/.o linker library.lib/.a executable.exe Wrapping up MIPS ISA Typical RISC style architecture 32 GPRs 32-bit instruction format 32-bit address space MIPS is the basis for our study throughout this semester; however, the concepts we study are not particularly tied with MIPS Operations & operands Arithmetic, logical, memory access, control instructions