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

Slides:



Advertisements
Similar presentations
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Advertisements

Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 – Introduction to MIPS Procedures I If cars broadcast their speeds to.
Digital System Design Using Verilog
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
Introduction to SPIM Simulator
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.
Computer Organization. This module surveys the physical resources of a computer system. –Basic components CPUMemoryBus I/O devices –CPU structure Registers.
MIPS Architecture CPSC 321 Computer Architecture Andreas Klappenecker.
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,
MicroComputer Engineering IntroLab1 page 1 Introduction Lab1  A crash course in assembler programming  Learn how a processor works!  Decode a coded.
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture.
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.
Computer Architecture & Operations I
MIPS Assembly.
MIPS Instruction Set Advantages
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
ECE3055 Computer Architecture and Operating Systems MIPS ISA
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Assembly Programming using MIPS R3000 CPU
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
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
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Assembly Programming using MIPS R3000 CPU
Computer Architecture
Introduction Lab1 A crash course in assembler programming
MIPS R3000 Subroutine Calls and Stack
Presentation transcript:

Introduction to SPIM Simulator

2 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

3 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

4 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~$s716~23 saved temporary (preserved across call) $t8~$t924~25 temporary (not preserved across call) $k0~$k126~27 reserved for OS kernel $gp 28 pointer to global area $sp 29 stack pointer $fp 30 frame pointer $ra 31 return address

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

6 Load, Store and Move Instructions lird, immrd  imm lard, labelrd  label lwrd, imm(rs) rd  imm(rs) swrd, imm(rs) imm(rs)  rd moverd, rsrd  rs

7 Arithmetic and Logical Instructions addrd, rs, rtrd  rs + rt subrd, rs, rtrd  rs – rt mulrd, rs, rtrd  rs * rt divrd, rs, rtrd  rs / rt remrd, rs, rtrd  rs % rt negrd, rsrd  - rs andrd, rs, rtrd  rs & rt orrd, rs, rtrd  rs | rt notrd, rsrd  ! rs

8 Branch and Jump Instructions beqrs, rt, labelbranch to label if rs == rt bners, rt, labelbranch to label if rs != rt bgtrs, rt, labelbranch to label if rs > rt bgers, rt, labelbranch to label if rs >= rt bltrs, rt, labelbranch to label if rs < rt blers, rt, labelbranch to label if rs <= rt blabelbranch to label jallabeljump to label, save the next address in $ra jrrsjump to the address in rs

9 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

10 Assembler Syntax Labels are declared by putting them at the beginning of a line followed by a colon Strings are enclosed in doublequotes ( “ ). Special characters in strings: newline \n, tab \t, quote \ “ Numbers are base 10 by default. If they are preceded by 0x, they are interpreted as hexadecimal

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

12 Assembler Directives.globl symDeclare that label sym is global.text Subsequent items are put in the user text segment. These items may only be instructions. If the optional addr is present, the items are stored starting at address addr.data Subsequent items are stored in the data segment. If the optional addr is present, the items are stored starting at address addr.word w1, …, wnStore the n 32-bit values in successive memory words.asciiz strStore the string str in memory and null-terminate it

13 Procedure Call Convention … Argument 6 Argument 5 $a3 $a2 $a1 $a0 $ra $fp Saved registers Local variables $fp $sp Higher address Lower address

14 Frame Size The minimum frame size is 24 bytes. It can hold $a0~$a3, $ra, and $fp Frame size must be double word aligned

15 Caller Pass arguments. The first four arguments are passed in $a0~$a3. The remaining arguments are passed in frame Save caller-saved registers $t0~$t9 Execute a jal instruction, which jumps to the callee ’ s first instruction and saves the return address in $ra

16 Entry of Callee Allocate the frame by subtracting the frame size from the stack pointer Save callee-saved registers. $s0~$s7, $fp, and $ra Establish the frame pointer by adding the frame size minus four to $sp and storing the sum in $fp

17 Exit of Callee If the callee is a function that returns a value, place the returned value in $v0 Restore all callee-saved registers that were saved upon procedure entry Pop the stack frame by adding the frame size to $sp Return by jumping to the address in $ra

18 An Example int main() { int m; m = fact(10); } int fact(int n) { int m; if (n <= 1) return 1; else { m = fact(n – 1); return (n * m); } }

19 An Example $a3 $a2 $a1 $a0 $ra $fp m $fp $sp

20 An Example.text.globl main main: li$t0, 32 sub$sp, $sp, $t0 sw$ra, 12($sp) sw$fp, 8($sp) li$t0, 28 add$fp, $sp, $t0 li$a0, 10 jalfact lw $ra, 12($sp) lw$fp, 8($sp) li$t0, 32 add$sp, $sp, $t0 jr$ra.text fact:li$t0, 32 sub$sp, $sp, $t0 sw$ra, 12($sp) sw$fp, 8($sp) li$t0, 28 add$fp, $sp, $t0

21 An Example sw$a0, -12($fp) lw$t0, -12($fp) bgt$t0, $zero, L1 li$v0, 1 bL2 L1:lw$t0, -12($fp) li$t1, 1 sub$t0, $t0, $t1 move$a0, $t0 jalfact sw$v0, -24($fp) lw$t0, -12($fp) lw$t1, -24($fp) mul$t0, $t0, $t1 move$v0, $t0 L2:lw $ra, 12($sp) lw$fp, 8($sp) li$t0, 32 add$sp, $sp, $t0 jr$ra

22 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

23 System Call Code Service System call code Arguments Result print_int $v0=1 $a0=interger print_string $v0=4 $a0=string read_int $v0=5 integer in $v0 exit $v0=10

24 An Example.data str:.asciiz“the answer = ”.text la$a0, str li$v0, 4 syscall li$a0, 5 li$v0, 1 syscall “the answer = 5”

25 An Example int main() { int m; print_string(“The factorial of 10 is ”); m = fact(10); print_int(m); }

26 An Example.text.globl main main:li$t0, 32 sub$sp, $sp, $t0 sw$ra, 12($sp) sw$fp, 8($sp) li$t0, 28 add$fp, $sp, $t0 la$a0, LC li$v0, 4 syscall li$a0, 10 jalfact sw$v0, -24($fp) lw$a0, -24($fp) li$v0, 1 syscall lw $ra, 12($sp) lw$fp, 8($sp) li$t0, 32 add$sp, $sp, $t0 jr$ra.data LC:.asciiz“The factorial of 10 is ”