SPIM and MIPS programming

Slides:



Advertisements
Similar presentations
Catch up on previous topics Summary and putting together first four classes.
Advertisements

Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
The University of Adelaide, School of Computer Science
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
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.
Chapter 2 Instructions: Language of the Computer
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Syscall in MIPS Xinhui Hu Yuan Wang.
MIPS Function Continued
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.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
ECE 0142 Recitation #5.
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
ECE 232 L7.Simul.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 7 MIPS Assembly.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
On Textbook CD: SPIM Jen-Chang Liu, Simulation of a virtual machine Virtual machine (simulator) Differences between SPIM and real MIPS? No delayed.
MIPS Instruction Set Advantages
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
Comp Sci vars & expns 1 Ch. 4 Variables and Expressions.
Ch2b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost.
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Instructions: Part the Last.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
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.
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.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
The SPIM Trap Handler Syscall Trap handler services String operations File operations Memory allocation Central Connecticut State University, MIPS Tutorial.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
CS 312 Computer Architecture & Organization
System Calls & Arithmetic
Computer Architecture & Operations I
MIPS Instruction Set Advantages
Introduction to Lab #1 José Nelson Amaral.
Integers/Characters Input/Output
Register Use Policy Conventions
Assembly Programming using MIPS R3000 CPU
MIPS I/O and Interrupt.
Instructions - Type and Format
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
SPIM Syscalls.
MPIS Instructions Functionalities of instructions Instruction format
Assembler Directives Example program: .data # DATA segment city: .asciiz “Seattle” .align 2 num: .word 2210, 2341, 26, 0x022ec,
MIPS Functions.
MIPS coding.
Компьютерийн зохион байгуулалт, ассемблер CS201
MIPS function continued
COMS 361 Computer Organization
COMS 361 Computer Organization
Assembly Programming using MIPS R3000 CPU
Generalities for Assembly Language
MIPS Assembly Language Programming Computer Architecture
9/27: Lecture Topics Memory Data transfer instructions
CS 286 Computer Architecture & Organization
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Introduction to SPIM Simulator
PROF. JOHN ABRAHAM UTRGV
Presentation transcript:

SPIM and MIPS programming

Review: Memory Organization Large single-dimension array A memory address is an index into the array Memory stores 8 bits in each address Registers store 32 bits of information For example: Li $t0, 0 lw $t0, 0($t1) Then $t0 will contain the data of the first four memory locations 6 5 4 3 2 1 8 bits of data

Review: Registers MIPS has 32 registers, each containing 32 bits Some registers are listed below $zero: constant 0 $at: reserved for the assembler $v0 - $v1: function results $a0 - $a3: function arguments $t0 - $t9: temporary $s0 - $s7: temporary

Arithmetic Instructions (1/2) Some instructions include: Add Subtract Multiply Divide Must break expression into simple operations use temporary registers ($t0 to $t9) to store intermediate results use load to insert a value into a variable use store to assign a value to a variable

Instructions Instruction Meaning add $s1, $s2, $s3 $s1 = $s2 + $s3 sub $s1, $s2, $s3 $s1 = $s2 – $s3 lw $s1, 100($s2) $s1 = Memory[$s2+100] sw $s1, 100($s2) Memory[$s2+100] = $s1

Global variables C program Assembly Program int variable = -42; .data variable: .word -42 int r1; r1: .space 4 .space allocates empty space in bytes .word allocates 4-byte value followed by the value to store

Assember Directives All assembler directives have names that begin with a period (`.'). Examples: .word w1 allocate a 4-byte word .half h1 allocate 2-bytes .byte b1 allocate a single byte .ascii “hello" allocate a sequence of bytes and store ASCII values .asciiz “hello" allocate a sequence of bytes and store ASCII values. terminate string with 0 byte (end of string) .float .double

Input/Output On real machines (including real MIPS computers), I/O is very complicated usually handled by operating system In SPIM, I/O is managed by system calls syscall instruction SPIM suspends simulation to perform I/O, then resumes simulation

System calls Systems calls are used to interact with the user To make a system call determine which service you want put service’s call code in register $v0 put arguments in registers $a0, $a1, etc. execute the syscall instruction results are in registers $v0, $v1

System calls

Input/Output: Numbers .data value: .space 4 .text main: li $v0, 5 #Syscall 5: read int syscall sw $v0, value #Number is in $v0 li $v0, 1 #Syscall 1: print int lw $t0, value mul $a0, $t0, $t0 #$a0 is what to print li $v0, 10 #Exit

Input/Output: strings .data msg: .asciiz "Type a string: " buff: .space 20 .text main: li $v0, 4 # print string la $a0, msg # $a0: address of string syscall li $v0, 8 # read string la $a0, buff # $a0: max length of buffer li $a1, 20 # $a1: max length of string li $v0, 4 la $a0, buff li $v0, 10 # exit