From 0989bd54f06fe24421804965c147550b9f5c5899 Mon Sep 17 00:00:00 2001 From: bx Date: Fri, 3 Sep 2021 13:58:33 +0100 Subject: [PATCH] added syscall and jalr to assembler, also fixed v1 value --- assembler.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/assembler.rb b/assembler.rb index 115659f..2fe3edd 100644 --- a/assembler.rb +++ b/assembler.rb @@ -6,7 +6,7 @@ def r0() 0 end # zero def at() 1 end # assembler temporary # subroutine return values, may be changed by subroutines -def v0() 2 end ; def v0() 3 end +def v0() 2 end ; def v1() 3 end # subroutine arguments, may be changed by subroutines def a0() 4 end ; def a1() 5 end @@ -193,6 +193,24 @@ class Assembler word op end + # TODO: actually encode "comment" argument + def syscall(comment) + # iiiiii ccccc ccccc ccccc ccccc iiiiii + op = 0b000000_00000_00000_00000_00000_001100 + word op + end + + # TODO: expose the return address storage register + # NOTE: cannot use the same register for both operands + def jalr(reg) + # jumps to addr in j and stores return adr in r + # iiiiii jjjjj ----- rrrrr ----- iiiiii + op = 0b000000_00000_00000_00000_00000_001001 + op |= (reg & 0b11111) << 21 + op |= (ra) << 11 # ra + word op + end + # # # PSEUDO-INSTRUCTIONS # # # def nop word 0x00000000