Introductory MIPS Assembly Code Programming - Lab 2 | CPSC 321, Assignments of Computer Science

Material Type: Assignment; Subject: COMPUTER SCIENCE; University: Texas A&M University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-krp
koofers-user-krp 🇺🇸

4.3

(3)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 321:501-503 - Computer Architecture
Texas A&M University
Department of Computer Science
Fall 2006
Lab 2 (50 pts) – Introductory MIPS Assembly Code Programming
Complete by yourself
Release date: 11 September 2006
Due date: One week following lab
Objective
This laboratory assignment will help you understand loops, procedures, and the parameter passing
conventions of the MIPS assembly language.
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 input.
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 on 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.
2.
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.
3. Display the inverted sentence on 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
Documentation on MIPS Assembler and SPIM
This section explains the various directives of the MIPS assembler, as well as, the
OS
like
services
Page
1
of
4
Introduction to MIPS Assembly Programming
9/1/2006
file://H:\web_courses\cpsc321\labs\lab2_06c.htm
pf3
pf4

Partial preview of the text

Download Introductory MIPS Assembly Code Programming - Lab 2 | CPSC 321 and more Assignments Computer Science in PDF only on Docsity!

CPSC 321:501-503 - Computer Architecture

Texas A&M University

Department of Computer Science

Fall 2006

Lab 2 (50 pts) – Introductory MIPS Assembly Code Programming

Complete by yourself

Release date: 11 September 2006 Due date: One week following lab

Objective

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

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 input. 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 on 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.
  2. 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.
  3. Display the inverted sentence on 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

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.

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

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

Dishonesty

                                    

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)