Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:20:45+00:00 2026-06-15T03:20:45+00:00

So I am busy writing a MIPS program that will take an input string,

  • 0

So I am busy writing a MIPS program that will take an input string, and then print all possible UNIQUE permutations of that string. (AKA if the word is LoOp, LoOp and LOop are the same).

In order to do this, I know I need to NOT have a newline character on the end of my input string, but I don’t know to make sure it’s not added. Here is what I have so far:

.data


newLine:
    .asciiz "\n"
promptUser:
    .asciiz "Enter a 20 letter or less word:\n"
word:
    .space 21

.text

main:

    la $a0, promptUser
    li $v0, 4       # Ask User for Input
    syscall

    la $a0, word
    li $a1,21       # Max number of characters 20
    li $v0,8
    syscall         # Prompting User

    la $a0,newLine      # Newline   
    li $v0, 4
    syscall

    la $a0, word        # Printing Word
    li $v0, 4
    syscall

The only time a ‘\n’ isn’t included is when the number of letters entered is exactly 20. Any suggestions??

FIX:

This works:

    li $s0,0        # Set index to 0
remove:
    lb $a3,word($s0)    # Load character at index
    addi $s0,$s0,1      # Increment index
    bnez $a3,remove     # Loop until the end of string is reached
    beq $a1,$s0,skip    # Do not remove \n when string = maxlength
    subiu $s0,$s0,2     # If above not true, Backtrack index to '\n'
    sb $0, word($s0)    # Add the terminating character in its place
skip:
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:20:46+00:00Added an answer on June 15, 2026 at 3:20 am

    You can parse the string upon returning from syscall 8 to remove the character:

    # your code to prompt the user        
    
        addu  $a2, $zero, $zero     # i = 0
    loop:
        lbu $a3, word($a2)          # word[i]
        addiu $a2, $a2, 1
        bnez $a3, loop       # Search the NUL char code
    
        beq $a1, $a2, skip   # Check whether the buffer was fully loaded
                             # Otherwise 'remove' the last character
        sb $0, word-2($a2)   # and put a terminating NUL instead
    skip:
    
    # your code continues here
    

    Also note that you didn’t reserve enough space for the word. You should reserve 21 bytes with

    word: .space(21)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm busy writing a Program that Transmits GPS Coordinates to a Server from a
Hl Guys, I am busy writing a backend administrative program for a system that
I'm busy writing a application that refreshes a IFrame completely using javascript, now my
I'm busy working on a windows phone application that calls a servlet that then
I am busy writing a CodeSmith template that has one of its properties as
I've got a java code that is writing a Linux bash script out, then
I'm busy writing a small snippet of code that should allow cross-browser usage of
I just split a C++ program that i'm writing up into multiple files. Now
I am busy writing a program in Visual Basic .NET and I have a
I'm busy writing a servlet that generates HTML code. The goal is to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.