aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-06-19 21:52:30 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-06-19 21:52:30 +0200
commitd1dece42509fbaddcdc0cd69ca42733a652930ca (patch)
treee7a0ad56bde91a651dd113e1f3160aa019748f96
parentdd9743e29cca88ce2c885f2f85bf8536f41bf1e4 (diff)
...
-rw-r--r--parse.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/parse.go b/parse.go
index 3b8bea2..3777c76 100644
--- a/parse.go
+++ b/parse.go
@@ -2,18 +2,24 @@ package j1
import "fmt"
+func isLit(v uint16) bool { return v&(1<<15) != 0 }
+func isJump(v uint16) bool { return v&(7<<13) == 0 }
+func isCond(v uint16) bool { return v&(7<<13) == 1<<13 }
+func isCall(v uint16) bool { return v&(7<<13) == 2<<13 }
+func isALU(v uint16) bool { return v&(7<<13) == 3<<13 }
+
// Decode instruction
func Decode(v uint16) Instruction {
switch {
- case v&(1<<15) != 0:
+ case isLit(v):
return ParseLit(v)
- case v&(7<<13) == 0:
+ case isJump(v):
return ParseJump(v)
- case v&(7<<13) == 1<<13:
+ case isCond(v):
return ParseCond(v)
- case v&(7<<13) == 2<<13:
+ case isCall(v):
return ParseCall(v)
- case v&(7<<13) == 3<<13:
+ case isALU(v):
return ParseALU(v)
}
return nil