Class: N65::Space

Inherits:
InstructionBase show all
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

Instance Method Summary collapse

Methods inherited from InstructionBase

#unresolved_symbols?

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_sObject

Display



40
41
42
# File 'lib/n65/directives/space.rb', line 40

def to_s
  ".space #{@name} #{@size}"
end