SPIM Instruction Set

Similar documents
MIPS Reference Guide

MIPS Instruction Format

MIPS Assembly Language

Computer Architecture. The Language of the Machine

MIPS Instruction Reference

TSK3000A - Generic Instructions

MIPS Instruction Set

F. Appendix 6 MIPS Instruction Reference

Computer Systems and Architecture

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

CSc 256 Midterm (green) Fall 2018

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

Examples of branch instructions

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

CSc 256 Midterm 2 Spring 2012

CSc 256 Midterm 2 Fall 2011

MIPS Architecture and Assembly Language Overview

MIPS Assembly Language. Today s Lecture

The MIPS R2000 Instruction Set

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

The MIPS Instruction Set Architecture

Flow of Control -- Conditional branch instructions

Adventures in Assembly Land

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

MIPS%Assembly% E155%

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

Computer Architecture. MIPS Instruction Set Architecture

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

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

Reduced Instruction Set Computer (RISC)

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

Q1: /30 Q2: /25 Q3: /45. Total: /100

MIPS Assembly Language Programming

QtSPIM and MARS : MIPS Simulators

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

Introduction to MIPS Processor

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

Reduced Instruction Set Computer (RISC)

Mips Code Examples Peter Rounce

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

Week 10: Assembly Programming

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

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

COMP2421 COMPUTER ORGANZATION. Lab 3

CSc 256 Final Fall 2016

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

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

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

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

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

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

MIPS Assembly Language Guide

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

USING A SIMULATOR. QUICK INTRODUCTION From various sources For cs470

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

Lec 10: Assembler. Announcements

Programming the processor

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

SPIM S20: A MIPS R2000 Simulator

ece4750-parc-isa.txt

Compiling Techniques

M2 Instruction Set Architecture

ECE 15B Computer Organization Spring 2010

CS 61c: Great Ideas in Computer Architecture

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

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

CPS311 - COMPUTER ORGANIZATION. A bit of history

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

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

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

Control Instructions

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

INSTRUCTION SET COMPARISONS

Project Part A: Single Cycle Processor

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

CSc 256 Midterm 1 Fall 2011

Arithmetic for Computers

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

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

CS 4200/5200 Computer Architecture I

Assembly Programming

Chapter 2A Instructions: Language of the Computer

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

CSc 256 Final Spring 2011

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

Exam in Computer Engineering

Course Administration

Chapter loop: lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $v1, $zero, loop

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 9 December 2015

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

Fundamentals of Computer Systems

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

ece4750-tinyrv-isa.txt

MIPS Functions and the Runtime Stack

CS153: Compilers Lecture 2: Assembly

Concocting an Instruction Set

Transcription:

SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large number of pseudoinstructions that correspond to one or more equivalent MIPS instructions. There are also a small number of system call commands used to interface with the console window of the SPIM simulator. Finally, SPIM renames registers according to commonly used conventions in order to facilitate the readability of programs. Instructions and PseudoInstructions The following is an abbreviated list of MIPS instructions and SPIM pseudoinstructions. This list is not complete. Notably missing are all Floating Point and coprocessor instructions. - Indicates an actual MIPS instruction. Others are SPIM pseudoinstructions. Instruction Function add Rd, Rs, Rt Rd = Rs + Rt (signed) addu Rd, Rs, Rt Rd = Rs + Rt (unsigned) addi Rd, Rs, Imm Rd = Rs + Imm (signed) sub Rd, Rs, Rt Rd = Rs - Rt (signed) subu Rd, Rs, Rt Rd = Rs - Rt (unsigned) div Rs, Rt lo = Rs/Rt, hi = Rs mod Rt (integer division, signed) divu Rs, Rt lo = Rs/Rt, hi = Rs mod Rt (integer division, unsigned) div Rd, Rs, Rt Rd = Rs/Rt (integer division, signed) divu Rd, Rs, Rt Rd = Rs/Rt (integer division, unsigned) rem Rd, Rs, Rt Rd = Rs mod Rt (signed) remu Rd, Rs, Rt Rd = Rs mod Rt (unsigned) mul Rd, Rs, Rt Rd = Rs * Rt (signed) mult Rs, Rt hi, lo = Rs * Rt (signed, hi = high 32 bits, lo = low 32 bits) multu Rd, Rs hi, lo = Rs * Rt (unsigned, hi = high 32 bits, lo = low 32 bits) and Rd, Rs, Rt Rd = Rs Rt andi Rd, Rs, Imm Rd = Rs Imm neg Rd, Rs Rd = -(Rs) nor Rd, Rs, Rt Rd = (Rs + Rt) not Rd, Rs Rd = (Rs) or Rd, Rs, Rt Rd = Rs + Rt ori Rd, Rs, Imm Rd = Rs + Imm xor Rd, Rs, Rt Rd = Rs Rt xori Rd, Rs, Imm Rd = Rs Imm

sll Rd, Rt, Sa Rd = Rt left shifted by Sa bits sllv Rd, Rs, Rt Rd = Rt left shifted by Rs bits srl Rd, Rs, Sa Rd = Rt right shifted by Sa bits srlv Rd, Rs, Rt Rd = Rt right shifted by Rs bits move Rd, Rs Rd = Rs mfhi Rd Rd = hi mflo Rd Rd = lo li Rd, Imm Rd = Imm lui Rt, Imm Rt[31:16] = Imm, Rt[15:0] = 0 lb Rt, Address(Rs) Rt = byte at M[Address + Rs] (sign extended) sb Rt, Address(Rs) Byte at M[Address + Rs] = Rt (sign extended) lw Rt, Address(Rs) Rt = word at M[Address + Rs] sw Rt, Address(Rs) Word at M[Address + Rs] = Rt slt Rd, Rs, Rt Rd = 1 if Rs < Rt, Rd = 0 if Rs Rt (signed) slti Rd, Rs, Imm Rd = 1 if Rs < Imm, Rd = 0 if Rs Imm (signed) sltu Rd, Rs, Rt Rd = 1 if Rs < Rt, Rd = 0 if Rs Rt (unsigned) beq Rs, Rt, Label Branch to Label if Rs == Rt beqz Rs, Label Branch to Label if Rs == 0 bge Rs, Rt, Label Branch to Label if Rs Rt (signed) bgez Rs, Label Branch to Label if Rs 0 (signed) bgezal Rs, Label Branch to Label and Link if Rs Rt (signed) bgt Rs, Rt, Label Branch to Label if Rs > Rt (signed) bgtu Rs, Rt, Label Branch to Label if Rs > Rt (unsigned) bgtz Rs, Label Branch to Label if Rs > 0 (signed) ble Rs, Rt, Label Branch to Label if Rs Rt (signed) bleu Rs, Rt, Label Branch to Label if Rs Rt (unsigned) blez Rs, Label Branch to Label if Rs 0 (signed) bgezal Rs, Label Branch to Label and Link if Rs 0 (signed) bltzal Rs, Label Branch to Label and Link if Rs < 0 (signed) blt Rs, Rt, Label Branch to Label if Rs < Rt (signed) bltu Rs, Rt, Label Branch to Label if Rs < Rt (unsigned) bltz Rs, Label Branch to Label if Rs < 0 (signed) bne Rs, Rt, Label Branch to Label if Rs Rt bnez Rs, Label Branch to Label if Rs 0 j Label Jump to Label unconditionally jal Label Jump to Label and link unconditionally jr Rs Jump to location in Rs unconditionally jalr Label Jump to location in Rs and link unconditionally

Registers By convention, many MIPS registers have special purpose uses. To help clarify this, SPIM defines aliases for each register that represent its purpose. The following table lists these aliases and the commonly accepted uses for the registers. Register Number Usage zero 0 Constant 0 at 1 Reserved for assembler v0 2 Used for return values from function calls. v1 3 a0 4 Used to pass arguments to procedures and functions. a1 5 a2 6 a3 7 t0 8 Temporary (Caller-saved, need not be saved by called procedure) t1 9 t2 10 t3 11 t4 12 t5 13 t6 14 t7 15 s0 16 Saved temporary (Callee-saved, called procedure must save and restore) s1 17 s2 18 s3 19 s4 20 s5 21 s6 22 s7 23 t8 24 Temporary (Caller-saved, need not be saved by called procedure) t9 25 k0 26 Reserved for OS kernel k1 27 gp 28 Pointer to global area sp 29 Stack pointer fp 30 Frame pointer ra 31 Return address for function calls. System Calls In order to perform I/O with the console, SPIM provides a small library of system calls. In general, system calls are set up by placing a system call in register $v0, and any

arguments in register $a0 and $a1. Returned values are placed in register $v0. See the table and the example program below for usage. Example Program # This program takes input from the user and echoes it back Service System Call Code Arguments Result Print_int 1 $a0 = integer Print_float 2 $f12 = float Print_double 3 $f12 = double Print_string 4 $a0 = string Read_int 5 Integer (in $v0) Read_float 6 Float (in $f0) Read_double 7 Double (in $f0) Read_string 8 $a0 = buffer, $a1 = length Sbrk 9 $a0 = amount Address (in $v0) exit 10.data # Constant strings to be output to the terminal promptint:.asciiz "Please input an integer: " resultint:.asciiz "Next integer is: " linefeed:.asciiz "\n" enterkey:.asciiz "Press any key to end program.".text main: # prompt for an integer la $a0,promptint # point $a0 to prompt string # print the prompt # get an integer from the user li $v0,5 # code for read_int #get int from user --> returned in $v0 move $t0,$v0 # move the resulting int to $t0 # compute the next integer addi $t0, $t0, 1 # t0 <-- t0 + 1 # print out text for the result li $v0,4 #code for print_string la $a0,resultint # point $a0 to result string # print the result string # print out the result li $v0,1 # code for print_int move $a0,$t0 # put result in $a0 # print out the result # print out a line feed la $a0,linefeed # point $a0 to linefeed string # print linefeed

# wait for the enter key to be pressed to end program la $a0,enterkey # point $a0 to enterkey string # print enterkey # wait for input by getting an integer from the user (integer is ignored) li $v0,5 # code for read_int #get int from user --> returned in $v0 # All done, thank you! li $v0,10 # code for exit # exit program