Class: N65::Space
- Inherits:
-
InstructionBase
- Object
- InstructionBase
- N65::Space
- Defined in:
- lib/n65/directives/space.rb
Overview
This directive gives a symbolic name for memory and creates space for a variable in RAM
Class Method Summary collapse
-
.parse(line) ⇒ Object
Try to parse a .space directive.
Instance Method Summary collapse
-
#exec(assembler) ⇒ Object
.space creates a symbol at the current PC, and then advances PC by size.
-
#initialize(name, size) ⇒ Space
constructor
Initialize some memory space with a name.
-
#to_s ⇒ Object
Display.
Methods inherited from InstructionBase
Constructor Details
#initialize(name, size) ⇒ Space
Initialize some memory space with a name
23 24 25 26 |
# File 'lib/n65/directives/space.rb', line 23 def initialize(name, size) @name = name @size = size end |
Class Method Details
.parse(line) ⇒ Object
Try to parse a .space directive
12 13 14 15 16 17 18 |
# File 'lib/n65/directives/space.rb', line 12 def self.parse(line) match_data = line.match(/^.space\s+([a-zA-Z]?[a-zA-Z0-9_]+?)\s+([0-9]+)$/) return nil if match_data.nil? _, name, size = match_data.to_a Space.new(name, size.to_i) end |
Instance Method Details
#exec(assembler) ⇒ Object
.space creates a symbol at the current PC, and then advances PC by size
31 32 33 34 35 |
# File 'lib/n65/directives/space.rb', line 31 def exec(assembler) program_counter = assembler.program_counter assembler.symbol_table.define_symbol(@name, program_counter) assembler.program_counter += @size end |
#to_s ⇒ Object
Display
40 41 42 |
# File 'lib/n65/directives/space.rb', line 40 def to_s ".space #{@name} #{@size}" end |