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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top