Computer Organization & Architecture Lab (CSC451) : Dr. Bibhash Sen Associate Professor Department of CSE, NIT Durgapur

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Computer Organization & Architecture Lab (CSC451)

Dr. Bibhash Sen


Associate Professor
Department of CSE, NIT Durgapur

MIPS assembly language programming

MARS-(MIPS Assembler and Runtime Simulator)


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.. P. Sanderson and Kenneth Vollmar developed it at Missouri State University. It reads and executes
assembly language programs written for the processor.

Features:
 Quickly editable register and memory values, similar to a spreadsheet.
 Display values in hexadecimal or decimal.
 Command-line mode for instructions to test and evaluate many programs quickly.

Download Link:
https://courses.missouristate.edu/KenVollmar/MARS/download.htm
As of V4.0, MARS requires Java J2SE 1.5 (or later) SDK installed on your computer.
To download - https://www.oracle.com/technetwork/java/javase/downloads/index.html

How to use it:


After downloading the MARS.jar file, you should choose the OpenJDK Platform binary option to open.
Then you will see the initial screen like the below one.

CSC451 – MIPS Assembly Language Programimg 1


Here you can see in the right of the screen that there is a list of Registers that are used for different purposes.
You can see the purposes by taking the cursor-pointer to the name of the register.
You can also check this link below.
http://www.cs.uwm.edu/classes/cs315/Bacon/Lecture/HTML/ch05s03.html
In the bottom, you will see that there are two tabs named Mars Message and Run I/O. These options are for
showing a message when you try to compile and run any program.
At the top of the window, you will see the menu consisting of options like file, edit, run, settings, and help,
which will help you to create a file, open a file, edit a file and run the file.
Firstly create a new file from the menu section then save it using a proper name and ‘.asm’ extension to
start a new program.
Every assembly program has two parts:
1) .data- This section has all the data. Here mainly all the variables are declared. Every variable you
declare here will be stored in the data segment at the next available address.
2) .text- This section has all the instructions that every program needs. Every instruction you write
here will be stored in the text segment at the next available address.

CSC451 – MIPS Assembly Language Programimg 2


Example: .data
mymessage: .asciiz "Hello world."
.text
li $v0, 4
la $a0, mymessage
syscall

Every MIPS program uses different memory segments Data Segment, Text Segment.
In this example, ‘mymessage’ is a variable. ‘asciiz’ this keyword stores the string “Hello World.” in the
data segment and adds a null character to terminate. ‘li’ means load immediately signifies that the machine
should be ready to print anything. The value ‘4’ signifies the data type to be loaded on the variable. ‘la
$a0,mymessage’ signifies that load the mymessage value into the register a0.
MIPS syscall is an individual instruction used to do a service. It is a “Software Interrupt ” to invoke OS for
an action. ‘syscall’ instruction provides many services. It may be to print a number or to terminate a
program.
To execute this code save the file, then go to the ‘Run’ menu then select ‘Assemble.’ If the program has an
error, then at the bottom, a message will be displayed regarding the fault. If it has no error, then a message
‘Assemble: operation completed successfully.’ Will be displayed. Then select the run option at the top. The
bottom message box will show the output of the program.

Some Common Data Definitions:


• .word w1, …, wn
• store n 32-bit quantities in successive memory words.
• .half h1, …, hn
• store n 16-bit quantities in successive memory halfwords.
• .byte b1, …, bn
• store n 8-bit quantities in successive memory bytes.
• .ascii str
• store the string in memory but do not null-terminated it.
• strings are represented in double-quotes “str”.
• special characters, e.g. \n, \t, follow C convention.
• .asciiz str
• store the string in memory and null-terminated it.
• .float f1, …, fn
• store n floating-point single precision numbers in successive memory locations.
• .double d1, …, dn
• store n floating-point double precision numbers in successive memory locations.

CSC451 – MIPS Assembly Language Programimg 3

You might also like