Five classic components

Similar documents
Five classic components

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

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

CS/COE0447: Computer Organization

MIPS%Assembly% E155%

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

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

ECE260: Fundamentals of Computer Engineering

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

ECE260: Fundamentals of Computer Engineering

ECE232: Hardware Organization and Design

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

Instructions: Language of the Computer

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

Unsigned Binary Integers

Unsigned Binary Integers

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

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

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

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Lecture 4: MIPS Instruction Set

Lecture 5: Procedure Calls

Computer Architecture. The Language of the Machine

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

MIPS Reference Guide

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture

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

Computer Organization and Components

Chapter 2. Instructions:

Instructions: Language of the Computer

Topic Notes: MIPS Instruction Set Architecture

Chapter 2A Instructions: Language of the Computer

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

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

MIPS and QTSPIM Recap. MIPS Architecture. Cptr280. Dr Curtis Nelson. Cptr280, Autumn

EEC 581 Computer Architecture Lecture 1 Review MIPS

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

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

Computer Architecture. MIPS Instruction Set Architecture

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

Computer Architecture

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

Chapter 2: Instructions:

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

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

MIPS Instruction Set

Part II Instruction-Set Architecture. Jan Computer Architecture, Instruction-Set Architecture Slide 1

CS222: MIPS Instruction Set

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

ECE 154A Introduction to. Fall 2012

MIPS Processor Overview

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

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

M2 Instruction Set Architecture

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

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

The MIPS Instruction Set Architecture

MIPS Instruction Set Architecture (2)

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

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

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

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

Concocting an Instruction Set

CS/COE1541: Introduction to Computer Architecture

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

Instructions: Language of the Computer

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

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

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

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

MIPS Assembly: More about MIPS Instructions Using Functions in MIPS CS 64: Computer Organization and Design Logic Lecture #8

CENG3420 Lecture 03 Review

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Computer Organization MIPS ISA

Programming the processor

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

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

Computer Organization and Components

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

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

ECE 486/586. Computer Architecture. Lecture # 7

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

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

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

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

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

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

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

SPIM Instruction Set

Chapter 2. Instruction Set Architecture (ISA)

MIPS Assembly Language. Today s Lecture

Transcription:

CS/COE0447: Computer Organization and Assembly Language Chapter 2 modified by Bruce Childers original slides by Sangyeun Cho Dept. of Computer Science Five classic components I am like a control tower I am like a pack of file folders I am like a conveyor belt + service stations I exchange information with outside world 2 1

MIPS operations and operands Operation specifies what function to perform by the instruction Operand specifies what quantity to use with the instruction MIPS operations operation: addition Arithmetic (integer/floating-point) Logical (AND, OR, etc) Shift (moves bits around) Compare (equality test) addi $t0,$t1,10 Load/store (get/put stuff in memory) Branch/jump (make decisions) source operands System control and coprocessor MIPS operands Registers (one of 32 general-purpose regs) Fixed registers (e.g., HI/LO) destination operand Memory location (place in memory) Immediate value (constant) $t0 = $t1 + 10 3 MIPS arithmetic <op> <r target >, <r source1 >, <r source2 > All arithmetic instructions have 3 operands Operand order in notation is fixed; target (destination) first Two source registers and one target (destination) register Operands are either 2 registers or 1 register + 1 immediate (constant) Destination is always a register Examples add $s1, $s2, $s3 # $s1 $s2 + $s3 sub $s4, $s5, $s6 # $s4 $s5 $s6 4 2

MIPS registers 32 bits 32 bits 32 bits $zero $at $v0 $v1 $a0 $a1 $a2 $a3 $t0 $t1 $t2 $t3 $t4 $t5 $t6 $t7 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31 General-Purpose Registers Just a table, or array, of temporary locations referred to by a number (register number) $s0 $s1 $s2 $s3 $s4 $s5 $s6 $s7 $t8 $t9 $k0 $k1 $gp $sp $fp $ra HI LO PC Special-Purpose Registers 5 General-purpose registers (GPRs) 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 (from the PRM) $0, termed $zero, always has a value of 0 $31, 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? 6 3

Special-purpose registers HI/LO registers used to store result from multiplication PC register (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 instruction set architectures May not have HI/LO; use GPRs to store the result of multiplication May allow storing to PC to make a jump 7 Instruction encoding 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/branch instructions J-format: jump instruction format (changes program counter) (FI-/FR-format: floating-point instruction format) 8 4

MIPS instruction formats Name Fields Comments bit 31 bit 0 Field Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits All MIPS instructions 32 bits R-format op (opcode) rs rt rd shamt funct Arithmetic/logic instruction format I-format op (opcode) rs rt Immediate/address Data transfer, branch, imm. format J-format op (opcode) target address Jump instruction format 9 Instruction encoding example add $t0,$t1,$t8 $t8 is register 24 rt = 11000 (5 bits) $t1 is register 9 rs = 01001 (5 bits) $t0 is register 8 rd = 01000 (5 bits) operation is addition opcode = 000000 (6 bits) funct = 100000 (6 bits) Resulting encoded instruction: shamt is unused shamt = 00000 (5 bits) Op Rs Rt Rd Shamt Funct 00000001001110000100000000100000 10 5

Dealing with immediate Name Fields Comments I-format op rs rt 16-bit immediate Transfer, branch, immediate format Many operations involve small immediate value a = a + 1 b = b 4 c = d & 0xff Example instructions addi $s3, $s2, 1 # $s3 $s2 + 1 addi $s4, $s1, -4 # $s4 $s1 + (-4) andi $s5, $s0, 0xff # $s5 $s0 & 0x000000ff Immediate is pos/neg up to 15 bits (15 bit value with 1 bit sign ) li $reg,immediate # $s3 0xFDECBA98 (up to 32 bits) 11 Interacting with the OS We need the OS s help!!! How to print a number? (output) How to read a number? (input) How to terminate (halt) a program? How to open, close, read, write a file? These are operating system services Special instruction: syscall A software interrupt to invoke OS for an action (to do a service) Need to indicate the service to perform (e.g., print vs. terminate) May also need to pass an argument value (e.g., number to print) 12 6

A few useful syscalls syscall takes a service ID (number) sent to OS in $v0 <load arguments> <set service id in $v0> syscall Print integer $v0=1, $a0=integer to print Read integer $v0=5, after syscall, $v0 holds the integer read from keyboard Print string $v0=4, $a0=memory address of string to print (null terminated) Exit (halt) $v0=10, no argument Example: Print 100d li $a0,100 # value to print li $v0,10 # print int service syscall # call OS See MARS docs for more!!! Also, attend recitation. 13 Example: First Asm. Program! Program should do the following: 1 Ask user for a number, X 2 Add 100 to X 3 Print the result (X+100) 4 Exit What do we need? syscall to input, output number, exit program add instruction for X + 100 load immediate 14 7

Example: First Asm. Program!!li!$v0,5!!!# read integer, X!!syscall!!!# returns X in $v0!!addi!$a0,$v0,100!# $a0 = $v0 + 100!!li!$v0,1!!!# print integer in $a0!!syscall!!!# invoke OS!!li!$v0,10!!# exit program!!syscall! 15 Example: Second Asm. Program! Let s clean this up a bit. We should prompt the user to ask for a number. We should print a prompt with the output. We need to use strings in the assembly program. The strings are data! Specify string name, string type, and string value Data is specified in special part of program: data section Data has general format: name:!.type!!data-values! allowed types are: asciiz, word, byte, etc. 16 8

!.data! msg1:!.asciiz!! Enter a value:\n!! msg2:!.asciiz!! Sum of value and 100:\n!!.text!!li!$v0,4!!# prompt user (print string)!!la!$a0,msg1!# indicate the message!!syscall!!li!$v0,5!!# read integer, X!!syscall!!!!!addi!$s0,$v0,100!# $s0 = X + 100!!li!$v0,4!!# output message!!la!$a0,msg2!# indicate the message!!syscall!!li!$v0,1!!# print integer!!move!$a0,$s0!# value to print!!syscall!!!!!li!$v0,10!!# exit program!!syscall! DATA CODE 17 Logic instructions Name Fields Comments R-format op rs rt rd shamt funct Logic instruction format Bit-wise logic operations <op> <r target >, <r source1 >, <r source2 > Examples and $s3, $s2, $s1 # $s3 $s2 & $s1 or $t3, $t2, $t1 # $t3 $t2 $t1 nor $s3, $t2, $s1 # $s3 ~($t2 $s1) note: nor $s3,$t2,$0 is $s3!($t2) (not of $t2) xor $s3, $s2, $s1 # $s3 $s2 ^ $s1 note: xor produces 1 iff one of the operands is 1 21 9

Logic Instructions with Immediates Logic instructions have I-format (small immediate) versions andi $s0,$s1,0xff00 ori $s0,$s1,0x0ff0 xori $s0,$s1,0xf00f nori $s0,$s1,0xffff Upper bits (bits 31..16) are set to 0s by instruction E.g., 0xff00 is really 0x0000ff00 This operation is known as zero extension 22 Handling long immediate number li allows loading large immediates (> 16 bits) Pseudo-operation: Assembler converts to actual machine instructions Consider: li $s3,0xaa55cc33 Converted to two instructions: lui $s3, 1010 1010 0101 0101b $s3 1010101001010101 0000000000000000 Then we fill the low-order 16 bits ori $s3, $s3, 1100 1100 0011 0011b $s3 1010101001010101 1100110000110011 23 10

Shift instructions Name Fields Comments 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 $s3, $s4, 4 # $s3 $s4 << 4 srl $s6, $s5, 6 # $s6 $s5 >> 6 Shift amount can be in a register ( shamt is not used) Shirt right arithmetic (sra) keeps the sign of a number sra $s7, $s5, 4 Let s try it in MARS!!!! (mips6.asm) 24 11