Introduction to SPIM Simulator

Slides:



Advertisements
Similar presentations
Introduction to SPIM Simulator. 2 SPIM Simulator SPIM is a software simulator that runs programs written for MIPS R2000/R3000 processors SPIM ’ s name.
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Lecture 9: MIPS Instruction Set
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
ELEN 468 Advanced Logic Design
CS3350B Computer Architecture Winter 2015 Lecture 4
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
1 Computer Architecture MIPS Simulator and Assembly language.
Procedure call frame: Hold values passed to a procedure as arguments
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
CS 536 Spring Code generation I Lecture 20.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Intro to Computer Architecture
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
RISC Concepts, MIPS ISA and the Mini–MIPS project
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )
MIPS R3000 Subroutine Calls and Stack Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Computer Engineering IntroLab1 page 1 Beginners explanation on how a processor works! The labs will teach you the truth.
1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang.
R3000/001 Assembly Programming using MIPS R3000 CPU R3000 CPU Chip Manufactured by IDT What is MIPS R3000 Processor? A 32-bit RISC CPU developed by MIPS.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
MicroComputer Engineering IntroLab1 page 1 Introduction Lab1  A crash course in assembler programming  Learn how a processor works!  Decode a coded.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
MIPS Lab CMPE 142 – Operating Systems. MIPS Simulator First Time Startup Setting Options.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Computer Architecture & Operations I
MIPS Assembly.
Computer Architecture Instruction Set Architecture
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Assembly Programming using MIPS R3000 CPU
Instructions - Type and Format
Application Binary Interface (ABI)
MIPS Instructions.
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
Instruction encoding The ISA defines Format = Encoding
Computer Instructions
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
Assembly Programming using MIPS R3000 CPU
Instruction encoding The ISA defines Format = Encoding
Computer Architecture
Introduction Lab1 A crash course in assembler programming
MIPS Arithmetic and Logic Instructions
MIPS R3000 Subroutine Calls and Stack
Presentation transcript:

Introduction to SPIM Simulator

SPIM Simulator SPIM is a software simulator that runs programs written for MIPS R2000/R3000 processors SPIM’s name is just MIPS spelled backwards SPIM can read and immediately execute MIPS assembly language files or MIPS executable files SPIM contains a debugger and provides a few operating system-like services

MIPS Processors MIPS is a load-store architecture, which means that only load and store instructions access memory Computation instructions operate only on values in registers

MIPS Registers Name Number Usage $zero 0 constant 0 $at 1 reserved for assembler $v0~$v1 2~3 return value of a function $a0~$a3 4~7 arguments $t0~$t7 8~15 temporary (not preserved across call) $s0~$s7 16~23 saved temporary (preserved across call) $t8~$t9 24~25 temporary (not preserved across call) $k0~$k1 26~27 reserved for OS kernel $gp 28 pointer to global area $sp 29 stack pointer $fp 30 frame pointer $ra 31 return address

Addressing Modes Format Address computation register contents of register imm immediate imm(register) contents of (immediate + contents of register) label address of label

Load, Store and Move Instructions li rd, imm rd  imm la rd, label rd  label lw rd, imm(rs) rd  imm(rs) sw rd, imm(rs) imm(rs)  rd move rd, rs rd  rs

Arithmetic Instructions add rd, rs, rt rd  rs + rt sub rd, rs, rt rd  rs – rt mul rd, rs, rt rd  rs * rt div rd, rs, rt rd  rs / rt rem rd, rs, rt rd  rs % rt neg rd, rs rd  - rs

Branch Instructions beq rs, rt, label branch to label if rs == rt bne rs, rt, label branch to label if rs != rt bgt rs, rt, label branch to label if rs > rt bge rs, rt, label branch to label if rs >= rt blt rs, rt, label branch to label if rs < rt ble rs, rt, label branch to label if rs <= rt b label branch to label

Assembler Syntax Comments in assembler files begin with a sharp sign (#) and continue to the end of the line Identifiers are a sequence of alphanumeric characters, underbars (_), and dots (.) that do not begin with a number Opcodes are reserved words that cannot be used as identifiers

Assembler Syntax Labels are declared by putting them at the beginning of a line followed by a colon Numbers are base 10 by default. If they are preceded by 0x, they are interpreted as hexadecimal

Memory Layout 7ffffff Stack segment Dynamic data Data segment Static data 10000000 Text segment 400000 Reserved

Assembler Directives .text Subsequent items are put in the user text segment. These items may only be instructions. .data Subsequent items are stored in the data segment. .word n Store the 32-bit value n in current memory word

System Calls SPIM provides a small set of operating system-like services through the system call (syscall) instruction To request a service, a program loads the system call code into register $v0 and arguments into registers $a0~$a3 System calls that return values put their results in register $v0

System Call Code Service Code Arguments Result print_int $v0= 1 $a0=interger read_int $v0= 5 integer in $v0 exit $v0=10

An Example procedure SUM is declare N: integer; S: integer; I: integer; begin read N; if N < 0 then write -1; exit; else S := 0; end if; for I in 1..N loop S := S + I; end loop; write S; end;

An Example .data N: .word 0 S: I: .text main: li $v0, 5 syscall la $t0, N sw $v0, 0($t0) la $t0, n lw $t0, 0($t0) li $t1, 0 blt $t0, $t1, L1 b L2 L1: li $t0, 1 neg $t0, $t0 move $a0, $t0 li $v0, 1 syscall

An Example li $v0, 10 syscall b L3 L2: li $t0, 0 la $t1, S sw $t0, 0($t1) L3: li $t0, 1 la $t1, I la $t0, N lw $t0, 0($t0) L4: la $t1, I lw $t1, 0($t1) ble $t1, $t0, L5 b L6 L5: la $t1, S la $t2, I lw $t2, 0($t2) add $t1, $t1, $t2

An Example move $a0, $t0 la $t2, S li $v0, 1 sw $t1, 0($t2) syscall la $t1, I lw $t1, 0($t1) li $t2, 1 add $t1, $t1, $t2 la $t2, I sw $t1, 0($t2) b L4 L6: la $t0, S lw $t0, 0($t0) move $a0, $t0 li $v0, 1 syscall