class Ronin::ASM::MemoryOperand

Represents a Memory Operand.

@see asm.sourceforge.net/articles/linasm.html#Memory

Public Class Methods

new(base=nil,offset=0,index=nil,scale=1,width=nil) click to toggle source

Creates a new Memory Operand.

@param [Register, nil] base

The base of the value.

@param [Integer] offset

The fixed offset to add to the `base`.

@param [Register, nil] index

The variable index to multiple by `scale`, then add to `base.

@param [Integer] scale

The scale to multiple `index` by.

@raise [TypeError]

`base` or `index` was not a {Register} or `nil`.
Calls superclass method
# File lib/ronin/asm/memory_operand.rb, line 51
def initialize(base=nil,offset=0,index=nil,scale=1,width=nil)
  unless (base.nil? || base.kind_of?(Register))
    raise(TypeError,"base must be a Register or nil")
  end

  unless offset.kind_of?(Integer)
    raise(TypeError,"offset must be an Integer")
  end

  unless (index.nil? || index.kind_of?(Register))
    raise(TypeError,"index must be a Register or nil")
  end

  unless scale.kind_of?(Integer)
    raise(TypeError,"scale must be an Integer")
  end

  if base
    width ||= base.width
  end

  super(base,offset,index,scale,width)
end

Public Instance Methods

+(offset) click to toggle source

Adds to the offset of the Memory Operand.

@param [Integer] offset

The offset to add to the Memory Operand.

@return [MemoryOperand]

The new Memory Operand.
# File lib/ronin/asm/memory_operand.rb, line 84
def +(offset)
  MemoryOperand.new(
    self.base,
    self.offset + offset,
    self.index,
    self.scale,
    self.width
  )
end
-(offset) click to toggle source

Subtracts from the offset of the Memory Operand.

@param [Integer] offset

The offset to subject from the Memory Operand.

@return [Memoryoperand]

The new Memory Operand.
# File lib/ronin/asm/memory_operand.rb, line 103
def -(offset)
  MemoryOperand.new(
    self.base,
    self.offset - offset,
    self.index,
    self.scale,
    self.width
  )
end