title: How Can I Store a String in MIPS using Dynamic Memory?
body: <p>Okay guys, basically the problem I'm having is this.</p>
  
  <p>I've been assigned to write a MIPS program that stores a struct dynamically.</p>
  
  <p>Basically, it stores an ID, a Year, a Title, and a Description
  It's to be stored using a binary search tree.</p>
  
  <p>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.</p>
  
  <p>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 :)</p>
  
  <p>Here is my memory setup:</p>
  
  <p>$s5 - Stores Root Node</p>
  
  <p>$s7 - Stores Size of Tree (Not Necessary)</p>
  
  <p>Each New Item Contains a chunk of 344 bytes</p>
  
  <p>The bytes are setup as such:</p>
  
  <p>8 Bytes - [ID]</p>
  
  <p>8 Bytes - [Year]</p>
  
  <p>64 Bytes - [Title]</p>
  
  <p>256 Bytes - [Description]</p>
  
  <p>8 Bytes - [LastNodeAddress]</p>
  
  <p>8 Bytes - [NextNodeAddress]</p>
  
  <p>Here's the code and you may see the issue:</p>
  
  <pre><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, 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
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>.data
  titlebuffer: .space 64
  descriptionbuffer: .space 256
  </code></pre>
  
  <p>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.</p>
  
  <p>Any help would be greatly appreciated! :)</p>