Skip to content

Commit

Permalink
Implement jal
Browse files Browse the repository at this point in the history
  • Loading branch information
schoeberl committed Jul 26, 2024
1 parent e42a542 commit 4b8c5cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions asm/test/jal.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Test jal

loadi <function
loadhi >function
jal r3
load r1
subi 5
scall 0

function:
loadi 5
store r1
load r3
jal r3
3 changes: 3 additions & 0 deletions src/main/scala/leros/Decode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/leros/Leros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/scala/leros/util/Assembler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 4b8c5cd

Please sign in to comment.