You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ops.go 829B

1234567891011121314151617181920212223
  1. package intcode
  2. // OpcodeFunc is a function that describes an opcode implemented in the VM.
  3. type OpcodeFunc = func(vm *VirtualMachine, args []int)
  4. // AddOpcode takes the values from the memory addresses given by args 1 and 2, adds them together,
  5. // and stores at the memory address given by arg 3.
  6. func AddOpcode(vm *VirtualMachine, args []int) {
  7. vm.Memory[args[2]] = vm.Memory[args[0]] + vm.Memory[args[1]]
  8. vm.ip += 4
  9. }
  10. // MulOpcode takes the values from the memory addresses given by args 1 and 2, muliplies them together,
  11. // and stores at the memory address given by arg 3.
  12. func MulOpcode(vm *VirtualMachine, args []int) {
  13. vm.Memory[args[2]] = vm.Memory[args[0]] * vm.Memory[args[1]]
  14. vm.ip += 4
  15. }
  16. // HaltOpcode halts the VM and takes no arguments.
  17. func HaltOpcode(vm *VirtualMachine, args []int) {
  18. vm.Halted = true
  19. }