Class: C8dasm::Opcode

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

Overview

Represents an opcode, in the sense of a disassembly file.

Examples

o = Opcode.new('a21e')
o.line     #=> '200:a21e  LD I, 21e  ;Puts 21e into register I.'

o.opcode   #=> 'a21e'
o.assembly #=> 'LD I, 21e'
o.comment  #=> 'Puts 21e into register I.'
o.address  #=> '200'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opcode, address: 0x200) ⇒ Opcode

Creates a new Opcode instance.

opcode - The String opcode to represents. address - The Fixnum address of this opcode. Default is 0x200.



20
21
22
23
24
25
26
27
28
# File 'lib/c8dasm/opcode.rb', line 20

def initialize(opcode, address: 0x200)
  @assembly = Assembly.new(opcode).to_s
  @opcode = opcode
  @comment = Comment.new(opcode).to_s
  @address = sprintf("%03x", address)
  @line = "#@address:#@opcode  " +
          sprintf("%-14s", @assembly) +
          ";#@comment"
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



30
31
32
# File 'lib/c8dasm/opcode.rb', line 30

def address
  @address
end

#assemblyObject (readonly)

Returns the value of attribute assembly.



30
31
32
# File 'lib/c8dasm/opcode.rb', line 30

def assembly
  @assembly
end

#commentObject (readonly)

Returns the value of attribute comment.



30
31
32
# File 'lib/c8dasm/opcode.rb', line 30

def comment
  @comment
end

#lineObject (readonly)

Returns the value of attribute line.



30
31
32
# File 'lib/c8dasm/opcode.rb', line 30

def line
  @line
end

#opcodeObject (readonly)

Returns the value of attribute opcode.



30
31
32
# File 'lib/c8dasm/opcode.rb', line 30

def opcode
  @opcode
end