Actions

Difference between revisions of "MIPS"

From Unofficial Stationeers Wiki

(Adjusted formatting to (hopefully) improve readability. Added IC10 to keywords.)
Line 2: Line 2:
  
 
<pre>
 
<pre>
 +
IC10
 
l
 
l
 
s
 
s
Line 44: Line 45:
 
yield
 
yield
 
</pre>
 
</pre>
 +
 +
----
  
 
<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>
 +
 +
<br>
  
move    d s    // stores the value of s in d
+
;move     
 +
:d s    // stores the value of s in d
  
add    d s t  // calculates s + t and stores the result in d
+
;add     
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
mul    d s t  // calculates s * t and stores the result in d
+
;sub     
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
mod    d s t  // calculates s mod t and stores the result in d. Note this
+
;mul     
                // doesn't behave like the % operator - the result will be
+
:d s t  // calculates s * t and stores the result in d
                // positive even if the either of the operands are negative
+
;div     
 +
:d s t  // calculates s / t and stores the result in d
 +
;mod     
 +
:d s t   
 +
::// calculates s mod t and stores the result in d. Note this
 +
::// doesn't behave like the % operator - the result will be  
 +
::// positive even if the either of the operands are negative
  
slt    d s t  // stores 1 in d if s < t, 0 otherwise
+
;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
+
;sqrt     
round  d s    // finds the rounded value of s and stores the result in d
+
:d s    // calculates sqrt(s) and stores the result in d
trunc  d s    // finds the truncated value of s and stores the result in d
+
;round   
ceil   d s    // calculates the ceiling of s and stores the result in d
+
:d s    // finds the rounded value of s and stores the result in d
floor   d s    // calculates the floor 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
+
;max  
min     d s t  // calculates the minimum 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
abs     d s    // calculates the absolute value of s and stores the result in d
+
;min  
log     d s    // calculates the natural logarithm of s and stores the result
+
: d s t  // calculates the minimum of s and t and stores the result in d
                // in d
+
;abs  
exp     d s    // calculates the exponential of s and stores the result in d
+
: d s    // calculates the absolute value of s and stores the result in d
rand   d      // selects a random number uniformly at random between 0 and 1
+
;log  
                // inclusive and stores the result in d
+
: d s    // calculates the natural logarithm of s and stores the result
 +
::// 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
 +
::// 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.
and     d s t  // stores 1 in d if both s and t have non-zero values,
+
;and  
                // 0 otherwise
+
: d s t  // stores 1 in d if both s and t have non-zero values,
or     d s t  // stores 1 in d if either s or t have non-zero values,
+
::// 0 otherwise
                // 0 otherwise
+
;or    
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 either s or t have non-zero values,
                // 0 otherwise
+
::// 0 otherwise
nor     d s t  // stores 1 in d if both s and t equal zero, 0 otherwise
+
;xor  
 +
: d s t  // stores 1 in d if exactly one of s and t are non-zero,
 +
::// 0 otherwise
 +
;nor  
 +
:    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
j            a // jumps to line a.
+
;j
bltz      s  a // jumps to line a if s <  0
+
:             a // jumps to line a.
blez     s  a // jumps to line a if s <= 0
+
;bltz
bgez     s  a // jumps to line a if s >= 0
+
:     s  a // jumps to line a if s <  0
bgtz      s  a // jumps to line a if s >  0
+
;blez  
beq       s t a // jumps to line a if s == t
+
:    s  a // jumps to line a if s <= 0
bne       s t a // jumps to line a if s != t
+
;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
  
yield          // ceases code execution for this power tick
+
;yield           
</pre>
+
: // ceases code execution for this power tick
  
 
This is a sample timer command set, alternating between 1 for 1 tick (0.5s), then off for 2 ticks (1s).
 
This is a sample timer command set, alternating between 1 for 1 tick (0.5s), then off for 2 ticks (1s).

Revision as of 18:20, 22 October 2018

Keywords:

IC10
l
s
ls
alias
move
add
sub
slt
and
or
xor
nor
mul
div
mod
j
bltz
bgez
blez
bgtz
beq
bne
jr
brltz
brgez
brlez
brgtz
breq
brne
sqrt
round
trunc
ceil
floor
max
min
abs
log
exp
rand
yield

// 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.


move
d s // stores the value of s in d
add
d s t // calculates s + t and stores the result in d
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
// calculates s mod t and stores the result in d. Note this
// doesn't behave like the % operator - the result will be
// 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
// 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
// inclusive and stores the result in d
// boolean arithmetic uses the C convention that 0 is false and any non-zero
// value is true.
and
d s t // stores 1 in d if both s and t have non-zero values,
// 0 otherwise
or
d s t // stores 1 in d if either s or t have non-zero values,
// 0 otherwise
xor
d s t // stores 1 in d if exactly one of s and t are non-zero,
// 0 otherwise
nor
d s t // stores 1 in d if both s and t equal zero, 0 otherwise


// 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
yield
// ceases code execution for this power tick

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	

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

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