Class: Haxor::Vm::Cpu::Unit::Jumps

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

Constant Summary collapse

OP_CALL =

0x20

0x20
OP_JMP =

call a

0x21
OP_JE =

jmp a

0x22
OP_JG =

je a

0x23
OP_JGE =

jg a

0x24
OP_JL =

jge a

0x25
OP_JLE =

jl a

0x26
OP_JNE =

jle a

0x27
OP_JNG =

jne a

0x28
OP_JNGE =

jng a

0x29
OP_JNL =

jnge a

0x2a
OP_JNLE =

jnl a

0x2b
OP_RET =

jnle a

0x2c
OP_IRET =

ret

0x2d

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

#fr_if(b) ⇒ Object



40
41
42
43
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 40

def fr_if(b)
  flags = fetch_cell 'fr'
  (flags & b) > 0
end

#op_call ⇒ Object



45
46
47
48
49
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 45

def op_call
  a = operand
  @vm.subsystem(:stack).push 'ip'
  jmp a
end

#op_iret ⇒ Object



110
111
112
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 110

def op_iret
  @vm.subsystem(:stack).pop 'ip'
end

#op_je ⇒ Object



56
57
58
59
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 56

def op_je
  a = operand
  jmp a if fr_if Consts::FR_ZERO
end

#op_jg ⇒ Object



61
62
63
64
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 61

def op_jg
  a = operand
  jmp a if !fr_if(Consts::FR_ZERO) && !fr_if(Consts::FR_SIGN)
end

#op_jge ⇒ Object



66
67
68
69
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 66

def op_jge
  a = operand
  jmp a if !fr_if(Consts::FR_SIGN) || fr_if(Consts::FR_ZERO)
end

#op_jl ⇒ Object



71
72
73
74
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 71

def op_jl
  a = operand
  jmp a if !fr_if(Consts::FR_ZERO) && fr_if(Consts::FR_SIGN)
end

#op_jle ⇒ Object



76
77
78
79
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 76

def op_jle
  a = operand
  jmp a if fr_if(Consts::FR_SIGN) || fr_if(Consts::FR_ZERO)
end

#op_jmp ⇒ Object



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

def op_jmp
  a = operand
  jmp a
end

#op_jne ⇒ Object



81
82
83
84
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 81

def op_jne
  a = operand
  jmp a unless fr_if Consts::FR_ZERO
end

#op_jng ⇒ Object



86
87
88
89
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 86

def op_jng
  a = operand
  jmp a unless !fr_if(Consts::FR_ZERO) && !fr_if(Consts::FR_SIGN)
end

#op_jnge ⇒ Object



91
92
93
94
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 91

def op_jnge
  a = operand
  jmp a unless !fr_if(Consts::FR_SIGN) || fr_if(Consts::FR_ZERO)
end

#op_jnl ⇒ Object



96
97
98
99
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 96

def op_jnl
  a = operand
  jmp a unless !fr_if(Consts::FR_ZERO) && fr_if(Consts::FR_SIGN)
end

#op_jnle ⇒ Object



101
102
103
104
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 101

def op_jnle
  a = operand
  jmp a unless fr_if(Consts::FR_SIGN) || fr_if(Consts::FR_ZERO)
end

#op_ret ⇒ Object



106
107
108
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 106

def op_ret
  @vm.subsystem(:stack).pop 'ip'
end

#register ⇒ Object

0x3f



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/haxor/vm/cpu/unit/jumps.rb', line 23

def register
  bind_opcode OP_CALL,   :op_call
  bind_opcode OP_JMP,    :op_jmp
  bind_opcode OP_JE,     :op_je
  bind_opcode OP_JG,     :op_jg
  bind_opcode OP_JGE,    :op_jge
  bind_opcode OP_JL,     :op_jl
  bind_opcode OP_JLE,    :op_jle
  bind_opcode OP_JNE,    :op_jne
  bind_opcode OP_JNG,    :op_jng
  bind_opcode OP_JNGE,   :op_jnge
  bind_opcode OP_JNL,    :op_jnl
  bind_opcode OP_JNLE,   :op_jnle
  bind_opcode OP_RET,    :op_ret
  bind_opcode OP_IRET,   :op_iret
end