Class: ECUTools::Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/instruction.rb

Instance Method Summary collapse

Constructor Details

#initialize(address, bytes, assembly) ⇒ Instruction

Returns a new instance of Instruction.



4
5
6
7
8
9
10
# File 'lib/instruction.rb', line 4

def initialize(address, bytes, assembly)
  @address = address
  @bytes = bytes
  @assembly = assembly
  @comments = []
  @data = !(/unknown/.match(assembly).nil?)
end

Instance Method Details

#addressObject



19
20
21
# File 'lib/instruction.rb', line 19

def address
  @address
end

#assemblyObject



31
32
33
# File 'lib/instruction.rb', line 31

def assembly
  @assembly
end

#assembly=(value) ⇒ Object



35
36
37
38
# File 'lib/instruction.rb', line 35

def assembly=(value)
  @assembly = value
  # TODO: Update bytes based on assembly instructions
end

#binaryObject



40
41
42
# File 'lib/instruction.rb', line 40

def binary
  @bytes.join.to_a.pack("H*")
end

#bytesObject



44
45
46
# File 'lib/instruction.rb', line 44

def bytes
  @bytes
end

#commentsObject



48
49
50
# File 'lib/instruction.rb', line 48

def comments
  @comments
end

#dataObject



23
24
25
# File 'lib/instruction.rb', line 23

def data
  @data
end

#data=(val) ⇒ Object



27
28
29
# File 'lib/instruction.rb', line 27

def data=(val)
  @data=val
end

#to_sObject



12
13
14
15
16
17
# File 'lib/instruction.rb', line 12

def to_s
  s = "0x#{@address}:\t#{@bytes.join(' ')}"
  s << "\t#{@assembly}" if (!data) 
  s << "\t; #{@comments.join(', ')}" if @comments.length > 0
  s
end