
/*

$0   $zero, $r0   Always zero
$1   $at   Reserved for assembler
$2, $3   $v0, $v1   First and second return values, respectively
$4, ..., $7   $a0, ..., $a3   First four arguments to functions
$8, ..., $15   $t0, ..., $t7   Temporary registers
$16, ..., $23   $s0, ..., $s7   Saved registers
$24, $25   $t8, $t9   More temporary registers
$26, $27   $k0, $k1   Reserved for kernel (operating system)
$28   $gp   Global pointer
$29   $sp   Stack pointer
$30   $fp   Frame pointer
$31   $ra   Return address

JAL in MIPS uses $31 !

  # Initialize register file
  addiu x1, zero, 0           # Return address register, holds link back and is also used to compose long calls with auipc and jalr
  li   x2, returnstackanfang # Stack pointer x2 (sp) is initialized by reset to end of RAM... We may choose another location.
  addiu x3, zero, 42          # TOS
  li   x4, datenstackanfang  # PSP Set data stack pointer
  addiu x5, zero, 0           # Free scratch register, not saved across calls.
  addiu x6, zero, 0           # Free scratch register, not saved across calls.
  addiu x7, zero, 0           # Scratch register, needs to be saved.
  addiu x8, zero, 0           # Loop index
  addiu x9, zero, 0           # Loop limit
  addiu x10, zero, 0          # Scratch register, needs to be saved.
  addiu x11, zero, 0          # Scratch register, needs to be saved.
  addiu x12, zero, 0          # Scratch register, needs to be saved.
  addiu x13, zero, 0          # Scratch register, needs to be saved.
  addiu x14, zero, 0          # Scratch register, needs to be saved.
  addiu x15, zero, 0          # Scratch register, needs to be saved.

  addiu x16, zero, 0          # x16-x31: Unused.
  addiu x17, zero, 0
  addiu x18, zero, 0
  addiu x19, zero, 0
  addiu x20, zero, 0
  addiu x21, zero, 0
  addiu x22, zero, 0
  addiu x23, zero, 0
  addiu x24, zero, 0
  addiu x25, zero, 0
  addiu x26, zero, 0
  addiu x27, zero, 0
  addiu x28, zero, 0
  addiu x29, zero, 0
  addiu x30, zero, 0
  addiu x31, zero, 0

*/


.set zero, $zero
.set x0,   $zero
.set x1,   $31   # Link register is x1 on RISC-V and $31 on MIPS
.set x2,   $2    # Stack pointer is x2 on RISC-V and $29 on MIPS for normal call convention - take care when doing syscalls !
.set sp,   $2    # Another name for stack pointer
.set x3,   $3
.set x4,   $4
.set x5,   $5
.set x6,   $6
.set x7,   $7

.set x8,   $8
.set x9,   $9
.set x10,  $10
.set x11,  $11
.set x12,  $12
.set x13,  $13
.set x14,  $14
.set x15,  $15

# x16-x31 are unused in Mecrisp-Quintus Forth core

.set x16,  $16
.set x17,  $17
.set x18,  $18
.set x19,  $19
.set x20,  $20
.set x21,  $21
.set x22,  $22
.set x23,  $23
.set x24,  $24
.set x25,  $25

.macro call name
  jal \name
.endm

.macro ret
  jr x1
.endm

.macro mv destination, source
  or \destination, \source, zero
.endm

.macro slli p1, p2, p3
  sll \p1, \p2, \p3
.endm

.macro srli p1, p2, p3
  srl \p1, \p2, \p3
.endm

.macro srai p1, p2, p3
  sra \p1, \p2, \p3
.endm

.macro add p1, p2, p3
  addu \p1, \p2, \p3
.endm

.macro addi p1, p2, p3
  addiu \p1, \p2, \p3
.endm

.macro sub p1, p2, p3
  subu \p1, \p2, \p3
.endm
