MIPS - write a function to remove blanks

  • Thread starter Thread starter Sasha7440
  • Start date Start date
  • Tags Tags
    Function Mips
AI Thread Summary
The discussion centers on writing MIPS assembly functions to manipulate strings. The primary function, RemoveBlanks(), is designed to take an input string and remove extra spaces, ensuring only single spaces separate words. Examples illustrate the expected input and output formats. Another function, getAlpha(), is proposed to read a string from the keyboard, replacing non-alphabetic characters with spaces, and terminating input with a special character '%', which is replaced by a null terminator. The main program should utilize these functions to read a string, print it, clean it up with RemoveBlanks(), and print the final result. Participants emphasize the importance of attempting code solutions before seeking help and recommend using the MARS assembler for its user-friendly features and comprehensive help resources.
Sasha7440
Messages
1
Reaction score
0
MIPS -- write a function to remove blanks

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.

Examples:
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)

Examples:

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

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
.text
removeBlanks:
sw $ra, -4
sw $fp, -8
move $fp, $sp
addiu $sp, $sp, -8
addi $v0, $0, 8
syscall

** HELP HERE PLEASE***


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


Thanks so much!
 
Technology news on Phys.org


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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top