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 8598173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:05:30+00:00 2026-06-12T01:05:30+00:00

I am attempting to reverse a string of ints when given size and string.

  • 0

I am attempting to reverse a string of ints when given size and string. Here is what I have so far. I know my problem is in the loop section, mainly in figuring out how to get a pointer to point at the back of the string and move what is contained to where it should go

Any help would be appreciated:

        .data

Size: .word 9 # Size is 9

Vals: .word 1, 2, 3, 4, 5, 6, 7, 8, 9 # Vals[9]={1,2,..}

        .text
main:

la $t1, Size # get the address of variable Size
la $t2, Vals # get the address of variable Vals
lw $t3, 0($t1) # fetch the value of Size to register $t3
sra $t4, $t3, 1 # right shift arithematic, now $t4 contains Size/2
sll $t3, $t3, 2 # left shift logic, now $t3 contains Size*4

loop:
lb $t5, 0($t2)
sb $t0, 36($t2)
sb  $t0, ($t5)
addi $t0, $t0, 4
addi $t5, $t5, -4
bne $t5, $t4, end
j loop

end:

la $t0, Vals # get the address of Vals to $t0
la $t1, Size # get the address of Size to $t1
lw $t3, 0($t1) # get Size to $t3
sll $t3, $t3, 2 # left shift logic, now $t3 contains Size*4
add $t1, $t0, $t3 # $t1=Vals+Size*4 => array bound
li $v0, 1       # service 1 is print integer

lab4:
lw $a0, 0($t0)  # load desired value into argument register $a0
syscall         # print the value in $a0
addi $t0, $t0, 4 # increase array index
bne $t0, $t1, lab4 # check if reach array bound
  • 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-12T01:05:32+00:00Added an answer on June 12, 2026 at 1:05 am

    There are some issues in that loop:

    • You are reading bytes instead of words (use lw/sw instead of lb/sb
    • You are mixing contents with addresses (usage of register $t5)
    • You are adding/subtracting 4 to the contents read instead of the pointers to the array
    • The way you are trying to reverse the array seems wrong as adding 36 (=9×4) would point to a location after the end of the array

    What you should do is use 2 pointers: one which starts pointing to the beginning of the array and another that starts pointing to the end of the array, then read both items and interchange its contents. Now move the the next element in each pointer (one pointer moves ahead and the other move behind), and repeat the process until all the items are processed (that is, when both pointers crosses).

    E.g (snip):

    addu $t7, $t2, $t3 # $t5 contains address of end of string
    
    loop:
      addi $t7, $t7, -4 # moves pointer backwards
      lw $t5, 0($t2)
      lw $t0, 0($t7)
      sw $t5, ($t7)    # interchange
      sw  $t0, ($t2)   # contents
      addi $t2, $t2, 4 # moves pointer forward
      ble $t2, $t7, loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to reverse a string without using the reverse function, classes and
I am attempting to use recursion to reverse a string but the special twist
I am attempting to reverse engineer an LZ1/LZ77 decompression algorithm. The length of an
Attempting to build a C# NPAPI plugin I have found a tutorial which describes
Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files
Attempting/struggling to get registration and sign-up working within an active admin project. I have
Attempting to create a filter select to find schedules with coursedates within a given
I'm attempting to make a function in Ruby that tells if a string is
Attempting to cutover our EF4 solution to EF CTP5, and ran into a problem.
Attempting to parse json from a url requiring login. Including all my code here

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.