1
0
mirror of https://github.com/safiire/n65.git synced 2024-12-12 00:29:03 +00:00
n65/lib/label.rb
2015-02-17 19:05:37 -08:00

64 lines
961 B
Ruby

module Assembler6502
####
## Represents a label
class Label
attr_reader :label, :address
def self.parse_label(asm_line, address)
sanitized = Assembler6502.sanitize_line(asm_line)
match_data = sanitized.match(/([A-za-z][A-Za-z0-9]+):/)
unless match_data.nil?
_, label = match_data.to_a
self.new(label, address)
else
nil
end
end
####
## Create a label on an address
def initialize(label, address)
@label = label
@address = address
end
####
## Pretty print
def to_s
sprintf("%.4X | #{@label}", @address)
end
####
## Labels take no space
def length
0
end
####
## Emit bytes, (none)
def emit_bytes
[]
end
####
## Mode
def mode
"label"
end
####
## Description
def description
sprintf("Label pointing to $%.4X", @address)
end
end
end