MIPS Assembly Homework 2: Writing and Running a Simple Program with SPIM Simulator, Assignments of Engineering

The instructions for completing homework 2 in cpr e 381, which involves installing spim simulator, writing a mips assembly program, and running it with different inputs. Students are required to submit the results for at least three distinct values, explain what the program does, provide a commented source code, and translate it into c code. References to chapter 2 and appendix a of the book are provided.

Typology: Assignments

Pre 2010

Uploaded on 09/02/2009

koofers-user-fb5
koofers-user-fb5 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cpr E 381 Homework 2
1. Install a version of spim (the MIPS
simulator). The software is available for
Windows and Linux/Unix/Mac OSX
systems. It can be found on the CD
included with your book or can be
downloaded from the web
(http://pages.cs.wisc.edu/~larus/spim.html).
Read the platform specific introduction to
the simulator.
Type the program at right into a text file
named “hw2.s”.
Load the program into spim.
A) Run the program several times trying
different values. Submit results for at
least three distinct values.
B) What is the program doing? Keep your
answers brief.
C) Submit a line commented source code
describing the program.
D) Translate and submit the program into
C code.
You will want to look at Chapter 2 as a
reference for instructions. Appendix A from
the book (may be on the CD) will also be
useful, especially for the “syscall” operations.
.data
str1: .asciiz " Please enter a number >= 1 : "
str2: .asciiz "\n\n The result is:"
.text
.globl main
main:
li $v0, 4
la $a0, str1
syscall
li $v0, 5
syscall
move $t1, $v0
addi $t3, $zero, 1
slti $t2, $t1, 1
beq $t3, $t2, do_nothing
addi $t0, $t0, 0
loop:
sge $t2, $t1, $t3
beq $t2, $zero, end
add $t0, $t0 , $t1
addi $t1, $t1 , -1
j loop
end:
li $v0, 4
la $a0, str2
syscall
li $v0, 1
move $a0, $t0
syscall
do_nothing:
li $v0, 10
syscall

Partial preview of the text

Download MIPS Assembly Homework 2: Writing and Running a Simple Program with SPIM Simulator and more Assignments Engineering in PDF only on Docsity!

Cpr E 381 Homework 2

1. Install a version of spim (the MIPS

simulator). The software is available for

Windows and Linux/Unix/Mac OSX

systems. It can be found on the CD

included with your book or can be

downloaded from the web

(http://pages.cs.wisc.edu/~larus/spim.html).

Read the platform specific introduction to

the simulator.

Type the program at right into a text file

named “hw2.s”.

Load the program into spim.

A) Run the program several times trying

different values. Submit results for at

least three distinct values.

B) What is the program doing? Keep your

answers brief.

C) Submit a line commented source code

describing the program.

D) Translate and submit the program into

C code.

You will want to look at Chapter 2 as a

reference for instructions. Appendix A from

the book (may be on the CD) will also be

useful, especially for the “syscall” operations.

.data str1: .asciiz " Please enter a number >= 1 : " str2: .asciiz "\n\n The result is:" .text .globl main

main: li $v0, 4 la $a0, str syscall

li $v0, 5 syscall move $t1, $v

addi $t3, $zero, 1 slti $t2, $t1, 1 beq $t3, $t2, do_nothing

addi $t0, $t0, 0 loop: sge $t2, $t1, $t beq $t2, $zero, end

add $t0, $t0 , $t addi $t1, $t1 , - j loop

end: li $v0, 4 la $a0, str syscall

li $v0, 1 move $a0, $t syscall

do_nothing:

li $v0, 10 syscall