CSE 378 Homework 1 - Part 3
You're going to write a MIPS simulator, that is, a program that can simulate the execution of MIPS instructions. More precisely, your simulator handles exactly six instructions: , , , , , and . (The last is not an actual MIPS instruction, but is useful for obvious reasons. It's part of the Cebollita instruction set.)
Your program takes as input a program written using only those six instructions. You execute each of the instructions, in order, halting when you encounter a instruction. As you execute each instruction, you update values stored in the simulator's registers. That's pretty much all there is to it.
Your simulator happens to be written in MIPS assembler as well (or, actually, the subset of MIPS assembler that Cebollita implements).
Input to your program is a list of instructions, encoded as decimal integer representations of the 32-bit machine instructions. For example: 5 537395212 554237972 554303505 19552293 1073741848 The first integer indicates how many instructions follow. The integers that come next are instructions, written in decimal (because the only routine available to read an integer from assembler requires decimal input). They correspond to the assembler program, and the hex encoded machine instructions, shown in the following output: 00000000 0x2008000c: addi $t0, $0, 12 00000004 0x21090014: addi $t1, $t0, 20 00000008 0x210a0011: addi $t2, $t0, 17 0000000c 0x012a5825: or $t3, $t1, $t2 00000010 0x40000018: halt
None. We'll run your program in Cebollita and examine the contents of the simulated registers when it halts.
Having a look at skeleton code will probably make things somewhat less confusing. At the top, it allocates space to hold the program to be simulated and to keep the values in the simulated registers. In the section, the code begins by reading in the input: first the number of instructions in the input and then the instructions themselves. It then initializes the simulated PC, as a pointer into the memory holding the program to be simulated, and goes into a loop fetching instructions and updating the simulated PC to mimic sequential flow control. The skeleton doesn't actually simulate the effect of each instruction it fetches, though - that's what you'll implement. Instead, it simply checks whether or not the instruction just fetched is a . If not, it fetches the next instruction. Otherwise, the skeleton program itself halts.
Building Your Application
There are two steps:
You can now execute in the Cebollita simulator: $ java dbg.UI a.exe
- Assemble: $ java asm.parser mipsSim.s That produces file .
- Link: $ java asm.Linker prologue-standalone.o mipsSim.o (The order of the operands is significant.) That produces .
Preparing Test Input
It's a bit clunky to prepare the input to your simulator. The basic process is
- Create a small assembler program () that uses only the instructions your simulator supports.
- Assemble it to produce a file.
- Use to dump the instructions in hex.
- Convert the hex to decimal.
- Run your simulator and type in the input.
That's so painful that we're providing some automation to help. The distribution (see below) comes with a simple - it should be intelligible from what you've seen in CSE 303. The has four useful targets:
You can (and should) use the even if you're not currently 100% comfortable with - it's easy, just try it. Your system must have installed, though, to use all the facilities provided.
will assemble and link your simulator ().
will assemble , run on it to get the hex coding of the instructions, then run a program () to extract the hex instructions and turn them into decimal, and finally create a file () that is suitable for feeding as input to your simulator.
will build your simulator, build the input file, and then invoke the Cebollita simulator to run your simulator, providing it with input from . (The switch to causes it to read input from the named file, rather than from the keyboard.)
deletes all intermediate files.
The Cebollita assembler doesn't implement everything described in the text. In particular, it doesn't implement pseudo-instructions - instructions that are not actually supported by the hardware, but for which the assembler inserts one or two instructions that achieve the same effect. Examples are things like , , and . It also doesn't implement the full MIPS instructio set. It's very unlikely, though, that you'll want to use an instruction that isn't available.
I would guess that the vast majority of you won't come across any distinctions between what the book describes and what Cebollita implements. If something won't assemble, though, the Cebollita documentation is the place to look for exactly what it supports.
You can (and should!) assume in your code that the input is always error free - there are 10 or fewer instructions, and each is one of the six your simulator supports.
This is terrible programming practice, but makes life a lot easier, especially when hand coding assembler. (Never, ever, make this assumption again, though. I hang my head in shame that we need it to make this assignment reasonable.)
Downloading Starter Files
Download hw1programming.tar.gz, and save it in the directory you want to work in. Expand it like this: $ tar xzf hw1programming.tar.gz That will produce files , , , , and .
How To Turn In
CS 271: Computer Architecture and Assembly Language (Winter 2013)
Important announcements and changes to this page will be noted here. Please check back regularly!
The dates of the midterm exams and assignment deadlines will be added to this list as the course develops.
- Fri, Jan 18 — Homework 1 due (in class)
- Mon, Jan 21 — No class! MLK Jr. Day
- Wed, Jan 30 — Programming Assignment 1 due (via TEACH)
- Mon, Feb 4 — Midterm #1
- Wed, Feb 13 — Programming Assignment 2 due (via TEACH)
- Wed, Feb 27 — Midterm #2
- Fri, Mar 1 — No class! (I'm out of town)
- Wed, Mar 6 — Programming Assignment 3 due (via TEACH)
- Fri, Mar 15 — Programming Assignment 4 due (via TEACH)
- Tues, Mar 19, Noon-2pm — Final exam
Slides from the lectures are posted below, usually just before class. I will continue to update the slides for each stage of the course until we are done with that stage.
Toggle outlines ← click to show/hide a listing of the contents of each set of slides.
|Jan 7||Course Overview||[pdf]|
|Jan 9–14||Data Representation||[pdf]||(updated: Jan 18)|
|Jan 14–16||Intro to MIPS Architecture||[pdf]||(updated: Jan 18)|
|Jan 18||More Data Representation||[pdf]|
|Jan 23–25||Intro to MIPS Assembly||[pdf]||(updated: Jan 25)||Hello.asm, Decls.asm, Add3.asm, SubWord.asm, Parrot.asm|
|Jan 28–30||Algorithms in Assembly (Pt. 1)||[pdf]||(updated: Feb 6)|
|Feb 1||Midterm #1 Review||[pdf]||(updated: Feb 3)|
|Feb 6–15||Algorithms in Assembly (Pt. 2)||[pdf]||(updated: Feb 13)||Parrot.asm, Circle.asm, JokeIdx.asm, JokeAddr.asm, ReverseIdx.asm, ReverseAddr.asm, Switch.asm|
|Feb 18–22||Procedure Calls (Pt. 1)||[pdf]||(updated: Feb 22)||ProcJoke.asm|
|Feb 25||Midterm #2 Review||[pdf]|
|Mar 4–6||Procedure Calls (Pt. 2)||[pdf]||(updated: Mar 6)||FactRec.asm, FactMemo.asm, FunPointers.asm|
|Mar 8–13||Machine Code||[pdf]||(updated: Mar 13)||AbsVsRel.asm|
|Mar 15||Pipelining and Final Review||[pdf]|
Tools and links
MARS MIPS Assembler and Runtime Simulator — This is the tool you will be using to complete your programming assignments. It provides a MIPS assembler and a simulator of the MIPS architecture. We'll do a brief MARS tutorial in class.
Other useful MIPS resources:
Contact info and office hours
Grading and homework policies
Grades will be computed using the following weights. (This is still subject to change as the course develops.)
- 10% – written homework
- 30% – programming assignments
- 30% – midterms (2 x 15% each)
- 30% – final exam
Scores for individual tests and assignments may be curved upward if the results suggest this is necessary, but never downward.
For written homework and programming assignments:
- Discussion is encouraged!
- However, each student should submit their own final work.
- You should understand fully the work you submit, and be able to reproduce it if necessary.
- Remember, the goal of homework is to help you learn the material, so don't cheat yourself out of that!
- Please list the names of any students you collaborate with in your final submission.
Last updated: Mar 15, 2013