Class: N65::Label
- Inherits:
-
Object
- Object
- N65::Label
- Defined in:
- lib/n65/directives/label.rb
Overview
This class represents a label, and will create an entry in the symbol table associated with the address it appears at.
Class Method Summary collapse
Instance Method Summary collapse
-
#exec(assembler) ⇒ Object
Create an entry in the symbol table for this label.
-
#initialize(symbol) ⇒ Label
constructor
Create a new label object.
-
#to_s ⇒ Object
Display.
Constructor Details
#initialize(symbol) ⇒ Label
Create a new label object
18 19 20 |
# File 'lib/n65/directives/label.rb', line 18 def initialize(symbol) @symbol = symbol end |
Class Method Details
.parse(line) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/n65/directives/label.rb', line 8 def self.parse(line) match_data = line.match(/^([a-zA-Z][a-zA-Z0-9_]+):$/) unless match_data.nil? label = match_data[1].to_sym return new(label) end nil end |
Instance Method Details
#exec(assembler) ⇒ Object
Create an entry in the symbol table for this label
23 24 25 26 |
# File 'lib/n65/directives/label.rb', line 23 def exec(assembler) program_counter = assembler.program_counter assembler.symbol_table.define_symbol(@symbol, program_counter) end |
#to_s ⇒ Object
Display
29 30 31 |
# File 'lib/n65/directives/label.rb', line 29 def to_s "#{@symbol}:" end |