Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 9: MIPS Instruction Set
Introduction to SPIM Simulator
MIPS Assembly Language CPSC 321 Computer Architecture Andreas Klappenecker.
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
SPIM and MIPS programming
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
Computer Architecture CSCE 350
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Function Continued
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
MIPS Assembly Language Programming
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
1 Computer Architecture MIPS Simulator and Assembly language.
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
ECE 0142 Recitation #5.
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
Appendix A: MIPS Assembly Language. Instruction Format R-type I-type J-type.
1 Lecture 6: Compilers, the SPIM Simulator Today’s topics:  SPIM simulator  The compilation process Additional TA hours: Liqun Cheng, legion at.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
Procedure Basics Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Procedure Support From previous study of high-level languages,
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
Lecture 161 Lets examine a SPIM program in detail. io.asm This program is a simple routine which demonstrates input/output using assembly code. SPIM.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Integers/Characters Input/Output Integers and Characters Input/Output System Calls. syscall Trap Handler Services for Integers and Characters Read Integer,
3-Apr-2006cse spim © 2006 DW Johnson and University of Washington1 SPIM simulator CSE 410, Spring 2006 Computer Systems
MIPS Architecture Topics –What resources MIPS assembly manipulates –CPU (Central Processing Unit) –ALU (Arithmetic & Logical Unit), Registers –Memory –I/O.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS Architecture Topics –What resources MIPS assembly manipulates –CPU (Central Processing Unit) –ALU (Arithmetic & Logical Unit), Registers –Memory –I/O.
CS 312 Computer Architecture & Organization
Function Calls in Assembly MIPS R3000 Language (extensive use of stack) Updated 7/11/2013.
Computer Architecture & Operations I
MIPS Assembly Language Programming
Lecture 6: Assembly Programs
Introduction to Lab #1 José Nelson Amaral.
Lecture 7: MARS, Computer Arithmetic
Integers/Characters Input/Output
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Assembly Programming using MIPS R3000 CPU
Instructions - Type and Format
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Lecture 4: MIPS Instruction Set
Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,
The University of Adelaide, School of Computer Science
Lecture 7: Examples, MARS, Arithmetic
MIPS function continued
Компьютерийн зохион байгуулалт, ассемблер CS201
MIPS Functions.
COMS 361 Computer Organization
COMS 361 Computer Organization
Assembly Programming using MIPS R3000 CPU
Program Assembly.
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
MIPS Functions.
Introduction to SPIM Simulator
Presentation transcript:

Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1

2 SPIM SPIM is a simulator that reads in an assembly program and models its behavior on a MIPS processor Note that a “MIPS add instruction” will eventually be converted to an add instruction for the host computer’s architecture – this translation happens under the hood To simplify the programmer’s task, it accepts pseudo-instructions, large constants, constants in decimal/hex formats, labels, etc. The simulator allows us to inspect register/memory values to confirm that our program is behaving correctly

3 Example This simple program (similar to what we’ve written in class) will run on SPIM (a “main” label is introduced so SPIM knows where to start) main: addi $t0, $zero, 5 addi $t1, $zero, 7 add $t2, $t0, $t1 If we inspect the contents of $t2, we’ll find the number 12

4 User Interface main: addi $t0, $zero, 5 addi $t1, $zero, 7 add $t2, $t0, $t1 File add.s > spim (spim) read “add.s” (spim) run (spim) print $10 Reg 10 = 0x c (12) (spim) reinitialize (spim) read “add.s” (spim) step (spim) print $8 Reg 8 = 0x (5) (spim) print $9 Reg 9 = 0x (0) (spim) step (spim) print $9 Reg 9 = 0x (7) (spim) exit

5 Directives.text.globl main main: addi $t0, $zero, 5 addi $t1, $zero, 7 add $t2, $t0, $t1 … jal swap_proc jr $ra.globl swap_proc swap_proc: … File add.s Stack Dynamic data (heap) Static data (globals) Text (instructions) This function is visible to other files

6 Directives.data.word 5.word 7.byte 25.asciiz “the answer is”.text.globl main main: lw $t0, 0($gp) lw $t1, 4($gp) add $t2, $t0, $t1 … jal swap_proc jr $ra File add.s Stack Dynamic data (heap) Static data (globals) Text (instructions)

7 Labels.data in1.word 5 in2.word 7 c1.byte 25 str.asciiz “the answer is”.text.globl main main: lw $t0, in1 lw $t1, in2 add $t2, $t0, $t1 … jal swap_proc jr $ra File add.s Stack Dynamic data (heap) Static data (globals) Text (instructions)

8 Endian-ness Two major formats for transferring values between registers and memory Memory: low address 45 7b 87 7f high address Little-endian register: the first byte read goes in the low end of the register Register: 7f 87 7b 45 Most-significant bit Least-significant bit Big-endian register: the first byte read goes in the big end of the register Register: 45 7b 87 7f Most-significant bit Least-significant bit SPIM operates with both byte orders depending the byte order of the underlying machine that runs the simulator (e.g. 80x86 is little endian; Sun is big endian)

9 System Calls SPIM provides some OS services: most useful are operations for I/O: read, write, file open, file close The arguments for the syscall are placed in $a0-$a3 The type of syscall is identified by placing the appropriate number in $v0 – 1 for print_int, 4 for print_string, 5 for read_int, etc. $v0 is also used for the syscall’s return value

10 Example Print Routine.data str:.asciiz “the answer is ”.text li $v0, 4 # load immediate; 4 is the code for print_string la $a0, str # the print_string syscall expects the string # address as the argument; la is the instruction # to load the address of the operand (str) syscall # SPIM will now invoke syscall-4 li $v0, 1 # syscall-1 corresponds to print_int li $a0, 5 # print_int expects the integer as its argument syscall # SPIM will now invoke syscall-1

11 Example Write an assembly program to prompt the user for two numbers and print the sum of the two numbers

12 Example.text.data.globl main str1:.asciiz “Enter 2 numbers:” main: str2:.asciiz “The sum is ” li $v0, 4 la $a0, str1 syscall li $v0, 5 syscall add $t0, $v0, $zero li $v0, 5 syscall add $t1, $v0, $zero li $v0, 4 la $a0, str2 syscall li $v0, 1 add $a0, $t1, $t0 syscall