Class: Ragweed::Rasm::Register

Inherits:
Object
  • Object
show all
Defined in:
lib/ragweed/rasm/isa.rb

Overview

A register target encoding, including [EAX+10] disp/indir

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, opts = {}) ⇒ Register

Returns a new instance of Register.



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ragweed/rasm/isa.rb', line 118

def initialize(code, opts={})
  @combined = false
  @code = code
  @disp = opts[:disp]
  @indir = opts[:indir]
  @byte = opts[:byte]
  @index = nil
  @scale = nil

  @indir = true if @disp
  disp = 0 if (@indir and not @disp)
end

Instance Attribute Details

#byteObject

Returns the value of attribute byte.



32
33
34
# File 'lib/ragweed/rasm/isa.rb', line 32

def byte
  @byte
end

#codeObject

Returns the value of attribute code.



29
30
31
# File 'lib/ragweed/rasm/isa.rb', line 29

def code
  @code
end

#combinedObject

Returns the value of attribute combined.



34
35
36
# File 'lib/ragweed/rasm/isa.rb', line 34

def combined
  @combined
end

#dispObject

Returns the value of attribute disp.



30
31
32
# File 'lib/ragweed/rasm/isa.rb', line 30

def disp
  @disp
end

#indexObject

Returns the value of attribute index.



33
34
35
# File 'lib/ragweed/rasm/isa.rb', line 33

def index
  @index
end

#indirObject

Returns the value of attribute indir.



31
32
33
# File 'lib/ragweed/rasm/isa.rb', line 31

def indir
  @indir
end

#scaleObject

Returns the value of attribute scale.



35
36
37
# File 'lib/ragweed/rasm/isa.rb', line 35

def scale
  @scale
end

Class Method Details

.comb(rc1, rc2) ⇒ Object



39
40
41
# File 'lib/ragweed/rasm/isa.rb', line 39

def self.comb(rc1, rc2)
  (rc1 << 8|rc2)
end

.eax(opts = {}) ⇒ Object



109
# File 'lib/ragweed/rasm/isa.rb', line 109

def self.eax(opts={}); Eax.clone.regopts opts; end

.ebp(opts = {}) ⇒ Object



114
# File 'lib/ragweed/rasm/isa.rb', line 114

def self.ebp(opts={}); Ebp.clone.regopts opts; end

.ebx(opts = {}) ⇒ Object



112
# File 'lib/ragweed/rasm/isa.rb', line 112

def self.ebx(opts={}); Ebx.clone.regopts opts; end

.ecx(opts = {}) ⇒ Object



110
# File 'lib/ragweed/rasm/isa.rb', line 110

def self.ecx(opts={}); Ecx.clone.regopts opts; end

.edi(opts = {}) ⇒ Object



116
# File 'lib/ragweed/rasm/isa.rb', line 116

def self.edi(opts={}); Edi.clone.regopts opts; end

.edx(opts = {}) ⇒ Object



111
# File 'lib/ragweed/rasm/isa.rb', line 111

def self.edx(opts={}); Edx.clone.regopts opts; end

.esi(opts = {}) ⇒ Object



115
# File 'lib/ragweed/rasm/isa.rb', line 115

def self.esi(opts={}); Esi.clone.regopts opts; end

.esp(opts = {}) ⇒ Object



113
# File 'lib/ragweed/rasm/isa.rb', line 113

def self.esp(opts={}); Esp.clone.regopts opts; end

Instance Method Details

#*(x) ⇒ Object

Raises:



57
58
59
60
61
62
63
64
# File 'lib/ragweed/rasm/isa.rb', line 57

def *(x)
  if x.kind_of? Numeric
    ret = clone
    ret.scale = x
    return ret
  end
  raise BadArg, "bad operand type for *"
end

#+(x) ⇒ Object

Raises:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ragweed/rasm/isa.rb', line 66

def +(x)
  if x.kind_of? Numeric
    ret = clone
    ret.disp = x
    return ret
  elsif x.kind_of? Register
    ret = clone
    ret.combined = true
    ret.indir = 1
    ret.scale = x.scale
    ret.code = self.class.comb(ret.code, x.code)
    return ret
  end

  raise BadArg, "bad operand type for +"
end

#-(x) ⇒ Object



83
84
85
86
87
# File 'lib/ragweed/rasm/isa.rb', line 83

def -(x)
  ret = clone
  ret.disp = -x
  return ret
end

#combined?Boolean

Returns:

  • (Boolean)


44
# File 'lib/ragweed/rasm/isa.rb', line 44

def combined?; @combined; end

#displace(disp) ⇒ Object



131
132
133
134
# File 'lib/ragweed/rasm/isa.rb', line 131

def displace(disp)
  @disp = disp
  @indir = true
end

#reg1Object



45
46
47
48
49
50
51
# File 'lib/ragweed/rasm/isa.rb', line 45

def reg1
  if combined?
    self.class.new((code>>8)&0xff)
  else
    self
  end
end

#reg2Object



53
54
55
# File 'lib/ragweed/rasm/isa.rb', line 53

def reg2
  self.class.new(code&0xFF)
end

#regopts(opts = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ragweed/rasm/isa.rb', line 89

def regopts(opts={})
  if (v = opts[:disp])
    @disp = v
  end

  if (v = opts[:indir])
    @indir = v
  end

  if (v = opts[:byte])
    @byte = v
  end

  if (v = opts[:index])
    @index = v
  end

  return self
end

#scaled?Boolean

Returns:

  • (Boolean)


43
# File 'lib/ragweed/rasm/isa.rb', line 43

def scaled?; @scale and @scale > 0; end