Register to reply

MIPS - write a function to remove blanks

by Sasha7440
Tags: blanks, function, mips, remove, write
Share this thread:
Nov2-08, 03:53 PM
P: 1
So I am new to MIPS and I have been working on a program that my brother had for a class a while back ago and I am trying to do the following...

Write a function RemoveBlanks() that inputs an asciz string
consisting of a list of words. The function returns the
string with all extra blanks removed; e.g there should be
only 1 blank separating words.

input "the fat dog ate my sandwich \0"
output "the fat dog ate my sandwich\0"

input " where is my hat\0"
output "where is my hat\0"

There is only argument to the function - the array of characters
that is the string. The result modifies the original string.
e.g the call in c would be void RemoveBanks ( char A[] );

I also want to continue by writing the following....

Write a function getAlpha() to input a string from the keyboard.
Any chars that are not alphabetic (a-z or A-Z) or blanks are replaced
with blanks in the string.

void getAlpha( char A[] , int N)


input from keyboard " where 45 to me 789 Joe%"
output " where to me Joe\0"

Read the string 1 char at a time. (Use the read character syscall.)
Use a special char of % as a flag to denote the end of the input
string. Replace it with a \0 in the output string.

Read a maximum of N chars into the array ( including the \0 )

Then last the main function....

Write a main program that reads in a string from the keyboard
using getAlpha(), prints the string, uses RemoveBanks()
to remove extra blanks and then prints the resulting

Clearly identify each function in the source code. Test the
code on the keyboard input:
" 34 big 45old 674;jack%" (without the " "s)

***** If anyone ould be willing to send me advise or code to look at that would be great! So far I have been able to take some instruction on how to set up the stack and to tear it back down and how to call the system to enter the string. here is what I have ....

.globl removeBlanks
sw $ra, -4
sw $fp, -8
move $fp, $sp
addiu $sp, $sp, -8
addi $v0, $0, 8


move $sp, $fp
lw $ra, -4($sp)
lw $fp, -8($sp)
jr $ra

Thanks so much!
Phys.Org News Partner Science news on
'Smart material' chin strap harvests energy from chewing
King Richard III died painfully on battlefield
Capturing ancient Maya sites from both a rat's and a 'bat's eye view'
Nov8-08, 02:23 AM
P: 18
Well, you'll want to jal around until a condition (aka eof or rather a \0 is encountered at the end of the string). I doubt that anyone here will write this homework assignment for you. If, however you do provide at least an attempt at a solution I can help you, or I'm sure someone else will guide you :)

A word of advice - use the free MARS assembler to initially write your code (even though you're probably using SPIM). The help menu of MARS shows all the MIPS directives, and it also has an explanation of every syscall and how to use them. It will definitely be of help to you.

Then after writing your code, make sure to run it in whatever assembler you're supposed to use, just to double check the functionality.

Good luck.

Register to reply

Related Discussions
MIPS help Programming & Computer Science 7
How do you write equations in a single sine function? Calculus & Beyond Homework 1
Filling in the blanks proof, having some issues! Set Theory Unions/Subsets Calculus & Beyond Homework 1
Blanks in Mohr Titration? Biology, Chemistry & Other Homework 1
Drawing blanks? Forum Feedback & Announcements 0