Class: SCASM::Assembler
- Inherits:
-
Object
- Object
- SCASM::Assembler
- Defined in:
- lib/scasm/assembler.rb
Instance Method Summary collapse
- #assemble ⇒ Object
- #data(*words) ⇒ Object
- #eval(code) ⇒ Object
-
#initialize ⇒ Assembler
constructor
A new instance of Assembler.
-
#inst(opsym, a, b) ⇒ Object
Statements.
-
#jmp(label) ⇒ Object
Pseudoinstructions.
- #label(name) ⇒ Object
- #o ⇒ Object
- #pc ⇒ Object
- #peek ⇒ Object
-
#pop ⇒ Object
Values.
- #push ⇒ Object
- #ret ⇒ Object
- #sp ⇒ Object
Constructor Details
#initialize ⇒ Assembler
Returns a new instance of Assembler.
9 10 11 12 |
# File 'lib/scasm/assembler.rb', line 9 def initialize @stmts = [] @relocations = [] end |
Instance Method Details
#assemble ⇒ Object
18 19 20 21 22 23 |
# File 'lib/scasm/assembler.rb', line 18 def assemble resolve_labels io = StringIO.new @stmts.each { |stmt| stmt.assemble io } io.string end |
#data(*words) ⇒ Object
38 39 40 |
# File 'lib/scasm/assembler.rb', line 38 def data *words @stmts << Data.new(words) end |
#eval(code) ⇒ Object
14 15 16 |
# File 'lib/scasm/assembler.rb', line 14 def eval code instance_eval code end |
#inst(opsym, a, b) ⇒ Object
Statements
27 28 29 30 31 |
# File 'lib/scasm/assembler.rb', line 27 def inst opsym, a, b a = parse_value a b = parse_value b @stmts << Instruction.new(opsym, a, b) end |
#jmp(label) ⇒ Object
Pseudoinstructions
84 85 86 |
# File 'lib/scasm/assembler.rb', line 84 def jmp label set pc, label end |
#label(name) ⇒ Object
33 34 35 36 |
# File 'lib/scasm/assembler.rb', line 33 def label name raise "label names must be strings" unless name.is_a? String @stmts << Label.new(name) end |
#o ⇒ Object
73 74 75 |
# File 'lib/scasm/assembler.rb', line 73 def o O.new end |
#pc ⇒ Object
69 70 71 |
# File 'lib/scasm/assembler.rb', line 69 def pc PC.new end |
#peek ⇒ Object
57 58 59 |
# File 'lib/scasm/assembler.rb', line 57 def peek Peek.new end |
#push ⇒ Object
61 62 63 |
# File 'lib/scasm/assembler.rb', line 61 def push Push.new end |
#ret ⇒ Object
88 89 90 |
# File 'lib/scasm/assembler.rb', line 88 def ret set pc, pop end |
#sp ⇒ Object
65 66 67 |
# File 'lib/scasm/assembler.rb', line 65 def sp SP.new end |