MIPS - write a function to remove blanks

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

    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!
  2. jcsd
  3. Re: MIPS -- write a function to remove blanks

    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.
Know someone interested in this topic? Share this thead via email, Google+, Twitter, or Facebook

Have something to add?
Similar discussions for: MIPS - write a function to remove blanks