Class: Haxor::Vm::Cpu::Unit::Arithmetic
- Defined in:
- lib/haxor/vm/cpu/unit/arithmetic.rb
Constant Summary collapse
- OP_ADD =
0x00 (not used)
0x01- OP_SUB =
add a, b
0x02- OP_DIV =
sub a, b
0x03- OP_MUL =
div a
0x04- OP_INC =
mul a
0x05- OP_DEC =
inc a
0x06- OP_CMP =
dec a
0x07
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #op_add ⇒ Object
- #op_cmp ⇒ Object
- #op_dec ⇒ Object
- #op_div ⇒ Object
- #op_inc ⇒ Object
- #op_mul ⇒ Object
- #op_sub ⇒ Object
-
#register ⇒ Object
0x1f.
Methods inherited from Base
#bind_opcode, #dereference, #fetch_cell, #next_cell, #operand, #operands, #replace_cell
Instance Method Details
#op_add ⇒ Object
26 27 28 29 30 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 26 def op_add a, b = operands c = @vm.subsystem(:mem).read(a) + @vm.subsystem(:mem).read(b) @vm.subsystem(:mem).write a, c end |
#op_cmp ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 65 def op_cmp a, b = operands av = @vm.subsystem(:mem).read a bv = @vm.subsystem(:mem).read b v = av - bv @vm.subsystem(:registers).flag Consts::FR_ZERO, v == 0 @vm.subsystem(:registers).flag Consts::FR_SIGN, v < 0 end |
#op_dec ⇒ Object
59 60 61 62 63 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 59 def op_dec a = operand av = @vm.subsystem(:mem).read a @vm.subsystem(:mem).write a, (av - 1) end |
#op_div ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 38 def op_div a = operand av = @vm.subsystem(:mem).read a arv = @vm.subsystem(:registers).read 'ar' @vm.subsystem(:registers).write 'ar', (arv / av) @vm.subsystem(:registers).write 'dr', (arv % av) end |
#op_inc ⇒ Object
53 54 55 56 57 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 53 def op_inc a = operand av = @vm.subsystem(:mem).read a @vm.subsystem(:mem).write a, (av + 1) end |
#op_mul ⇒ Object
46 47 48 49 50 51 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 46 def op_mul a = operand av = @vm.subsystem(:mem).read a arv = @vm.subsystem(:registers).read 'ar' @vm.subsystem(:registers).write 'ar', (arv * av) end |
#op_sub ⇒ Object
32 33 34 35 36 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 32 def op_sub a, b = operands c = @vm.subsystem(:mem).read(a) - @vm.subsystem(:mem).read(b) @vm.subsystem(:mem).write a, c end |
#register ⇒ Object
0x1f
16 17 18 19 20 21 22 23 24 |
# File 'lib/haxor/vm/cpu/unit/arithmetic.rb', line 16 def register bind_opcode OP_ADD, :op_add bind_opcode OP_SUB, :op_sub bind_opcode OP_DIV, :op_div bind_opcode OP_MUL, :op_mul bind_opcode OP_INC, :op_inc bind_opcode OP_DEC, :op_dec bind_opcode OP_CMP, :op_cmp end |