Add sqrt instruction
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package vm
|
||||
|
||||
import "math"
|
||||
|
||||
type opHandler func(*State, *Instruction)
|
||||
|
||||
var opHandlers = map[OpCodeType]opHandler{
|
||||
@@ -42,6 +44,8 @@ var opHandlers = map[OpCodeType]opHandler{
|
||||
OpReturn: (*State).handleReturn,
|
||||
OpReturnIfTrue: (*State).handleReturnIfTrue,
|
||||
OpReturnIfFalse: (*State).handleReturnIfFalse,
|
||||
|
||||
OpSqrt: (*State).handleSqrt,
|
||||
}
|
||||
|
||||
func (state *State) handleNoOp(instr *Instruction) {
|
||||
@@ -232,3 +236,8 @@ func (state *State) handleReturnIfFalse(instr *Instruction) {
|
||||
state.handleReturn(instr)
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) handleSqrt(instr *Instruction) {
|
||||
in := state.readUnsigned(instr.Operands[0])
|
||||
state.writeUnsigned(instr.Operands[0], uint64(math.Round(math.Sqrt(float64(in)))))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user