USING A SIMULATOR. QUICK INTRODUCTION From various sources For cs470

Similar documents
Programming with QtSpim: A User s Manual

QtSPIM and MARS : MIPS Simulators

SPIM Instruction Set

MIPS and QTSPIM Recap. MIPS Architecture. Cptr280. Dr Curtis Nelson. Cptr280, Autumn

MIPS Processor Overview

MIPS Assembly Language

Compiling Techniques

Introduction to MIPS Processor

COMP2421 COMPUTER ORGANZATION. Lab 3

MIPS Architecture and Assembly Language Overview

MIPS Reference Guide

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

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

Examples of branch instructions

Adventures in Assembly Land

CSc 256 Midterm (green) Fall 2018

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

Assignment 1: Pipelining Implementation at SPIM Simulator

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

CDA3100 Midterm Exam, Summer 2013

MIPS function continued

Flow of Control -- Conditional branch instructions

Computer Architecture. The Language of the Machine

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

MIPS Assembly Language. Today s Lecture

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

Field 6-Bit Op Code rs Field rt Field 16-bit Immediate field

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

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

MIPS Instruction Format

LAB B Translating Code to Assembly

MIPS Assembly Language Programming

MIPS Assembly Programming

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

CPSC 330 Computer Organization

CSc 256 Midterm 1 Fall 2011

CS 61C: Great Ideas in Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading)

UCB CS61C : Machine Structures

CENG3420 Lab 1-1: MIPS assembly language programing

Computer Systems and Architecture

F. Appendix 6 MIPS Instruction Reference

MIPS Instruction Reference

SPIM S20: A MIPS R2000 Simulator

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

Review. Lecture 18 Running a Program I aka Compiling, Assembling, Linking, Loading

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

HW2 solutions You did this for Lab sbn temp, temp,.+1 # temp = 0; sbn temp, b,.+1 # temp = -b; sbn a, temp,.+1 # a = a (-b) = a + b;

Course Administration

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

CS152 Computer Architecture and Engineering

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

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

Mark Redekopp, All rights reserved. EE 352 Unit 4. Assembly and the MARS Simulator Control Flow (Branch Instructions)

UC Berkeley CS61C : Machine Structures

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

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

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.

CS3350B Computer Architecture MIPS Introduction

ECE 15B COMPUTER ORGANIZATION

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Computer Architecture. MIPS Instruction Set Architecture

CS3350B Computer Architecture

CS 61C: Great Ideas in Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading)

The MIPS Instruction Set Architecture

Lecture 6 Decision + Shift + I/O

COMP MIPS instructions 2 Feb. 8, f = g + h i;

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Assembler

EECS 322 The SPIM simulator

CSc 256 Midterm 2 Fall 2011

MIPS (SPIM) Assembler Syntax

MIPS Assembly Language Programming

The MIPS R2000 Instruction Set

CSc 256 Midterm 2 Spring 2012

ECE 30 Introduction to Computer Engineering

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

CS 4200/5200 Computer Architecture I

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Points available Your marks Total 100

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

Control Instructions

COMPUTER ORGANIZATION AND DESIGN

Reduced Instruction Set Computer (RISC)

Machine Instructions - II. Hwansoo Han

MIPS Assembly Language Guide

Lecture 7: Examples, MARS, Arithmetic

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Chapter 2A Instructions: Language of the Computer

MIPS Instruction Set

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

MIPS Assembly (Functions)

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

Reduced Instruction Set Computer (RISC)

MIPS Assembly Language Programming

Midterm. CS64 Spring Midterm Exam

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

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

Chapter Two MIPS Arithmetic

Transcription:

USING A SIMULATOR QUICK INTRODUCTION From various sources For cs470 INTRODUCTION MARS INTERFACE SIMULATOR USAGE MIPS ASSEMBLER LANGUAGE PROGRAM EXAMPLE

Introduction MARS IDE A simulator for the MIPS processor Pete Sanderson, Ken Vollmar Similar to SPIM discussed in Appendix A Functions Text editor to writing code Loads and executes MIPS assembly language files (.asm or.s) immediately Debugger (breakpoints, single-stepping) Provides Console for input/output

INTERFACE Registers window values of all registers Int/FP Text segment window user and kernel instructions Addresses, code in binary and assembly Data segment window User data, stack, kernel data Messages window Registers Text Segment Data Segment messages (include error messages) Console interface Input/output

Simulator Settings

Execute Program

Program Text and Data segments

Set a break point

Simulator Usage The icon runs the program to completion. Using this icon, you should observe the yellow highlight showing the program s progress and the values of the Fibonacci sequence appearing in the Data Segment display. The icon resets the program and simulator to initial values. Memory contents are those specified within the program, and register contents are generally zero. The icon is single-step. Its complement is, single-step backwards (undoes each operation).

MIPS Assembly Layout Program Layout.text #code section.globl main #starting point: must be global main: # user program code.data #data section label:.data_type list_of_data #data loc + data type + data.text #code section label: #function label #user functions

MIPS Assembler Directives Data Types.word,.half - 32/16 bit integer.byte - 8 bit integer (similar to char type in C).ascii,.asciiz - string (asciiz is null terminated) Strings are enclosed in double-quotas( ) Special characters in strings follow the C convention newline(\n), tab(\t), quote(\ ).double,.float - floating point Other Directives.text - Indicates that following items are stored in the user text segment.data - Indicates that following data items are stored in the data segment.globl sym - Declare that symbol sym is global and can be referenced from other files

SPIM Program Example I #sample example 'load, add, store.text # text section.globl main # call main by SPIM main: la $t0, value # load address value into $t0 lw $t1, 0($t0) # load word 0(value) into $t1 lw $t2, 4($t0) # load word 4(value) into $t2 add $t3, $t1, $t2 # add two numbers into $t3 sw $t3, 8($t0) # store word $t3 into 8($t0) li $v0, 10 # 10 exit syscall. syscall # do the syscall..data # data section value:.word 10, 20, 0 # data for addition #this ends the program.

Common Pseudoinstructions Pseudoinstruction Translation mov $rt, $rs add $rt, $rs, $0 li $rs, small li $rs, big la $rs, big lw $rt, big($rs) addi $rs, $0, small lui $rs, upper( big ) ori $rs, $rs, lower( big ) lui $rs, upper( big ) ori $rs, $rs, lower( big ) lui $t0, upper( big ) ori $t0, $t0, lower( big ) add $t0, $rs, $t0 lw $rt, 0($t0)

SPIM System Calls System Calls (syscall): OS services Load system call code into register $v0 Load arguments into registers $a0 After call, return value (if any) is in register $v0 Frequently used system calls Service Code($v0) Arg Result Print_int 1 $a0 (int to print) Print_string 4 $a0 (addr of string) Read_int 5 Int in $v0 Read_string 8 $a0: addr, $a1:bytes

SPIM Program Example II #sample example 'system call'.text.globl main main: la $t0, value li $v0, 5 #get input syscall sw $v0, 0($t0) li $v0, 5 #get input syscall sw $v0, 4($t0) lw $t1, 0($t0) lw $t2, 4($t0) add $t3, $t1, $t2 sw $t3, 8($t0) li $v0, 4 #print message la $a0, msg1 syscall li $v0, 1 #print result move $a0, $t3 syscall.data value:.word 0, 0, 0 msg1:.asciiz "Result = "

Psuedoinstructions Name instruction syntax Real instruction translation meaning Move move $rt,$rs addi $rt,$rs,0 R[rt]=R[rs] Clear clear $rt add $rt,$zero,$zero R[rt]=0 Load Address la $rd, LabelAddr lui $rd, LabelAddr[31:16]; ori $rd,$rd, LabelAddr[15:0] $rd = Label Address Load Immediate li $rd, IMMED[31:0] lui $rd, IMMED[31:16]; ori $rd,$rd, IMMED[15:0] $rd = 32 bit Immediate value Branch unconditionally b Label beq $zero,$zero,label if(r[rs]==r[rt]) PC=Label Branch and link bal $rs,label bgezal $zero,label if(r[rs]>=0) PC=Label Branch if greater than Branch if less than Branch if greater than or equal Branch if less than or equal Branch if greater than unsigned bgt $rs,$rt,label blt $rs,$rt,label bge $rs,$rt,label ble $rs,$rt,label bgtu $rs,$rt,label slt $at,$rt,$rs; bne $at,$zero,label slt $at,$rs,$rt; bne $at,$zero,label slt $at,$rs,$rt; beq $at,$zero,label slt $at,$rt,$rs; beq $at,$zero,label if(r[rs]>r[rt]) PC=Label if(r[rs]<r[rt]) PC=Label if(r[rs]>=r[rt]) PC=Label if(r[rs]<=r[rt]) PC=Label if(r[rs]>r[rt]) PC=Label Branch if greater than zero bgtz $rs,$rt,label if(r[rs]>0) PC=Label Multiplies and returns only first 32 bits mul $d, $s, $t mult $s, $t; mflo $d $d = $s * $t Divides and returns quotient div $d, $s, $t div $s, $t; mflo $d $d = $s / $t Divides and returns remainder rem $d, $s, $t div $s, $t; mfhi $d $d = $s % $t