Class: SCASM::Assembler

Inherits:
Object
  • Object
show all
Defined in:
lib/scasm/assembler.rb

Instance Method Summary collapse

Constructor Details

#initializeAssembler

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

#assembleObject



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

#oObject



73
74
75
# File 'lib/scasm/assembler.rb', line 73

def o
  O.new
end

#pcObject



69
70
71
# File 'lib/scasm/assembler.rb', line 69

def pc
  PC.new
end

#peekObject



57
58
59
# File 'lib/scasm/assembler.rb', line 57

def peek
  Peek.new
end

#popObject

Values



53
54
55
# File 'lib/scasm/assembler.rb', line 53

def pop
  Pop.new
end

#pushObject



61
62
63
# File 'lib/scasm/assembler.rb', line 61

def push
  Push.new
end

#retObject



88
89
90
# File 'lib/scasm/assembler.rb', line 88

def ret
  set pc, pop
end

#spObject



65
66
67
# File 'lib/scasm/assembler.rb', line 65

def sp
  SP.new
end