- YAMS: Awesome MIPS Server. Team HKNSoc (pronounced “hack-in-sock”) Stephen Brennan (smb196) Katherine Cass (krc53) Jeffrey Copeland (jpc86) Andrew Mason (ajm188) Thomas Murphy (trm70) Aaron Neyer (agn31) Description. This project is a static HTTP server in MIPS, using MARS as a simulator. Sockets are implemented by extending MARS syscalls.
- Introduction to MARS Instruction execution flow, Assembly programming, Addressing MARS installation procedure and MIPS Assembly Instructions 1. Y Week2 Week 3 1. Introduction to Project 1: Practice Problems and Code for Project 1 How to use registers and characters in MIPS Assembly 1. Y Week 4 Week 5 1. Project 1 (Part A Code): Write an assembly.
- MARS is a lightweight interactive development environment (IDE) for programming in MIPS assembly language, intended for educational-level use with Patterson and Hennessy's Computer Organization and Design.
- Sample MIPS assembly program to run under MARS Fibonacci.asm A 'tool' is the MARS utility for MIPS control of simulated devices, including contention for resources. Sample tool is a Scavenger Hunt (screeenshot 23KB), in which each student writes a MIPS subroutine to direct the path of a character to travel to several locations.
Assembly languages typically have a macro feature. A macro is a (few) lines of code with 'fill-in' formal parameters (or arguments). In this sense, it is similar to a function. However, while a function is assembled once, and then may be called from many different locations, with varying arguments, a 'macro call' (line containing the macro name) causes the assembler to copy the lines of the macro into the code at that point, putting in the actual arguments. This avoids the overhead of the call and return instructions, the associated argument passing, and register shuffling.
Mars Mips Machine
MARS is a lightweight interactive development environment (IDE) for programming in MIPS assembly language, intended for educational-level use with Patterson and Hennessy's Computer Organization and Design.
James Larus' article (pdf) describes macros for MIPS, however, his SPIM only implements a subset of the assembly language, that doesn't include macros. Mars has recently included macros, so you can use them, however that leaves me with a problem, because mipsmark relies on spim. So we need a preprocessor to do the macro expansion. I have written one, in python.
Thus, you are now free to use (Mars style) .macro and .include directives in your mips assembler code. You can run you programs with Mars, or use my 'mapp' preprocessor (Macro (or Mars) Assembly PreProcessor).
The Mars .macro, .include
.include 'somefile'
includes all the lines of somefile (in your current directory) as though they were written in your program. This would be a good way to include some generally useful macros.
.macro swap (%a, %b)
--- for example, introduces a macro named swap, with two parameters. Then follow lines of assembly, in which %a and %b will be replaced whenever the macro is 'called'
.end_macro ends the macro
However, the ( , and ) are optional, to make it look like C, so please leave them out, and just use spaces, like this:
.macroswap %a %b
My mapp uses a simple split() method, which splits on 'whitespace' Mars also allows $ instead of %, mapp doesn't care, but I recommend using % for clairity, and lest 'load a number' be transformed into 'lo$spd $sp number'
swap $t0 $t1
later onwill insert the assembly instructions for swapping the values in 2 memory locations pointed to by $t0 and $t1
Restrictions for mapp
- (parentheses) and commas are not allowed in macro definitions or calls
- If not enough arguments in a call, line will be left as is, with an error comment
- Extra arguments will be ignored - Actually Mars will object
- Do not put comments on the .macro line -- they will be assumed to be more parameters
- does not 'recurse' -- no macro calls inside of macros, no include directives inside included files.
Please name your file with macros with .am, for example, myfile.am
mapp myfile
will create a file named myfile.a
Use this created file for QtSpim, spim, mipsmark, and submit cs216.
Always make your changes to myfile.am and then rerun mapp
An example of macros in Mars and mapp for SPIM
These give this result:
From running the command mapp macroThis is the resulting file, macro.a which spim can execute.
Mars (version 4.3 and up) will run macro.am directly, so it won't produce this file, but the code in the execute window will be the same. Mars gives the same results from either file.
Back to CS 216, or current LabRemarks
This section provides an overview of what mips is, and why a developer might want to use it.
It should also mention any large subjects within mips, and link out to the related topics. Since the Documentation for mips is new, you may need to create initial versions of those related topics.
Installation or Setup
Detailed instructions on getting mips set up or installed.
MARS MIPS Simulator
MARS MIPS simulator is an assembly language editor, assembler, simulator & debugger for the MIPS processor, developed by Pete Sanderson and Kenneth Vollmar at Missouri State University (src).
You get the MARS for free here. As for installing the 4.5 version, you might need the suitable Java SDK for your system from here
Before assembling, the environment of this simulator can be simplisticly split to three segments: the editor at the upper left where all of the code is being written, the compiler/output right beneath the editor and the list of registers that represent the 'CPU' for our program.
Mars Mips Assembly
After assembling (by simply pressing F3) the environment changes, with two new segments getting the position of the editor: the text segment where
i) each line of assembly code gets cleared of 'pseudoinstructions' (we'll talk about those in a sec) at the 'basic' column and
ii) the machine code for each instruction at the 'code' column,
and the data segment where we can have a look at a representation of the memory of a processor with little-endian order.
After assembling, we can execute our code either all at once (F5) or step by step (F7), as well as rewinding the execution several steps backwards to the back (F8).
Now, let's see the example code from above and explain each line:
MARS accepts and exports files with the .asm filetype
But the code above prints just a character, what about the good ol' 'Hello World'? What about, dunno, adding a number or something? Well, we can change what we had a bit for just that:
Before illustrating the results through MARS, a little more explanation about these commands is needed:
System calls are a set of services provided from the operating system. To use a system call, a call code is needed to be put to $v0 register for the needed operation. If a system call has arguments, those are put at the $a0-$a2 registers. Here are all the system calls.
li
(load immediate) is a pseudo-instruction (we'll talk about that later) that instantly loads a register with a value.la
(load address) is also a pseudo-instruction that loads an address to a register. Withli $v0, 4
the $v0 register has now4
as value, whilela $a0, str
loads the string ofstr
to the$a0
register.A word is (as much as we are talking about MIPS) a 32 bits sequence, with bit 31 being the Most Significant Bit and bit 0 being the Least Significant Bit.
lw
(load word) transfers from the memory to a register, whilesw
(store word) transfers from a register to the memory. With thelw $s1, 0($t0)
command, we loaded to$s1
register the value that was at the LSB of the$t0
register (thats what the0
symbolizes here, the offset of the word), aka256
.$t0
here has the address, while$s1
has the value.sw $t2, 0($t0)
does just the opposite job.MARS uses the Little Endian, meaning that the LSB of a word is stored to the smallest byte address of the memory.
MIPS uses byte addresses, so an address is apart of its previous and next by 4.
By assembling the code from before, we can further understand how memory and registers exchange, disabling 'Hexadecimal Values' from the Data Segment:
or enabling 'ASCII' from the Data Segment:
Start it like this
$ java -jar Mars4_5.jar
Create this file and save it.
Press F3 to assembly it and then press run. Now you are started compiling and executing MIPS code.
QtSpim for windows
- download QtSpim from here 32.6 MB
- install it easy installation
- make your first assembly file (.s) or use the sample C:Program Files (x86)QtSpimhelloworld.s
- run the program from the desktop shortcut or C:Program Files (x86)QtSpimQtSpim.exe
there are two windows for the program the main one labeled QtSpim here you see the program you are executing (labeled text), the memory(labeled data), the values of the registers (labeled FP Regs for floating point and Int Regs for integer ) and the control for the simulator
the other window labeled console is where you will see the output and enter the input of your program if there are any
- load the file using File -> Load File
- you can use click run (f5) to see the end result or go step by step (p10) to see state of the register and memory while the program executing to debug