Mips Programming Assignment 1

CSE 378 Homework 1 - Part 3

Assembler Programming

Problem Overview

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).

Program Input

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

Program Output

None. We'll run your program in Cebollita and examine the contents of the simulated registers when it halts.

Skeleton Code

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:
  1. Assemble: $ java asm.parser mipsSim.s That produces file .
  2. Link: $ java asm.Linker prologue-standalone.o mipsSim.o (The order of the operands is significant.) That produces .
You can now execute in the Cebollita simulator: $ java dbg.UI a.exe

Preparing Test Input

It's a bit clunky to prepare the input to your simulator. The basic process is
  1. Create a small assembler program () that uses only the instructions your simulator supports.
  2. Assemble it to produce a file.
  3. Use to dump the instructions in hex.
  4. Convert the hex to decimal.
  5. 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:


  1. will assemble and link your simulator ().

  2. 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.

  3. 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.)

  4. deletes all intermediate files.
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.

Caveat

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.

Un-Caveat

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

TBA

CS 271: Computer Architecture and Assembly Language (Winter 2013)


Contents

Announcements

Important announcements and changes to this page will be noted here. Please check back regularly!

Important dates

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

Lecture slides

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.

DateTitleAdditional files
Jan 7Course Overview[pdf]
  • Course logistics
  • What is this course about?
    • What is the scope?
    • What is a computer architecture?
    • What is an assembly language?
  • Learning objectives
Jan 9–14Data Representation[pdf](updated: Jan 18)
  • Internal vs. external representations
  • Representing the natural numbers
    • Binary number system
    • Binary arithmetic
    • Hexadecimal and base-N number systems
  • Fixed-size integer representations
    • Representing negative numbers
    • Big endian vs. little endian
Jan 14–16Intro to MIPS Architecture[pdf](updated: Jan 18)
  • Overview of the MIPS architecture
    • What is a computer architecture?
    • Fetch-decode-execute cycle
    • Datapath and control unit
  • Components of the MIPS architecture
    • Memory
    • Other components of the datapath
    • Control unit
Jan 18More Data Representation[pdf]
  • Some more comments on integers
    • Carry out vs. overflow
    • Identifying negative integers
  • Representing characters and strings
    • ASCII encoding
    • Strings in MIPS and endianness
Jan 23–25Intro to MIPS Assembly[pdf](updated: Jan 25)Hello.asm, Decls.asm, Add3.asm, SubWord.asm, Parrot.asm
  • Overview of assembly programming
    • MARS tutorial
    • MIPS assembly syntax
    • Role of pseudocode
  • Some simple instructions
    • Integer logic and arithmetic
    • Manipulating register values
  • Interacting with data memory
    • Declaring constants and variables
    • Reading and writing
  • Performing input and output
    • Memory-mapped I/O, role of the OS
    • Using the systemcall interface
Jan 28–30Algorithms in Assembly (Pt. 1)[pdf](updated: Feb 6)
  • Effective documentation
  • Arithmetic and logical expressions
    • Compositionality
    • Sequentializing complex expressions
    • Bitwise vs. logical operations
Feb 1Midterm #1 Review[pdf](updated: Feb 3)
  • Structure of midterm
  • Example problems and exercises
Feb 6–15Algorithms in Assembly (Pt. 2)[pdf](updated: Feb 13)Parrot.asm, Circle.asm, JokeIdx.asm, JokeAddr.asm, ReverseIdx.asm, ReverseAddr.asm, Switch.asm
  • Reading strings into memory
  • Jumps and conditional branches
  • Branching control structures
    • If-then-else and if-then statements
  • Looping control structures
    • Do-while, while, and for loops
    • Break and continue, indefinite loops
  • Arrays
    • For-each loop
    • Switch statement
Feb 18–22Procedure Calls (Pt. 1)[pdf](updated: Feb 22)ProcJoke.asm
  • Intro to procedure calls
    • Caller vs. callee
    • Procedure call basics
  • Calling conventions
  • The stack
    • Interacting with the stack
    • Structure of a stack frame
  • Subroutine linkage
Feb 25Midterm #2 Review[pdf]
  • Structure of midterm
  • Example problems and exercises
Mar 4–6Procedure Calls (Pt. 2)[pdf](updated: Mar 6)FactRec.asm, FactMemo.asm, FunPointers.asm
  • Recursion
  • Memoization
  • Function pointers
  • Calling conventions review
Mar 8–13Machine Code[pdf](updated: Mar 13)AbsVsRel.asm
  • What is machine code?
    • RISC vs. CISC
    • MIPS instruction formats
  • Assembling basic instructions
    • R-type instructions
    • I-type instructions
    • J-type instructions
  • Macro instructions
Mar 15Pipelining and Final Review[pdf]
  • Pipelined execution
    • What is a pipeline?
    • MIPS pipeline
    • Hazards
  • Review for final
    • Overview of final
    • More practice assembling

Assignments

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:


Course details

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

One thought on “Mips Programming Assignment 1

Leave a Reply

Your email address will not be published. Required fields are marked *