Docsity

MIPS Assembler Exercise: Sorting and IO - Project | CSCE 212, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
CSCE 212
Project 1
MIPS Assembler Exercise
“Sorting and I/O”
Due Date: 2/19
Introduction
In this lab you will write a short program in MIPS assembly code and simulate it
using SPIM. This will familiarize you with the MIPS instruction set architecture.
Design Requirements
Your goal is to write a complete program in MIPS assembly language that
implements the bubble sort algorithm to sort a variable-sized array of signed 32-bit
integers (words) read from the console. A “special value” of 9999 will be used to
signify the end of the input. This value will not be used as part of the sort data.
Use the following pseudocode algorithm:
n=0;
do {
read in
vals[n]=in
n = n + 1
} while in != 9999
n = n - 1
for i = 0 to n-2 do {
for j = 0 to n-2 do {
if vals[j] > vals[j+1] then swap elements
}
}
for i = 0 to n-1 do {
print vals[i]
}
System call 5 ($v0=5) reads an integer from the console (returns to $v0), while
system call 1 ($v0=1) prints an integer to the console (input in $a0).
Use the following line to initialize memory to hold the input (note that vals is
essentially a label pointing to the start of the data segment):
.data
vals:
What to Submit
Submit your code via CSE Dropbox (via https://dropbox.cse.sc.edu)

Partial preview of the text

Download MIPS Assembler Exercise: Sorting and IO - Project | CSCE 212 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CSCE 212

Project 1

MIPS Assembler Exercise

“Sorting and I/O”

Due Date: 2/

Introduction In this lab you will write a short program in MIPS assembly code and simulate it using SPIM. This will familiarize you with the MIPS instruction set architecture.

Design Requirements Your goal is to write a complete program in MIPS assembly language that implements the bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words) read from the console. A “special value” of 9999 will be used to signify the end of the input. This value will not be used as part of the sort data.

Use the following pseudocode algorithm:

n =0;

do { read in vals [ n ]= in n = n + 1 } while in != 9999

n = n - 1

for i = 0 to n -2 do { for j = 0 to n -2 do { if vals [ j ] > vals [ j +1] then swap elements } }

for i = 0 to n -1 do { print vals [ i ] }

System call 5 ($v0=5) reads an integer from the console (returns to $v0), while system call 1 ($v0=1) prints an integer to the console (input in $a0).

Use the following line to initialize memory to hold the input (note that vals is essentially a label pointing to the start of the data segment):

.data vals:

What to Submit Submit your code via CSE Dropbox (via https://dropbox.cse.sc.edu)