Actions

Editing MIPS

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 81: Line 81:
 
=== Special registers ===
 
=== Special registers ===
 
There are two more registers. One called '''ra''' (return address) and one called '''sp''' (stack pointer). The '''ra''' is used by certain jump and branching instructions (those ending with '''-al''') to remember which line in the script it should return to. The '''sp''' tracks the next index within the stack (a memory that can store up to 512 values) to be pushed (written) to or popped (read) from. Neither '''ra''' or '''sp''' is protected, their values can be changed by instructions like any other register.
 
There are two more registers. One called '''ra''' (return address) and one called '''sp''' (stack pointer). The '''ra''' is used by certain jump and branching instructions (those ending with '''-al''') to remember which line in the script it should return to. The '''sp''' tracks the next index within the stack (a memory that can store up to 512 values) to be pushed (written) to or popped (read) from. Neither '''ra''' or '''sp''' is protected, their values can be changed by instructions like any other register.
 
==Stack Memory==
 
;push r?: adds the value of register '''r?''' to the stack memory at index '''sp''' and increments the '''sp''' by 1.
 
;pop r?: loads the value in the stack memory at index <code>sp-1</code> into register '''r?''' and decrements the '''sp''' by 1.
 
;peek r?: loads the value in the stack memory at index <code>sp-1</code> into register '''r?'''.
 
 
As mentioned previously, '''sp''' can be both written to and read from any time. When reading ('''peek''' or '''pop'''), '''sp''' must be between 1 and 512, inclusive. While writing ('''push'''), '''sp''' must be between 0 and 511, inclusive.
 
 
Stack memory is persistent on logic chips. This means that if you have a logic chip and push values to the stack, the code that pushes those values can be removed and the stack will retain those values.
 
 
Note that this does not carry over to any other logic chips which receive the program of the original; They will need to have their stack memories programmed individually.
 
 
'''Stack Traversing'''
 
 
Traversing the stack can be done similarly to how an array would be traversed in some other languages:
 
<blockquote>
 
<nowiki />#this will traverse indices {min value} through {max value} - 1
 
 
move sp {min value}
 
 
 
loop:
 
 
add sp sp 1
 
 
peek r0
 
<nowiki />#do something here with your stack values (loaded into r0)
 
 
blt sp {max value} loop
 
 
 
<nowiki />#continue on
 
 
</blockquote>
 
 
Alternatively, you can use the pop function's decrementing to make a more efficient loop:
 
 
<blockquote>
 
move sp {max value}
 
 
add sp sp 1
 
 
 
loop:
 
 
pop r0
 
 
<nowiki />#do something here with your stack values (loaded into r0)
 
 
bgt sp {min value} loop
 
 
 
<nowiki />#continue on
 
 
</blockquote>
 
  
 
==Device Ports==
 
==Device Ports==

Please note that all contributions to Unofficial Stationeers Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Unofficial Stationeers Wiki:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)