diff --git a/TODO.md b/TODO.md index ed07881..2de10cf 100644 --- a/TODO.md +++ b/TODO.md @@ -31,7 +31,7 @@ - [ ] loadi (test for sign extension, also high versions) - [ ] out - needed? - [ ] in - needed? - - [ ] jal + - [x] jal - [x] ldind - [x] ldindh - [x] ldindb/ldindh does sign extension diff --git a/asm/test/jal.s b/asm/test/jal.s new file mode 100644 index 0000000..a7162a1 --- /dev/null +++ b/asm/test/jal.s @@ -0,0 +1,14 @@ +// Test jal + + loadi function + jal r3 + load r1 + subi 5 + scall 0 + +function: + loadi 5 + store r1 + load r3 + jal r3 \ No newline at end of file diff --git a/src/main/scala/leros/Decode.scala b/src/main/scala/leros/Decode.scala index 2aa9313..712a09a 100644 --- a/src/main/scala/leros/Decode.scala +++ b/src/main/scala/leros/Decode.scala @@ -216,6 +216,9 @@ class Decode() extends Module { d.isDataAccess := true.B off := instrSignExt << 1 } + is(JAL.U) { + d.nextState := jal + } is(SCALL.U) { d.nextState := scall } diff --git a/src/main/scala/leros/Leros.scala b/src/main/scala/leros/Leros.scala index 3c894df..6fcc8f8 100644 --- a/src/main/scala/leros/Leros.scala +++ b/src/main/scala/leros/Leros.scala @@ -140,7 +140,9 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends LerosBa } is (jal) { - // TODO: write tests first + pcNext := accu + dataMem.io.wr := true.B + dataMem.io.wrData := pcReg + 1.U } is (scall) { diff --git a/src/main/scala/leros/util/Assembler.scala b/src/main/scala/leros/util/Assembler.scala index a0d4aa3..adb696b 100644 --- a/src/main/scala/leros/util/Assembler.scala +++ b/src/main/scala/leros/util/Assembler.scala @@ -49,8 +49,21 @@ object Assembler { var pc = 0 def toInt(s: String): Int = { + + def getSymb(s: String): Int = { + if (pass2) { + symbols(s.drop(1)) + } else { + 0 + } + } + if (s.startsWith("0x")) { Integer.parseInt(s.substring(2), 16) & 0xff + } else if (s.startsWith("<")) { + getSymb(s) & 0xff + } else if (s.startsWith(">")) { + getSymb(s) >> 8 } else { Integer.parseInt(s) & 0xff } @@ -103,6 +116,7 @@ object Assembler { case "brnz" => (BRNZ << 8) + brOff case "brp" => (BRP << 8) + brOff case "brn" => (BRN << 8) + brOff + case "jal" => (JAL << 8) + regNumber(tokens(1)) case "in" => (IN << 8) + toInt(tokens(1)) case "out" => (OUT << 8) + toInt(tokens(1)) case "scall" => (SCALL << 8) + toInt(tokens(1))