



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lab assignment for cpsc 321, computer architecture, fall semester 2004. The assignment focuses on understanding loops, procedures, and parameter passing conventions of the mips assembly language by writing a program to perform character manipulation and recursion. The document also includes documentation on mips assembler syntax and spim system calls.
Typology: Lab Reports
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Computer Architecture CPSC 321, Fall Semester 2004 Lab Assignment # Due: One week after your lab session – complete by yourself.
This laboratory assignment will help you understand loops, procedures, and the parameter passing conventions of the MIPS assembly language.
[15 points] For this part of the assignment, you are required to write a MIPS assembly program to perform character manipulation on a given string in- put.
The following are the tasks to complete this part:
Example.
Please enter a string: Abc123xY.,;"sdfGH
New string: ABC123XY.,;"SDFGH
[35 points] You are required to use recursion to invert an input sentence, which will be delimited by the whitespace character.
The following are the tasks to complete this part:
Example.
Please enter a whitespace delimited sentence: The quick brown fox jumped over the lazy dog
The inverted sentence is: dog lazy the over jumped fox brown quick The
This section explains the various directives of the MIPS assembler, as well as, the “OS-like” services provided by the SPIM simulator to MIPS programs.
Comments in assembler files begin with a sharp-sign (#). Everything from the sharp-sign to the end of the line is ignored. Identifiers are a sequence of alphanumeric characters, under-bars ( ), and dots (.) that do not begin with a number. Opcodes for instructions are reserved words that are not valid identifiers. Labels are declared by putting them at the beginning of a line followed by a colon, for example:
.data item: .word 1 .text .globl main # main must be global la $t0, item # load address(item) to register main: lw $s0, 0($t0) # $t0 == &item;
Strings are enclosed in double-quotes ("). Special characters in strings follow the C convention:
newline \n tab \t quote "
.kdata
.ktext
.space n Allocate n bytes of space in the current segment (which must be the data segment in SPIM).
.text
.word w1, ..., wn Store the n 32-bit quantities in successive memory words.
SPIM does not distinguish various parts of the data segment (.data, .rdata, and .sdata).
SPIM provides a small set of operating-system-like services through the MIPS system call (syscall) instruction. To request a service, a program loads the system call code (see Table 1) into register $v0 and the arguments into registers $a0,.. ., $a3 (or $f12 for floating point values). System calls that return values put their result in register $v0 (or $f0 for floating point results). For example, to print “the answer = 5”, use the commands:
.data str: .asciiz "the answer = " .text li $v0, 4 # $system call code for print_str la $a0, str # $address of string to print syscall # print the string
Service System Call Code Arguments Result print int 1 $a0 = integer print float 2 $f12 = float print double 3 $f12 = double print string 4 $a0 = string read int 5 integer (in $v0) read float 6 float (in $f0) read double 7 double (in $f0) read string 8 $a0 = buffer, $a1 = length sbrk 9 $a0 = amount address (in $v0) exit 10 print character 11 $a0 = integer read character 12 char (in $v0)
Table 1: System services.
li $v0, 1 # $system call code for print_int li $a0, 5 # $integer to print syscall # print it
print int is passed an integer and prints it on the console. print float prints a single floating point number. print double prints a double preci- sion number. print string is passed a pointer to a null-terminated string, which it writes to the console. read int, read float, and read double read an entire line of input up to and including the newline. Characters following the number are ignored. read string has the same semantics as the Unix library routine fgets. It reads up to n − 1 characters into a buffer and terminates the string with a null byte. If there are fewer characters on the current line, it reads through the newline and again null-terminates the string. sbrk returns a pointer to a block of memory containing n additional bytes. exit stops a program from running.
Make sure that you complete the assignment by yourself. Do not copy the code from others, nor provide others with your code. Refrain from copying and modifying the code from other sources.