CPSC 330 Computer Organization

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

Chapter 2: Instructions:

Levels of Programming. Registers

MIPS Processor Overview

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

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

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

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

CS3350B Computer Architecture MIPS Introduction

CS3350B Computer Architecture

Lecture 4: MIPS Instruction Set

Instructions: Language of the Computer

Instructions: Language of the Computer

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

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

Chapter 2. Instruction Set Architecture (ISA)

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

MIPS%Assembly% E155%

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

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

Computer Organization MIPS ISA

Chapter 2A Instructions: Language of the Computer

Assembler. Lecture 8 CS301

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

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Course Administration

MIPS (SPIM) Assembler Syntax

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

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

CS/COE1541: Introduction to Computer Architecture

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

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

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

Topic Notes: MIPS Instruction Set Architecture

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

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

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

MIPS Assembly Language. Today s Lecture

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

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

MIPS Reference Guide

CS222: MIPS Instruction Set

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

Instruction Set Architecture

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

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

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

COMPUTER ORGANIZATION AND DESIGN

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

MIPS History. ISA MIPS Registers

SPIM Instruction Set

ECE369. Chapter 2 ECE369

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

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

ECE232: Hardware Organization and Design

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

Lecture 5: Procedure Calls

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

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

Computer Architecture

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Instruction Set Architecture. "Speaking with the computer"

Course Administration

The MIPS Instruction Set Architecture

EEC 581 Computer Architecture Lecture 1 Review MIPS

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

Control Instructions

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

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

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

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

MIPS Instruction Set Architecture (2)

CS 61c: Great Ideas in Computer Architecture

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

Unsigned Binary Integers

Unsigned Binary Integers

CS/COE0447: Computer Organization

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

Computer Architecture. The Language of the Machine

MIPS Assembly Programming

MIPS Coding Continued

COMP2421 COMPUTER ORGANZATION. Lab 3

MIPS Functions and Instruction Formats

Computer Architecture. MIPS Instruction Set Architecture

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

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

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

Course Administration

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

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

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

Transcription:

CPSC 330 Computer Organization Chapter 2-II Instructions: Language of the computer MIPS Instructions - Review Instruction Meaning add $s1,$s2,$s3 $s1 = $s2 + $s3 sub $s1,$s2,$s3 $s1 = $s2 $s3 addi $s1,$s1,4 $s1 = $s1 + 4 sub $s1,$s2,$s3 $s1 = $s2 $s3 slt $t0,$s0,$s1 if ($s0 < $s1) then $t0 gets 1 otherwise $t0 gets 0 lw $s1,100($s2) $s1 = Memory[$s2+25] sw $s1,100($s2) Memory[$s2+25] = $s1 bne $s4,$s5,l Next instr. is at Label if $s4? $s5 beq $s4,$s5,l Next instr. is at Label if $s4 = $s5 jr $t1 jump via register: go to the address specified by $t1 j Label mult $t1,$t2 go to the target address {Hi,Lo} = $t1*$t2 div $t1,$t2 Lo = $t1/$t2; Hi = $t1%$t2 mflo $a0 move from Lo to $s0 new CPSC330 CompOrg: Dr. Gerousis Instructions 2 Instruction Format - Review MIPS Register Convention R I J op rs rt rd shamt funct op rs rt 16 bit address op 26 bit address Name Register number Usage $zero 0 the constant value 0 $v0-$v1 2-3 values for results and expression evaluation $a0-$a3 4-7 arguments $t0-$t7 8-15 temporaries $s0-$s7 16-23 saved $t8-$t9 24-25 more temporaries CPSC330 CompOrg: Dr. Gerousis Instructions 3 CPSC330 CompOrg: Dr. Gerousis Instructions 4 1

R - Format Example - Review MIPS Example sub $t1, $s1, $s2 opcode = 0 (lookup in table) funct = 34 (lookup in table) rs = 17 (first operand) rt = 18 (second operand) rd = 8 (destination) shamt = 0 (no shift) 0 17 18 8 0 34 000000 10001 10010 01000 00000 100010 op rs rt rd shamt funct I - Format Example - Review MIPS Example lw $t0, 32($s2) # $t0 = addr [$s2 + 32/4] (offset) opcode = 35 (lookup in table) rs = 18 (first operand) rt = 9 (second operand) 35 18 9 32 100011 10010 01001 0000000000100000 op rs rt 16-bit number CPSC330 CompOrg: Dr. Gerousis Instructions 5 CPSC330 CompOrg: Dr. Gerousis Instructions 6 J - Format Example - Review MIPS Example j Loop # go to location Loop Exercise Scoreboard the operation of the program by single-stepping through the MIPS code and recording results in the trace table. No register operands. Operand destination address is signed word offset from PC. 000010 00000000000000000000100000 op 26-bit number Trace Table 0x400:a addi $t0, $zero, 3 0x404:b add $v0, $t0, $t0 0x408:c addi $t0, $t0, -1 0x40c:d bne $t0, $zero, b 0x410:e j e Step 1 2 3 4 5 6 7 8 9 10 11 12 13 14 pc t0 v0 CPSC330 CompOrg: Dr. Gerousis Instructions 7 CPSC330 CompOrg: Dr. Gerousis Instructions 8 2

Addressing Modes Everything has an address Computers need to know Where to go next? Where to get data? Program execution either Continues sequentially or Branches (near) or jumps (far) somewhere else. Programs get data either from Registers (fast and inside CPU) or... Memory (maybe near, maybe far)... (or sometimes directly from IO devices). MIPS assembler What is an assembler? An assembler translates assembly language (human readable instructions) into machine language (binary instructions, 1 s & 0 s). It s a program, similar to a compiler, only it uses a language specific to a computer s ISA. CPSC330 CompOrg: Dr. Gerousis Instructions 9 CPSC330 CompOrg: Dr. Gerousis Instructions 10 Decoding Machine Language What is the assembly language statement corresponding to the this machine instruction: (00af8020) 16? op rs rt rd shamt funct Fields: Op: 6 bits rs, rt, rd, shamt: 5 bits Funct: 6 bits Name Register number Usage $zero 0 the constant value 0 $v0-$v1 2-3 values for results and expression evaluation $a0-$a3 4-7 arguments $t0-$t7 8-15 temporaries $s0-$s7 16-23 saved $t8-$t9 24-25 more temporaries $gp 28 global pointer $sp 29 stack pointer $fp 30 frame pointer $ra 31 return address MIPS Assembler How does it work? It reads an input text file (a program written in assembly language), then it parses a line of program at a time and assembles them into machine code instructions. Lines contain either: Single instructions Assembler directives Comments (lines preceded with # or just blank) It produces an output binary file that contains machine code, data, and startup info. CPSC330 CompOrg: Dr. Gerousis Instructions 11 CPSC330 CompOrg: Dr. Gerousis Instructions 12 3

MIPS Assembler What are directives? Directives tell the assembler to do something else besides assembling..text <address> : Store subsequent program instructions or static data at address specified (if present) in the text segment.data <address> : Indicates that subsequent data items should be put in data segment MIPS Assembler More directives.byte <b>, : Store bytes in data segment.half <h>, : Store half -words (16bit).word <w>, : Store words (32bit).double <d>, : Store double words (64bit).float <f>, : Store floating point numbers.ascii <string> : store string in memory.asciiz <string> : store string zero terminated CPSC330 CompOrg: Dr. Gerousis Instructions 13 CPSC330 CompOrg: Dr. Gerousis Instructions 14 Assembler & SPIM:Starting a program SPIM Windows version C pro gram Compiler Assembly langua ge progr am Assembler Object: Machinelanguage module Object: Library routine(machinelanguage) The CD that accompanies the book contains Software: HDL simulators, MIPS simulator, and FPGA design tools. Tutorials: SPIM, Verilog, and VHDL. Content/Software/Spim/Pcspim Linker Executable: Machine languageprogram Loader M emory CPSC330 CompOrg: Dr. Gerousis Instructions 15 CPSC330 CompOrg: Dr. Gerousis Instructions 16 4

SPIM Windows version Registers window shows the values of all registers in the MIPS CPU Text segment window: shows assembly inst. & machine code Data segment window: shows the data loaded into the program s memory Messages window: shows PCSpim messages Separate console window appears for I/O CPSC330 CompOrg: Dr. Gerousis Instructions 17 Using SPIM Simulator -> Settings : In the Display section check only the first two items Save window positions and General registers in hexadecimal Simulator -> Set Value : to load PC with address of first instruction enter Address or Register Name as PC and enter Value as 0x00400000 Reason: the text area of memory, where programs are stored, starts here. Simulator -> Go : run loaded program F5 Click the OK button in the Run Parameters pop-up window if the StartingAddress: value is 0x00400000 Simulator -> Break : stop execution Simulator -> Clear Registers and Reinitialize : clean-up before new run CPSC330 CompOrg: Dr. Gerousis Instructions 18 Using SPIM Simulator Reload : load file again after editing Simulator Single Step (F10) or Multiple Step (F11): stepping to debug Simulator Breakpoints: set breakpoints Arithmetic Example for SPIM # Using SPIM, write and debug a program to input two # numbers, then computes and prints their sum and their difference. Use the # SPIM system calls read_int (5, $a0), print_int (1, $v0). # # Inputs : # integer values # Outputs: # sum, diff. # Register Usage: # $t2 = arg1 # $t4 = arg1 # $v0 = function code # $a0 = string pointer #-.text #.globl main # Entry point for SPIM linkage. CPSC330 CompOrg: Dr. Gerousis Instructions 19 CPSC330 CompOrg: Dr. Gerousis Instructions 20 5

Example (continued) Example (continued) main: nop li $v0, 4 # Load code for print_str. la $a0, askstr1 # Load address of string # Print string li $v0, 5 # Load code for read # Get arg1 move $t2, $v0 # Save arg1 li $v0, 4 # Load code for print_str. la $a0, askstr2 # Load address of string # Print string li $v0, 5 # Load code for read # Get arg2 move $t4, $v0 # Save arg2 CPSC330 CompOrg: Dr. Gerousis Instructions 21 compute: li $v0, 4 # Load code for print_str. la $a0, sumstr # Load address of string. # Print string. add $a0, $t2, $t4 # Add them. li $v0, 1 # Load code for print_int. # Print li $v0, 4 # Load code for print_str. la $a0, difstr # Load address of string # Print string sub $a0, $t2, $t4 # Subtract them li $v0, 1 # Load code for print_int. # Print.data askstr1:.asciiz "Enter an integer." askstr2:.asciiz "Enter another integer." sumstr:.asciiz "\ntheir sum is : " difstr:.asciiz "\ntheir difference is : " CPSC330 CompOrg: Dr. Gerousis Instructions 22 save log file (ctrl+s) in File Registers ========================= PC = 00000000 EPC = 00000000 Cause = 00000000 BadVAddr= 00000000 Status = 00000000 HI = 00000000 LO = 00000000 General Registers R0 (r0) = 00000000 R8 (t0) = 00000000 R16 (s0) = 00000000 R 24 (t8) = 00000000 R1 (at) = 10010000 R9 (t1) = 00000000 R17 (s1) = 00000000 R 25 (t9) = 00000000 R2 (v0) = 00000001 R10 (t2) = 0000000a R18 (s2) = 00000000 R 26 (k0) = 00000000 R3 (v1) = 00000000 R11 (t3) = 00000000 R19 (s3) = 00000000 R 27 (k1) = 00000000 R4 (a0) = 00000019 R12 (t4) = fffffff1 R20 (s4) = 00000000 R 28 ( gp) = 10008000 R5 (a1) = 7fffebc4 R13 (t5) = 00000000 R21 (s5) = 00000000 R 29 (sp) = 7fffebc0 R6 (a2) = 7fffebc8 R14 (t6) = 00000000 R22 (s6) = 00000000 R 30 (s8) = 00000000 R7 (a3) = 00000000 R15 (t7) = 00000000 R23 (s7) = 00000000 R 31 (ra ) = 00400018 Double Floating Point Registers FP0 = 0.000000 FP8 = 0.000000 FP16 = 0.000000 F P24 = 0.000000 FP2 = 0.000000 FP10 = 0.000000 FP18 = 0.000000 F P26 = 0.000000 FP4 = 0.000000 FP12 = 0.000000 FP20 = 0.000000 F P28 = 0.000000 FP6 = 0.000000 FP14 = 0.000000 FP22 = 0.000000 F P30 = 0.000000 Single Floating Point Registers FP8 = 0.000000 FP16 = 0.000000 FP0 = 0.000000 F P24 = 0.000000 FP1 = 0.000000 FP9 = 0.000000 FP17 = 0.000000 F P25 = 0.000000 FP2 = 0.000000 FP10 = 0.000000 FP18 = 0.000000 F P26 = 0.000000 FP3 = 0.000000 FP11 = 0.000000 FP19 = 0.000000 F P27 = 0.000000 FP4 = 0.000000 FP12 = 0.000000 FP20 = 0.000000 F P28 = 0.000000 FP5 = 0.000000 FP13 = 0.000000 FP21 = 0.000000 F P29 = 0.000000 FP6 = 0.000000 FP14 = 0.000000 FP22 = 0.000000 F P30 = 0.000000 FP7 = 0.000000 FP15 = 0.000000 FP23 = 0.000000 F P31 = 0.000000 Next time... Wrapping-up chapter 2 Branching and Looping Alternative Architectures IA-32 CPSC330 CompOrg: Dr. Gerousis Instructions 23 CPSC330 CompOrg: Dr. Gerousis Instructions 24 6