


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
Material Type: Assignment; Subject: COMPUTER SCIENCE; University: Texas A&M University; Term: Unknown 1989;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Release date: 11 September 2006 Due date: One week following lab
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 input. 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.
MIPS Assembler Syntax Comments in assembler ¯ les begin with a sharp-sign (#) (also known as the pound sign or hash). Everything from the sharp-sign to the end of the line is ignored.
Identifers 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 identifers. 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 "
SPIM supports a subset of the assembler directives provided by the ac- tual MIPS assembler:
.align n
Align the next datum on a 2n^ byte boundary. For example, .align 2 aligns the next value on a word boundary. .align 0 turns off automatic alignment of .half, .word, .float, and .double directives until the next .data or .kdata directive.
.ascii str Store the string in memory, but do not null-terminate it.
.asciiz str Store the string in memory and null-terminate it.
.byte b1, ..., bn Store the n values in successive bytes of memory.
.data
.double d1, ..., dn Store the n floating-point double precision numbers in successive memory locations.
.extern sym size Declare that the datum stored at sym is size bytes large and is a global symbol. This directive enables the assembler to store the datum in a portion of the data segment that is efficiently accessed via register $gp.
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 precision 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 that is running.
print_character is passed an integer (character) and prints it on the console.
read_character has the same semantics as the UNIX library routine fgetc. It reads one character into an integer.
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)