1
0
mirror of https://github.com/safiire/n65.git synced 2024-12-12 15:29:12 +00:00
n65/lib/label.rb

64 lines
961 B
Ruby
Raw Normal View History

2015-02-18 03:05:37 +00:00
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