CS61C Fall 2012 HW3

TA: Loc Do

Due Sunday, Sep 16 , 2012 @ 23:59:59


This assignment is designed to give you some practice with MIPS and number system


Create a directory named “hw3” inside your working repository and put your solutions to problems 1 in hw3.txt, and problem 2 in stringlen. It is important that you place your submission for hw3 inside this directory and not somewhere else, as when we pull submissions, we will look for your submission there. Then run these commands:

git add -A
git commit -m "hw3 submission"
git tag -f hw3
git push --tags origin master

Problem 1: Numbers, numbers everywhere

Fill in the blank of the text file hw3.txt

NOTE: Please keep the format of the text file.

Problem 2: MIPS

Get the file stringlen here

To run MIPS, you can download MARS here

msg1:.asciiz "Please insert text (max 20 characters): "
msg2:.asciiz "\nThe length of the text is: "
str1: .space 20
.globl main
addi $v0, $v0,4
la $a0,msg1
syscall #print msg1
li $v0,8
la $a0,str1
addi $a1,$zero,20
syscall   #get string 1

la $a0,str1  #pass address of str1
jal len

#your code here

la $a0,msg2 
li $v0,4
move $a0,$t0 #output the results 
li $v0,1

li $v0,10

In this template, you need to create a function to find the length of the input string.

NOTE: the null terminator '\0' is counted as 2 characters. For example: your input string is "cs61CNL0" where NL is the newline code and 0 the terminator (0 !)

Example output:
Please insert text (max 20 characters): blablabla

The length of the text is: 9
-- program is finished running --

Reset: reset completed.

Please insert text (max 20 characters): cs61C is awesome!

The length of the text is: 17
-- program is finished running --

Please insert text (max 20 characters): 000

The length of the text is: 3
-- program is finished running --