Actions

Difference between revisions of "MIPS"

From Unofficial Stationeers Wiki

m (Links: added link to stationeering.com programmable circuits simulator)
(Replaced // comment notations with #. // no longer appears to function for commenting.)
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
  
 
<pre>
 
<pre>
// Text after a // will be ignored to the end of the line. The amount of white
+
# Text after a # will be ignored to the end of the line. The amount of white
// space between arguments isn't important, but new lines start a new command.
+
# space between arguments isn't important, but new lines start a new command.
 
</pre>
 
</pre>
  
Line 12: Line 12:
 
<div id="alias"></div>
 
<div id="alias"></div>
 
;alias
 
;alias
:alias str r? d? // labels register or device reference with name.  When alias is applied to a device, it will effect what shows on the screws in the IC base.  (housing)
+
:alias str r? d? # labels register or device reference with name.  When alias is applied to a device, it will effect what shows on the screws in the IC base.  (housing)
 
<code>alias vTemperature r0</code>
 
<code>alias vTemperature r0</code>
 
<br>
 
<br>
Line 19: Line 19:
 
<div id="move"></div>
 
<div id="move"></div>
 
;move     
 
;move     
:d s    // stores the value of s in d
+
:d s    # stores the value of s in d
 
<code>move r0 42 # Store 42 in register 0</code>
 
<code>move r0 42 # Store 42 in register 0</code>
  
 
<div id="add"></div>
 
<div id="add"></div>
 
;add     
 
;add     
:d s t  // calculates s + t and stores the result in d
+
:d s t  # calculates s + t and stores the result in d
 
<code>add r0 r1 1 # add 1 to r1 and store the result as r0</code>
 
<code>add r0 r1 1 # add 1 to r1 and store the result as r0</code>
 
<br>
 
<br>
Line 30: Line 30:
 
<div id="sub"></div>
 
<div id="sub"></div>
 
;sub     
 
;sub     
:d s t  // calculates s - t and stores the result in d
+
:d s t  # calculates s - t and stores the result in d
 
<div id="mul"></div>
 
<div id="mul"></div>
 
;mul     
 
;mul     
:d s t  // calculates s * t and stores the result in d
+
:d s t  # calculates s * t and stores the result in d
 
<div id="div"></div>
 
<div id="div"></div>
 
;div     
 
;div     
:d s t  // calculates s / t and stores the result in d
+
:d s t  # calculates s / t and stores the result in d
 
<div id="mod"></div>
 
<div id="mod"></div>
 
;mod     
 
;mod     
 
:d s t   
 
:d s t   
::// calculates s mod t and stores the result in d. Note this
+
::# calculates s mod t and stores the result in d. Note this
::// doesn't behave like the % operator - the result will be  
+
::# doesn't behave like the % operator - the result will be  
::// positive even if the either of the operands are negative
+
::# positive even if the either of the operands are negative
  
 
<div id="slt"></div>
 
<div id="slt"></div>
 
;slt     
 
;slt     
:d s t  // stores 1 in d if s < t, 0 otherwise
+
:d s t  # stores 1 in d if s < t, 0 otherwise
  
 
<div id="sqrt"></div>
 
<div id="sqrt"></div>
 
;sqrt     
 
;sqrt     
:d s    // calculates sqrt(s) and stores the result in d
+
:d s    # calculates sqrt(s) and stores the result in d
 
<div id="round"></div>
 
<div id="round"></div>
 
;round   
 
;round   
:d s    // finds the rounded value of s and stores the result in d
+
:d s    # finds the rounded value of s and stores the result in d
 
<div id="trunc"></div>
 
<div id="trunc"></div>
 
;trunc   
 
;trunc   
:d s    // finds the truncated value of s and stores the result in d
+
:d s    # finds the truncated value of s and stores the result in d
 
<div id="ceil"></div>
 
<div id="ceil"></div>
 
;ceil   
 
;ceil   
: d s    // calculates the ceiling of s and stores the result in d
+
: d s    # calculates the ceiling of s and stores the result in d
 
<div id="floor"></div>
 
<div id="floor"></div>
 
;floor   
 
;floor   
: d s    // calculates the floor of s and stores the result in d
+
: d s    # calculates the floor of s and stores the result in d
  
 
<div id="max"></div>
 
<div id="max"></div>
 
;max     
 
;max     
: d s t  // calculates the maximum of s and t and stores the result in d
+
: d s t  # calculates the maximum of s and t and stores the result in d
 
<div id="min"></div>
 
<div id="min"></div>
 
;min     
 
;min     
: d s t  // calculates the minimum of s and t and stores the result in d
+
: d s t  # calculates the minimum of s and t and stores the result in d
 
<div id="abs"></div>
 
<div id="abs"></div>
 
;abs     
 
;abs     
: d s    // calculates the absolute value of s and stores the result in d
+
: d s    # calculates the absolute value of s and stores the result in d
 
<div id="log"></div>
 
<div id="log"></div>
 
;log     
 
;log     
: d s    // calculates the natural logarithm of s and stores the result
+
: d s    # calculates the natural logarithm of s and stores the result
::// in d
+
::# in d
 
<div id="exp"></div>
 
<div id="exp"></div>
 
;exp     
 
;exp     
: d s    // calculates the exponential of s and stores the result in d
+
: d s    # calculates the exponential of s and stores the result in d
 
<div id="rand"></div>
 
<div id="rand"></div>
 
;rand   
 
;rand   
: d      // selects a random number uniformly at random between 0 and 1
+
: d      # selects a random number uniformly at random between 0 and 1
::// inclusive and stores the result in d
+
::# inclusive and stores the result in d
  
::// boolean arithmetic uses the C convention that 0 is false and any non-zero
+
::# boolean arithmetic uses the C convention that 0 is false and any non-zero
::// value is true.
+
::# value is true.
 
<div id="and"></div>
 
<div id="and"></div>
 
;and     
 
;and     
: d s t  // stores 1 in d if both s and t have non-zero values,
+
: d s t  # stores 1 in d if both s and t have non-zero values,
::// 0 otherwise
+
::# 0 otherwise
 
<div id="or"></div>
 
<div id="or"></div>
 
;or     
 
;or     
: d s t  // stores 1 in d if either s or t have non-zero values,
+
: d s t  # stores 1 in d if either s or t have non-zero values,
::// 0 otherwise
+
::# 0 otherwise
 
<div id="xor"></div>
 
<div id="xor"></div>
 
;xor     
 
;xor     
: d s t  // stores 1 in d if exactly one of s and t are non-zero,
+
: d s t  # stores 1 in d if exactly one of s and t are non-zero,
::// 0 otherwise
+
::# 0 otherwise
 
<div id="nor"></div>
 
<div id="nor"></div>
 
;nor  
 
;nor  
:    d s t  // stores 1 in d if both s and t equal zero, 0 otherwise
+
:    d s t  # stores 1 in d if both s and t equal zero, 0 otherwise
  
  
// Lines are numbered starting at zero
+
# Lines are numbered starting at zero
 
<div id="j"></div>
 
<div id="j"></div>
 
;j
 
;j
:            a // jumps to line a.
+
:            a # jumps to line a.
 
<div id="bltz"></div>
 
<div id="bltz"></div>
 
;bltz
 
;bltz
:      s  a // jumps to line a if s <  0
+
:      s  a # jumps to line a if s <  0
 
<div id="blez"></div>
 
<div id="blez"></div>
 
;blez  
 
;blez  
:    s  a // jumps to line a if s <= 0
+
:    s  a # jumps to line a if s <= 0
  
 
<div id="bgez"></div>
 
<div id="bgez"></div>
 
;bgez  
 
;bgez  
:    s  a // jumps to line a if s >= 0
+
:    s  a # jumps to line a if s >= 0
 
<div id="bgtz"></div>
 
<div id="bgtz"></div>
 
;bgtz
 
;bgtz
:      s  a // jumps to line a if s >  0
+
:      s  a # jumps to line a if s >  0
 
<div id="beq"></div>
 
<div id="beq"></div>
 
;beq  
 
;beq  
:      s t a // jumps to line a if s == t
+
:      s t a # jumps to line a if s == t
 
<div id="bne"></div>
 
<div id="bne"></div>
 
;bne  
 
;bne  
:      s t a // jumps to line a if s != t
+
:      s t a # jumps to line a if s != t
 
<div id="bdseal"></div>
 
<div id="bdseal"></div>
 
;bdseal
 
;bdseal
:    d? a(r?|num) // Jump execution to line a and store current line number if device d? is set.
+
:    d? a(r?|num) # Jump execution to line a and store current line number if device d? is set.
 
<code>bdseal d0 32 #Store line number and jump to line 32 if d0 is assigned.</code>
 
<code>bdseal d0 32 #Store line number and jump to line 32 if d0 is assigned.</code>
 
<BR>
 
<BR>
Line 136: Line 136:
 
<div id="yield"></div>
 
<div id="yield"></div>
 
;yield           
 
;yield           
: // ceases code execution for this power tick
+
: # ceases code execution for this power tick
  
 
<div id="#"></div>
 
<div id="#"></div>
 
; #
 
; #
:    // The following text will be ignored during compiling; use this to create comments.
+
:    # The following text will be ignored during compiling; use this to create comments.
  
  
Line 294: Line 294:
  
 
==Slot Variables==
 
==Slot Variables==
 +
In general (always?) slots are assigned as follows.
 +
:Slot 0: Import
 +
:Slot 1: Export
 +
:Slot 2: Inside Machine
 
-----
 
-----
  
Line 335: Line 339:
 
:<code>ls r0 d0 0 Mature # Store 1 in r0 if d0 has a mature crop</code>
 
:<code>ls r0 d0 0 Mature # Store 1 in r0 if d0 has a mature crop</code>
 
:<code>ls vMature dThisVictim 0 Mature # Store 1 in vMature if dThisVictim has a mature crop</code>
 
:<code>ls vMature dThisVictim 0 Mature # Store 1 in vMature if dThisVictim has a mature crop</code>
 
 
 
 
  
 
==Examples==
 
==Examples==
Line 429: Line 429:
  
 
<pre>
 
<pre>
move r0 0 // Line 0: move the value 0 to register0
+
move r0 0 # Line 0: move the value 0 to register0
sub r1 r0 3 // Line 1: subtract 3 from the value in r0 and write it to r1
+
sub r1 r0 3 # Line 1: subtract 3 from the value in r0 and write it to r1
bltz r1 4 // Line 2: jump to line 4 if r1 < 0 (skip the next line)
+
bltz r1 4 # Line 2: jump to line 4 if r1 < 0 (skip the next line)
move r0 0 // Line 3: move the value 0 to register0  
+
move r0 0 # Line 3: move the value 0 to register0  
slt o r0 1 // Line 4: if r0 < 1 write 1 to the output, otherwise 0.
+
slt o r0 1 # Line 4: if r0 < 1 write 1 to the output, otherwise 0.
add r0 r0 1 // Line 5: increment r0 by 1
+
add r0 r0 1 # Line 5: increment r0 by 1
yield // Line 6: wait until next power tick (0.5s)
+
yield # Line 6: wait until next power tick (0.5s)
j 1 // Line 7: jump back to line 1
+
j 1 # Line 7: jump back to line 1
  
 
##########
 
##########

Latest revision as of 18:30, 11 July 2019

MIPS scripting language for IC10 housings / chips[edit]

# Text after a # will be ignored to the end of the line. The amount of white
# space between arguments isn't important, but new lines start a new command.


Functions[edit]


alias
alias str r? d? # labels register or device reference with name. When alias is applied to a device, it will effect what shows on the screws in the IC base. (housing)

alias vTemperature r0
alias dAutoHydro1 d0

move
d s # stores the value of s in d

move r0 42 # Store 42 in register 0

add
d s t # calculates s + t and stores the result in d

add r0 r1 1 # add 1 to r1 and store the result as r0
add r0 r0 1 # increment r0 by one

sub
d s t # calculates s - t and stores the result in d
mul
d s t # calculates s * t and stores the result in d
div
d s t # calculates s / t and stores the result in d
mod
d s t
  1. calculates s mod t and stores the result in d. Note this
  2. doesn't behave like the % operator - the result will be
  3. positive even if the either of the operands are negative
slt
d s t # stores 1 in d if s < t, 0 otherwise
sqrt
d s # calculates sqrt(s) and stores the result in d
round
d s # finds the rounded value of s and stores the result in d
trunc
d s # finds the truncated value of s and stores the result in d
ceil
d s # calculates the ceiling of s and stores the result in d
floor
d s # calculates the floor of s and stores the result in d
max
d s t # calculates the maximum of s and t and stores the result in d
min
d s t # calculates the minimum of s and t and stores the result in d
abs
d s # calculates the absolute value of s and stores the result in d
log
d s # calculates the natural logarithm of s and stores the result
  1. in d
exp
d s # calculates the exponential of s and stores the result in d
rand
d # selects a random number uniformly at random between 0 and 1
  1. inclusive and stores the result in d
  1. boolean arithmetic uses the C convention that 0 is false and any non-zero
  2. value is true.
and
d s t # stores 1 in d if both s and t have non-zero values,
  1. 0 otherwise
or
d s t # stores 1 in d if either s or t have non-zero values,
  1. 0 otherwise
xor
d s t # stores 1 in d if exactly one of s and t are non-zero,
  1. 0 otherwise
nor
d s t # stores 1 in d if both s and t equal zero, 0 otherwise


  1. Lines are numbered starting at zero
j
a # jumps to line a.
bltz
s a # jumps to line a if s < 0
blez
s a # jumps to line a if s <= 0
bgez
s a # jumps to line a if s >= 0
bgtz
s a # jumps to line a if s > 0
beq
s t a # jumps to line a if s == t
bne
s t a # jumps to line a if s != t
bdseal
d? a(r?|num) # Jump execution to line a and store current line number if device d? is set.

bdseal d0 32 #Store line number and jump to line 32 if d0 is assigned.
bdseal dThisVictim HarvestCrop #Store line in ra and jump to sub HarvestCrop if device dThisVictim is assigned.

yield
# ceases code execution for this power tick
#
# The following text will be ignored during compiling; use this to create comments.



Device Variables[edit]


Activate
1 if device is activated (usually means running), otherwise 0
l r0 d0 Activate # sets r0 to 1 if on or 0 of off
AirRelease
Charge
The current charge the device has.
CLearMemory
When set to 1, clears the counter memory (e.g. ExportCount). Will set itself back to 0 when triggered.
Color
CompletionRatio
ElevatorLevel
ElevatorSpeed
Error
1 if device is in error state, otherwise 0
ExportCount
How many items exporfted since last ClearMemory.
Filtration
The current state of the filtration system. For example filtration = 1 for a Hardsuit when filtration is On.
Harvest
Performs the harvesting action for any plant based machinery.
s d0 Harvest 1 # Performs 1 harvest action on device d0
Horizontal
HorizontalRatio
Idle
ImportCount
Lock
Maximum
Mode
On
Open
Output
Plant
Performs the planting operation for any plant based machinery.
s d0 Plant 1 # Plants one crop in device d0
PositionX
PositionY
PositionZ
Power
PowerActual
PowerPotential
PowerRequired
Pressure
PressureExternal
PressureInteral
PressureSetting
Quantity
Total quantity in the device.
Ratio
Context specific value depending on device, 0 to 1 based ratio.
RatioCarbonDioxide
RatioNitrogen
The ratio of nitrogen in device atmosphere.
RatioOxygen
The ratio of oxygen in device atmosphere.
RatioPollutant
The ratio of pollutant in device atmosphere.
RatioVolatiles
The ratio of volatiles in device atmosphere.
RatioWater
The ratio of water in device atmosphere.
Reagents
RecipeHash
RequestHash
RequiredPower
Setting
SolarAngle
Solar angle of the device.
l r0 d0 SolarAngle # Sets r0 to the solar angle of d0.
Temperature
TemperatureSettings
TotalMoles
VelocityMagnitude
VelocityRelativeX
VelocityRelativeY
VelocityRelativeZ
Vertical
Vertical setting of the device.
VerticalRatio
Ratio of vertical setting for device.
Volume
Returns the device atmosphere volume



Slot Variables[edit]

In general (always?) slots are assigned as follows.

Slot 0: Import
Slot 1: Export
Slot 2: Inside Machine


Occupied
ls r0 d0 2 Occupied #Stores 1 in r0 if d0 has more seeds
ls vOccupied dThisVictim 2 Occupied #stores 1 in vOccupied if dThisVictim has more seeds
OccupantHash
Quantity
Damage
Efficiency
Health
Growth
ls r0 d0 0 Growth # Store the numerical growth stage of d0 in r0
Pressure
Temperature
Charge
ChargeRatio
Class
PressureWaste
PressureAir
MaxQuantity
Mature
ls r0 d0 0 Mature # Store 1 in r0 if d0 has a mature crop
ls vMature dThisVictim 0 Mature # Store 1 in vMature if dThisVictim has a mature crop

Examples[edit]



This example script automates autohydro units and powers the lights off during the day when they're not needed. (Hit Expand)[edit]

Uses aliases, sub-routines and comments to minimize lines of code and adaptability.

alias vMature r0​
alias vOccupied r1​
alias isDayLight r2​
alias isOccupied r3​
alias dSensor d5​
​
​
#start of Program Loop​
start:​
l isDayLight dSensor Activate​  #Check if it's daytime or not.
​
# For each device, harvest, plant, powerdown, then power on depending on conditions.
alias dThisVictim d0​  #Begin processing device 0
bdseal dThisVictim HarvestCrop​
bdseal dThisVictim PlantCrop​
bgtzal isDayLight PowerDown​
blezal isDayLight TurnitOn​
alias dThisVictim d1​  #Begin processing device 1
bdseal dThisVictim HarvestCrop​
bdseal dThisVictim PlantCrop​
bgtzal isDayLight PowerDown​
blezal isDayLight TurnitOn​
alias dThisVictim d2​  #Begin processing device 2
bdseal dThisVictim HarvestCrop​
bdseal dThisVictim PlantCrop​
bgtzal isDayLight PowerDown​
blezal isDayLight TurnitOn​
alias dThisVictim d3​  #Begin processing device 3
bdseal dThisVictim HarvestCrop​
bdseal dThisVictim PlantCrop​
bgtzal isDayLight PowerDown​
blezal isDayLight TurnitOn​
alias dThisVictim d4​  #Begin processing device 4
bdseal dThisVictim HarvestCrop​
bdseal dThisVictim PlantCrop​
bgtzal isDayLight PowerDown​
blezal isDayLight TurnitOn​
#Can't do a D5 because that's our sensor.​
​
j start​ #Return to the beginning of the program loop.  (Yields here may save processing power)
​
​​
HarvestCrop:​
ls vMature dThisVictim 0 Mature​
blez vMature ra​  #If the crop is not mature, return
s dThisVictim Harvest 1​ #If the crop is mature, harvest it (one).
j ra​ #return
​

PlantCrop:​
ls vOccupied dThisVictim 2 Occupied #seeds to plant​
blez vOccupied ra​ #If the machine has no seeds to plant, return.
ls vOccupied dThisVictim 0 Occupied #something growin​g
bgtz vOccupied ra​  # If the crop plot is occupied, return.
s dThisVictim Plant 1​  # if we made it this far, plant the crop
j ra​ #return
​
​
​
PowerDown:​
s dThisVictim On 0​ #Power the machine down.
​
j ra #Jump to line we came from​
​
​
TurnitOn:​
s dThisVictim On 1​ #Power the machine up
j ra

##########
#### End Script
##########




This is a sample timer command set, alternating between 1 for 1 tick (0.5s), then off for 2 ticks (1s).

move r0 0		# Line 0: move the value 0 to register0
sub r1 r0 3		# Line 1: subtract 3 from the value in r0 and write it to r1
bltz r1 4		# Line 2: jump to line 4 if r1 < 0 (skip the next line)
move r0 0		# Line 3: move the value 0 to register0 
slt o r0 1		# Line 4: if r0 < 1 write 1 to the output, otherwise 0.
add r0 r0 1		# Line 5: increment r0 by 1
yield			# Line 6: wait until next power tick (0.5s)
j 1			# Line 7: jump back to line 1	

##########
#### End Script
##########

Example:

so you will do l r0 d0 SolarAngle
Sorry had last args swapped
That would read in the value
while,
s d1 Vertical r0
Would write the contents of r0 into the devices 1's Vertical property
additionally you can make some aliases
alias SolarSensor d0
l r0 SolarSensor SolarAngle

##########
#### End Script
##########

Another example:

Now the IC is inserted into the housing. The screws D0-D5 can be adjusted directly to the equipment (sensor, console, solar panel, etc.). The ports 'o' and 'i0-i2' have been removed. Instead, commands that directly read and write hardware parameters are added.
l <register> <data_channel> <parameter>
 reads the value of the parameter
s <data_channel> <parameter> <register_or_value>
 writes the value of the parameter
ls <register> <data_channel> <slot_number> <parameter> 
 reads the parameter value from the slot
For example, 
l r0 d0 Horizontal
 
s d5 Activate 1
 
ls r3 db 0 OccupantHash

##########
#### End Script
##########

Links[edit]


  • [1] Stationeering.com offers a programmable circuits simulator so you can develop your code without repeatedly dying in game!
  • [2]
  • [3]

Index[edit]


Functions


Device Variables

Slot Variables