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



17
18
19
20
# File 'lib/n65/directives/space.rb', line 17

def initialize(name, size)
  @name = name
  @size = size
end

Class Method Details

.parse(line) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/n65/directives/space.rb', line 8

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



23
24
25
26
27
# File 'lib/n65/directives/space.rb', line 23

def exec(assembler)
  program_counter = assembler.program_counter
  assembler.symbol_table.define_symbol(@name, program_counter)
  assembler.program_counter += @size
end

#to_sObject

Display



30
31
32
# File 'lib/n65/directives/space.rb', line 30

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