diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2017-06-19 21:52:30 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2017-06-19 21:52:30 +0200 |
commit | d1dece42509fbaddcdc0cd69ca42733a652930ca (patch) | |
tree | e7a0ad56bde91a651dd113e1f3160aa019748f96 /parse.go | |
parent | dd9743e29cca88ce2c885f2f85bf8536f41bf1e4 (diff) |
...
Diffstat (limited to 'parse.go')
-rw-r--r-- | parse.go | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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 |