Class: Haxor::Vm::Cpu::Unit::Logical

Inherits:
Base
  • Object
show all
Defined in:
lib/haxor/vm/cpu/unit/logical.rb

Constant Summary collapse

OP_AND =

0x40

0x40
OP_NEG =

and a, b

0x41
OP_NOT =

neg a

0x42
OP_OR =

not a

0x43
OP_XOR =

or a, b

0x44

Instance Attribute Summary

Attributes inherited from Base

#vm

Instance Method Summary collapse

Methods inherited from Base

#bind_opcode, #dereference, #fetch_cell, #next_cell, #operand, #operands, #replace_cell

Instance Method Details

#op_and ⇒ Object



22
23
24
25
26
27
28
# File 'lib/haxor/vm/cpu/unit/logical.rb', line 22

def op_and
  a, b = operands
  av = @vm.subsystem(:mem).read a
  bv = @vm.subsystem(:mem).read b
  v = av & bv
  @vm.subsystem(:mem).write a, v
end

#op_neg ⇒ Object



30
31
32
33
34
# File 'lib/haxor/vm/cpu/unit/logical.rb', line 30

def op_neg
  a = operand
  av = @vm.subsystem(:mem).read a
  @vm.subsystem(:mem).write a, -av
end

#op_not ⇒ Object



36
37
38
39
40
# File 'lib/haxor/vm/cpu/unit/logical.rb', line 36

def op_not
  a = operand
  av = @vm.subsystem(:mem).read a
  @vm.subsystem(:mem).write a, ~av
end

#op_or ⇒ Object



42
43
44
45
46
47
# File 'lib/haxor/vm/cpu/unit/logical.rb', line 42

def op_or
  a, b = operands
  av = @vm.subsystem(:mem).read a
  bv = @vm.subsystem(:mem).read b
  @vm.subsystem(:mem).write a, (av | bv)
end

#op_xor ⇒ Object



49
50
51
52
53
54
# File 'lib/haxor/vm/cpu/unit/logical.rb', line 49

def op_xor
  a, b = operands
  av = @vm.subsystem(:mem).read a
  bv = @vm.subsystem(:mem).read b
  @vm.subsystem(:mem).write a, (av ^ bv)
end

#register ⇒ Object

0x5f



14
15
16
17
18
19
20
# File 'lib/haxor/vm/cpu/unit/logical.rb', line 14

def register
  bind_opcode OP_AND,     :op_and
  bind_opcode OP_NEG,     :op_neg
  bind_opcode OP_NOT,     :op_not
  bind_opcode OP_OR,      :op_or
  bind_opcode OP_XOR,     :op_xor
end