Bit shift operators

This commit is contained in:
Ian Gulliver
2021-11-19 17:04:11 -10:00
parent e2dafcf21a
commit c536961df3
4 changed files with 66 additions and 18 deletions

View File

@@ -18,6 +18,9 @@ var opHandlers = map[OpCodeType]opHandler{
OpOr: (*State).handleOr,
OpXor: (*State).handleXor,
OpShiftRight: (*State).handleShiftRight,
OpShiftLeft: (*State).handleShiftLeft,
OpIsEqual: (*State).handleIsEqual,
OpIsLessThanUnsigned: (*State).handleIsLessThanUnsigned,
OpIsLessThanSigned: (*State).handleIsLessThanSigned,
@@ -102,6 +105,18 @@ func (state *State) handleXor(instr *Instruction) {
state.writeUnsigned(&instr.Operand1, in1^in2)
}
func (state *State) handleShiftRight(instr *Instruction) {
in1 := state.readUnsigned(&instr.Operand1)
in2 := state.readUnsigned(&instr.Operand2)
state.writeUnsigned(&instr.Operand1, in1>>in2)
}
func (state *State) handleShiftLeft(instr *Instruction) {
in1 := state.readUnsigned(&instr.Operand1)
in2 := state.readUnsigned(&instr.Operand2)
state.writeUnsigned(&instr.Operand1, in1<<in2)
}
func (state *State) handleIsEqual(instr *Instruction) {
in1 := state.readUnsigned(&instr.Operand1)
in2 := state.readUnsigned(&instr.Operand2)