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

  • Home
  • SEARCH
  • 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 7738633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:19:01+00:00 2026-06-01T08:19:01+00:00

Okay guys, basically the problem I’m having is this. I’ve been assigned to write

  • 0

Okay guys, basically the problem I’m having is this.

I’ve been assigned to write a MIPS program that stores a struct dynamically.

Basically, it stores an ID, a Year, a Title, and a Description
It’s to be stored using a binary search tree.

If you’ve ever coded a stack in C++ you know what I’m talking about.
I’ve successfully stored the ID and Titles in memory dynamically,
but I’m having trouble storing the user-entered strings.

This is a complex question and there’s not a lot of info that I’ve
been able to find online so props if you can help me out with this 🙂

Here is my memory setup:

$s5 – Stores Root Node

$s7 – Stores Size of Tree (Not Necessary)

Each New Item Contains a chunk of 344 bytes

The bytes are setup as such:

8 Bytes – [ID]

8 Bytes – [Year]

64 Bytes – [Title]

256 Bytes – [Description]

8 Bytes – [LastNodeAddress]

8 Bytes – [NextNodeAddress]

Here’s the code and you may see the issue:

li $v0, 9           #allocate memory for new record
li $a0, 344         #enough memory for 2 addresses and all the data
syscall


move $s0, $v0           #hang onto the initial address of all our info

li $v0, 4           #prompt for ID
la $a0, addid
syscall

li $v0, 5           #enter integer
syscall

sw $v0, 0($s0)          #store our ID into memory   Offset: 0

li $v0, 4           #prompt for add year
la $a0, addyear
syscall

li $v0, 5           #enter integer
syscall

sw $v0, 4($s0)          #store year into our memory Offset: 4

li $v0, 4           #prompt for add title
la $a0, addtitle
syscall

li $v0, 8           #read title into titlebuffer
la $a0, titlebuffer
li $a1, 64
syscall

sw $a0, 8($s0)          #store title into our memory    Offset: 8

li $v0, 4           #prompt for add description
la $a0, adddescription
syscall

li $v0, 8           #read from input into descriptionbuffer
la $a0, descriptionbuffer
li $a1, 256
syscall

sw $a0, 72($s0)         #store description into our memory  Offset: 72

bne $s7, 0, setlocations    #if this isn't root node let's set the locations

add $s7, $s7, 1         #add 1 to the size of the records

move $s5, $s0           #store this address as root node for now

The problem is that all that’s being stored is the address of the buffers.
The buffers are defined in my data section like this:

.data
titlebuffer: .space 64
descriptionbuffer: .space 256

What I end up with is just the addresses stored in the memory I allocated,
and I have no idea how to store strings into allocated memory.

Any help would be greatly appreciated! 🙂

  • 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-01T08:19:03+00:00Added an answer on June 1, 2026 at 8:19 am

    Don’t bother defining your memory at the start of your program like I showed in the original question.

    Instead, allocate it and read the values into the correct offsets of your dynamic memory.

    Instead of la $a0, descriptionbuffer

    Instead of la $a0, titlebuffer

    Use:

    la $a0, 8($s0)

    la $a0, 72($s0)

    Here I move the memory address into $s0 using move $s0, $v0 and read the values into the correct offsets.

    to print you do the same thing!

    Here is the working code:

    li $v0, 9           #allocate memory for new record
    li $a0, 344         #enough memory for 2 addresses and all the data
    syscall
    
    move $s0, $v0           #hang onto the initial address of all our info
    
    li $v0, 8           #read our title into the allocated space
    la $a0, 8($s0)          #Offset: 8
    li $a1, 64
    syscall
    
    li $v0, 8           #read our description into the allocated space
    la $a0, 72($s0)         #Offset: 72
    li $a1, 256
    syscall 
    

    In addition, you can find the final solution here: https://stackoverflow.com/a/9953839/1274820

    Edit: Well, after 10k views, I decided to add more info here so you don’t have to search through later code

    Here’s the full code to store 4 different pieces of data in memory:

    li $v0, 9           #allocate memory for new record
    li $a0, 344         #[334 = how much memory - in bytes]
    syscall
    
    move $s0, $v0       #store the address of our allocated memory in $s0
    
    li $v0, 5           #enter integer
    syscall
    sw $v0, 0($s0)      #store our ID into memory   Offset: 0
    
    li $v0, 5           #enter integer
    syscall
    sw $v0, 4($s0)      #store year into our memory Offset: 4
    
    li $v0, 8           #read our title into the allocated space
    la $a0, 8($s0)      #Offset: 8
    li $a1, 64
    syscall
    
    li $v0, 8           #read our description into the allocated space
    la $a0, 72($s0)     #Offset: 72
    li $a1, 256
    syscall 
    

    That will store ID, Year, Title, and Description – the offset is where we place the data in the dynamic memory.

    Imagine that I have a block of 334 bytes (like above):

    [ 334 ]

    We store the ID an integer (4 bytes of data) at offset 0 like this:

    [(ID) 330 ]

    Then, we store the year next to it (at offset 4).

    [(ID)(YR) 326 ]

    And so on …

    To print it, do it like this:

    li $v0, 1           #Print the ID stored at $s0     [Offset: 0]
    lw $a0, 0($s0)
    syscall
    li $v0, 1           #Print the Year stored at $s0   [Offset: 4]
    lw $a0, 4($s0)
    syscall
    li $v0, 4           #Print the Title stored at $s0  [Offset: 8]
    la $a0, 8($s0)
    syscall
    li $v0, 4           #Print descript stored at $s0   [Offset: 72]
    la $a0, 72($s0)
    syscall
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, guys i have been trying to define a Stack , each node also
Okay, before you guys go nuts -- this is just a small site, temporary
Okay guys, so I've been stuck for at least 2 days, with googling and
Okay, so here is the basic background. This program connects to outlook/exchange and parses
The eclipse and checkstyle guys of you will surely now this problem: After organizing
Okay guys, I'm sure this has a very simple solution but my searches are
Okay guys, maybe you can help me out with this one. I'm about ready
Hello guys i have a problem streaming PDF files with php, i'm using this
Okay guys I have a database I have been working on for days now.
Hye guys. Okay. I have done this coding. But it seems have error. Can

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.