Implementing a Car Simulator in MIPS

Similar documents
Writing an Embedded Controller

Recitation 5: Recitation 5: MIPS Interrupts and Floating Point

Format. 10 multiple choice 8 points each. 1 short answer 20 points. Same basic principals as the midterm

CDA3100 Midterm Exam, Summer 2013

Points available Your marks Total 100

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

CS 61C, Midterm #2, Spring 1997 CS 61C. Spring 1997 Midterm #2. Professor Brian Harvey

Exceptions and Interrupts

EE 109 Unit 17 - Exceptions

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Common Problems on Homework

MIPS function continued

Lecture 6 Decision + Shift + I/O

9 Floating-Point. 9.1 Objectives. 9.2 Floating-Point Number Representation. Value = ± (1.F) 2 2 E Bias

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

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.

Introduction to MIPS Processor

CS152 Computer Architecture and Engineering

SPIM & MIPS Programming

MIPS%Assembly% E155%

Problem 3: Theoretical Questions: Complete the midterm exam taken from a previous year attached at the end of the assignment.

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

CSc 256 Midterm 1 Fall 2011

Patterson PII. Solutions

Systems Architecture I

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

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

ECE 30 Introduction to Computer Engineering

Assignment 1: Pipelining Implementation at SPIM Simulator

Midterm. CS64 Spring Midterm Exam

Introduction to Assembler Language Programming

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

CSc 256 Midterm (green) Fall 2018

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

Assembler. Lecture 8 CS301

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

MIPS Assembly Language Guide

ECE 473 Computer Architecture and Organization Project: Design of a Five Stage Pipelined MIPS-like Processor Project Team TWO Objectives

Written Homework 3. Floating-Point Example (1/2)

Computer Architecture Homework #1 Due: September 7, 2007 (F) (4 PM in ITT 305 mailbox or under my office door, ITT 313)

SPIM Instruction Set

MIPS Assembly (Functions)

CSCI 2321 (Computer Design), Spring 2018 Homework 3

CSc 256 Midterm 2 Spring 2012

Lecture 7: Examples, MARS, Arithmetic

This exam is worth 40 points, or 30% of your total course grade. The exam contains eight

Compiling Techniques

The MIPS R2000 Instruction Set

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

MIPS (SPIM) Assembler Syntax

MIPS Reference Guide

CSc 256 Midterm 2 Fall 2011

CSCI 402: Computer Architectures. Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI.

Arithmetic for Computers. Hwansoo Han

SPIM & MIPS. Department of Information and Management. Computer Organization and Structure 年 9 月 29 日星期 一

Chapter 2. Instructions:

Homework 4 - Solutions (Floating point representation, Performance, Recursion and Stacks) Maximum points: 80 points

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

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

Quick Review. lw $t0, 4($a0) Registers x Memory. $a0 is simply another name for register 4 $t0 is another name for register (green sheet)

CS 351 Exam 2 Mon. 11/2/2015

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

Programming with QtSpim: A User s Manual

MIPS Instruction Reference

QtSPIM and MARS : MIPS Simulators

Lecture 5: Procedure Calls

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Course Administration

University of California at Santa Barbara. ECE 154A Introduction to Computer Architecture. Quiz #1. October 30 th, Name (Last, First)

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

EE 109 Unit 15 Subroutines and Stacks

Lecture 5. Announcements: Today: Finish up functions in MIPS

ECE Exam I February 19 th, :00 pm 4:25pm

Computer Systems and Architecture

Computer Architecture. MIPS Instruction Set Architecture

instructions aligned is little-endian

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

CSSE 232 Computer Architecture I. I/O and Addressing

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

EE 361 University of Hawaii Fall

Topic Notes: MIPS Instruction Set Architecture

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage.

Functions in MIPS. Functions in MIPS 1

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

CS 2504 Intro Computer Organization Test 1

MIPS Coding Continued

CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

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

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Instruction Set Architectures (4)

MIPS Assembly Programming

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

F. Appendix 6 MIPS Instruction Reference

SPIM S20: A MIPS R2000 Simulator

MIPS Assembly Language

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

Lecture 7: MIPS Functions Part 2. Nested Function Calls. Lecture 7: Character and String Operations. SPIM Syscalls. Recursive Functions

Transcription:

1. This homework must be finished individually. 2. This assignment has been designated by the Department of Computer Science for assessment of certain expected outcomes for its degree programs, as required by our accreditation agencies, the University, and the State of Florida. Departmental policy does not permit a final grade of "C-" or better to be assigned unless the student has at earned a grade of "C-" or better on this assignment, regardless of performance on other work in the course. Implementing a Car Simulator in MIPS Your assignment is to write a MIPS program that will implement a car simulator. This simulator will maintain and display its current state every 10 seconds, update any state that constantly needs to be updated every 50ms, and respond to the user s input after each user command. The simulator must support the following commands: Help o Key h o Prints out a message showing the available commands Accelerate o Key a o Increases speed by 2 meters per second Decelerate o Key d o Decrease speed by 2 meters per second Add Passenger o Key p o Increase the number of passengers in the car by one o Can only do this when fully stopped Remove Passenger o Key r o Decrease the number of passengers in the car by one o Can only do this when fully stopped Toggle Wipers o Key w o Toggles wipers between on state and off state Increase Brightness o Key l o Brighten the headlights on the car Decrease Brightness o Key d o Dim the headlights on the car Turn Car o Key t o Prepare car for turning o Disallows all inputs other than the ones specified below Turn Right o Key r o Turns the car 90 degrees to the right, e.g. north->east o Can only do this after using the turn car command

Turn Left o Key l o Turns the car 90 degrees to the left, e.g. north->west o Can only do this after using the turn car command Cancel Turn o Key q o Aborts turn o Can only do this after using the turn car command The simulator needs the following states: Speed in meters per second o Floating Point o Default Value: 0.0 o Min Value: 0.0 o Max Value: 100.0 Total distance traveled in meters o Floating Point o Default Value: 0.0 o Min Value: 0.0 Current direction facing o String Value o Default Value: north o Possible Values: north, south, east, west Number of passengers o Integer Value o Default Value: 0 o Min Value: 0 o Max Value: 3 o The driver isn t a passenger and doesn t count towards this Wiper State o Integer Value o Default Value: 0 o Min Value: 0 o Max Value: 1 o 0 = Off, 1 = On Headlight Brightness o Integer Value o Default Value: 0 o Min Value: 0 o Max Value: 2 o 0 = Off, 1 = Dim, 2 = Bright Error checking is required, including: An invalid character is entered. o Drop the character and prepare for a new one. Making sure values stored are valid: o For most values, just make sure that when it goes above the max value or below the min value, it is set to the max value or min value.

o For string values, check to make sure the string matches one of the possible values. If it doesn t just don t do anything In such cases, an error message should NOT be displayed and the error should be silently handled. Other notes: Use mapped IO to read the inputs. (Given in the interrupt handler) Use interrupt timer instead of busy waiting (Given in the interrupt handler) When displaying the current state (every 10 seconds), print each item of the global state After typing in a command, display the current state of the proper item o E.g. after doing the accelerate command, display the new speed When displaying speed (and distance), show the values in the stored meters per second (meters) as well as miles per hour (miles). o That is you have to have one or more convert functions (use google unit converter to get the values) Extra point opportunity (10 extra points): In addition to the above keep track of car s fuel. You can use the values you want, but make sure to implement the following: o Add a new command to refuel o Decrease the fuel efficiency linearly as the number of passengers increases o Can only refuel when car is stopped. o Keep track of fuel for display o When out of fuel, stop the car Sample run (if you follow this printing convention, remove the typos first): You are driving north You are currently traveling at 0.00000000 m/s (0.00000000 mph) You have travled 0.00000000 meters (0.00000000 miles) The lights are turned off The wipers are off There are 0 passengers A passenger has boarded A passenger has boarded The car's speed has increased The car's speed has increased The car's speed has increased Use the following keys to interact with the system: 'h' for this help message 't' to turn 'w' to toggle the wipers 'l' to increase the intensity of the lights 'o' to decrease the intensity of the lights 'a' to incrase the speed of the car 'd' to decrease the speed of the car

'p' to add passengers when stopped 'r' to remove passengers when stopped Press 'l' to turn left Press 'r' to turn right or Press 'q' to stop turning You are now driving west The light intensity has increase The light intensity has increase You are driving west You are currently traveling at 3.00000000 m/s (6.71080875 mph) You have travled 25.59995842 meters (0.01590708 miles) The high beams are on The wipers are off There are 2 passengers The light intensity has decrease The wipers status has been toggled Press 'l' to turn left Press 'r' to turn right or Press 'q' to stop turning You are now driving south Press 'l' to turn left Press 'r' to turn right or Press 'q' to stop turning Turn canceled The car's speed has decreased]nthe car's speed has decreased]n You are driving south You are currently traveling at 1.00000000 m/s (2.23693633 mph) You have travled 52.65011215 meters (0.03271526 miles) The low beams are on The wipers are on There are 2 passengers The car's speed has decreased]na passenger has left You are driving south You are currently traveling at 0.00000000 m/s (0.00000000 mph) You have travled 56.95004654 meters (0.03538712 miles) The low beams are on The wipers are on There are 1 passengers You are driving south You are currently traveling at 0.00000000 m/s (0.00000000 mph) You have travled 56.95004654 meters (0.03538712 miles) The low beams are on The wipers are on There are 1 passengers

Template code: main: init:.text.globl main # allow hardware interrupts mfc0 $t0, $12 # get status register ori $t0, $t0, 0xff01 mtc0 $t0, $12 # set up keyboard interupts li $t0, 0xFFFF0000 # keyboard memory-mapped address li $a0, 2 sw $a0, 0($t0) # set up a timer li $a0, 5 mtc0 $a0, $11 mtc0 $0, $9 li $s0, 100000 li $s1, 100000 # get a timer interrupt every 50 ms # set up compare register # this will be our input-grabing register # this resets the input li $s2, 0 # our main timer; set to 1 when fired, resets to 0 li $s3, 200 li $s4, 200 # this will be our message timer (10 sec = 200 * 50 ms) # and its default value la $a0, north jal change_direction jal status main_loop: main_loop_inputs: beq $s0, $s1, main_loop_status jal process_input move $s0, $s1 main_loop_status: bgt $s3, $0, main_loop_tick move $s3, $s4 jal status main_loop_tick: beq $s2, $0, main_loop_end move $s2, $0 addi $s3, $s3, -1 jal update main_loop_end: j main_loop main_loop_exit: li $v0, 10 syscall # exit that we won t get to #---------------------------INTERRUPT-HANDLER-----------------------------.kdata ksave0:

.word 0 ksave1:.word 0.ktext 0x80000180 kinterrupt_handler: sw $a0, ksave0 sw $v0, ksave1 mfc0 $k0, $13 srl $a0, $k0, 2 andi $a0, $a0, 0x1F mfc0 $k0, $9 mfc0 $k1, $11 beq $k0, $k1, ktimer_handler kkeyboard_handler: li $v0, 0xFFFF0000 lw $s0, 4($v0) j kexit ktimer_handler: li $s2, 1 # reset timer li $k0, 5 mtc0 $k0, $11 mtc0 $0, $9 kexit: # reenable interrupts mtc0 $0 $13 mfc0 $k0 $12 ori $k0 0x1 mtc0 $k0 $12 # keyboard input # timer fired # get a timer interrupt every 50 ms # set up compare register # Clear Cause register # Set Status register # Interrupts enabled lw $a0, ksave0 lw $v0, ksave1 eret #---------------------------INTERRUPT-HANDLER----------------------------- Grading: 1. You should document your code properly in this homework. You may use the following code as an example for how to style your comments: # Zhenghao Zhang -- 04/10/09 # newton.asm a simple program calculating the square root of a given # is number n using singles. The value of the square root of n, # denoted by x, approximated by x=(x+n/x)/2, until the the # absolute value of the difference between new x and the previous # x is smaller than a given threshold such as 1.0E-3. # function main -- written by Zhenghao Zhang -- 04/10/09 # calling the calsqrt function and display the results # Register use: # $a0 syscall parameter

# $v0 syscall parameter # $f0 exp and syscall return value # $f12 exp and syscall parameter.text.globl main main: li.s $f0, 361.0 mfc1 $a0, $f0 jal calsqrt done: mtc1 $v0, $f12 li $v0,2 syscall eixt: li $v0,10 syscall # function calsqrt -- written by Zhenghao Zhang -- 04/10/09 # calculating the square root of a given number n using singles. # The value of the square root of n, denoted by x, approximated # by x=(x+n/x)/2, until the the absolute value of the difference # between new x and the previous x is smaller than a given # threshold such as 1.0E-3. # Register use: # $a0 parameter from calling routine # $v0 return value # $f0 storing the value of n as a single precision number # $f1 current value of x # $f2 next value of x # $f3 tempory vaiable # $f20 storing constant 2 for dividing # $f21 storing constant 0.001 for exit comparision calsqrt: addi $sp, $sp, -24 swc1 $f0, 20($sp) swc1 $f1, 16($sp) swc1 $f2, 12($sp) swc1 $f3, 8($sp) swc1 $f20, 4($sp) swc1 $f21, 0($sp) mtc1 $a0, $f0 # $f0 gets n li.s $f20, 2.0 # $f20 storing constant 2 for dividing li.s $f21, 0.001 # $f21 storing constant 0.001 for exit comparision div.s $f1, $f0, $f20 # $f1 gets n/2 calsqrtloop: div.s $f2, $f0, $f1 # $f2 gets n/x add.s $f2, $f2, $f1 # $f2 gets n/x + x div.s $f2, $f2, $f20 # $f2 gets x'=(n/x + x)/2 sub.s $f3, $f2, $f1 # $f3 gets x'-x abs.s $f3, $f3 # $f3 gets x'-x c.lt.s $f3, $f21 # set the flag if x'-x < 0.001 bc1t calsqrtdone mov.s $f1, $f2 j calsqrtloop calsqrtdone: mfc1 $v0, $f2 lwc1 $f0, 20($sp) lwc1 $f1, 16($sp) lwc1 $f2, 12($sp) lwc1 $f3, 8($sp) lwc1 $f20, 4($sp) lwc1 $f21, 0($sp) addi $sp, $sp, 24

jr $ra.data msg_done:.asciiz "done\n" 2. Your programs will be evaluated using the following criteria: Proper use of registers and memory (0-5,6-10,11-15) Proper use of load, store and branch instructions (0-4,5-8,9-10) Proper use of integer arithmetic instructions (0-4,5-8,9-10) Proper use of floating point arithmetic instructions (0-4,5-8,9-10) Proper use of character and string instructions (0-2,3-4,5-5) Proper use of subprogram calls [including use of stack] (0-4,5-8,9-10) Proper use of return instructions [including use of stack] (0-2,3-4,5-5) Proper design of a subprogram meet specified requirements (0-8,9-16,17-20) Proper use of appropriate tools to assemble, test and debug program (0-2,3-4,5-5) Appropriate documentation (0-4,5-8,9-10) The three point ranges next to each item specify the range of scores that will be used to represent ineffective, effective and highly effective performance, respectively.