MIPS Assembly Lab Assignment: Character Manipulation and Recursion, Lab Reports of Computer Science

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

Pre 2010

Uploaded on 02/13/2009

koofers-user-m78
koofers-user-m78 🇺🇸

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Architecture
CPSC 321, Fall Semester 2004
Lab Assignment #2
Due: One week after your lab session complete by yourself.
1 Objective
This laboratory assignment will help you understand loops, procedures, and
the parameter passing conventions of the MIPS assembly language.
2 Assignment
[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:
1. Accept a string input from the console. The input may contain any
ASCII character.
2. You are required to convert all lower case characters into upper case
characters.
3. Display the converted string onto the console.
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:
1. Accept a sentence as an input from the console.
1
pf3
pf4
pf5

Partial preview of the text

Download MIPS Assembly Lab Assignment: Character Manipulation and Recursion and more Lab Reports Computer Science in PDF only on Docsity!

Computer Architecture CPSC 321, Fall Semester 2004 Lab Assignment # Due: One week after your lab session – complete by yourself.

1 Objective

This laboratory assignment will help you understand loops, procedures, and the parameter passing conventions of the MIPS assembly language.

2 Assignment

[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:

  1. Accept a string input from the console. The input may contain any ASCII character.
  2. You are required to convert all lower case characters into upper case characters.
  3. Display the converted string onto the console.

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:

  1. Accept a sentence as an input from the console.
  1. Use recursion to invert the sequence of the words in the sentence. The only delimiter to be considered is the whitespace character. All other delimiters should be excluded when splitting the sentence.
  2. Display the inverted sentence onto the console.

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

3 Documentation on MIPS Assembler and SPIM

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.

3.1 MIPS Assembler Syntax

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 The following data items should be stored in the kernel data segment. If the optional argument addr is present, the items are stored beginning at address addr.

.ktext The next items are put in the kernel text segment. In SPIM, these items may only be instructions or words (see the .word directive be- low). If the optional argument addr is present, the items are stored beginning at address addr.

.space n Allocate n bytes of space in the current segment (which must be the data segment in SPIM).

.text The next items are put in the user text segment. In SPIM, these items may only be instructions or words (see the .word directive below). If the optional argument addr is present, the items are stored beginning at address addr.

.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).

3.2 System Calls

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.

4 Dishonesty

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.