Compare commits
No commits in common. "bd71e23e04b103327ec2ef096cbba34aeae2f650" and "0989bd54f06fe24421804965c147550b9f5c5899" have entirely different histories.
bd71e23e04
...
0989bd54f0
34
assembler.rb
34
assembler.rb
|
@ -30,7 +30,7 @@ def t8() 24 end ; def t9() 25 end
|
|||
# reserved for kernel, detroyed by some irq handlers
|
||||
def k0() 26 end ; def k1() 27 end
|
||||
|
||||
def gp() 28 end # global pointer, rarely used (we can use this to reffer to a struct or smtn)
|
||||
def gp() 28 end # global pointer, rarely used
|
||||
def sp() 29 end # stack pointer
|
||||
def fp() 30 end # frame pointer
|
||||
def ra() 31 end # return address
|
||||
|
@ -39,39 +39,25 @@ class Assembler
|
|||
def initialize(base, size)
|
||||
@base_addr = base
|
||||
@file_size = size
|
||||
|
||||
# moar vars defined in assemble()
|
||||
end
|
||||
|
||||
def inspect
|
||||
"(Assembler base_addr:0x#{@base_addr.to_s 16} file_size:0x#{@file_size.to_s 16})"
|
||||
end
|
||||
|
||||
# TODO: Sub-labels
|
||||
|
||||
def label(l)
|
||||
l = l.to_s
|
||||
|
||||
@sub_labels[l] = {} if not @sub_labels.member?(l)
|
||||
@last_label_subs = @sub_labels[l]
|
||||
|
||||
return if @first_pass == false
|
||||
raise "error redefinition of label #{l}" if @labels.member?(l)
|
||||
@labels[l] = @bytes.length + @base_addr
|
||||
end
|
||||
|
||||
def sub_label(l)
|
||||
return if @first_pass == false
|
||||
l = l.to_s
|
||||
raise "error redefinition of sub_label #{l}" if @last_label_subs.member?(l)
|
||||
@last_label_subs[l] = @bytes.length + @base_addr
|
||||
raise "error redefinition of label #{l.to_s}" if @labels.member?(l.to_s)
|
||||
@labels[l.to_s] = @bytes.length + @base_addr
|
||||
end
|
||||
|
||||
def method_missing(m, *args, &block)
|
||||
return 0 if @first_pass
|
||||
if @last_label_subs[m.to_s] then
|
||||
return @last_label_subs[m.to_s]
|
||||
elsif @labels.member?(m.to_s) then # if m.to_s[0, 2] == "l_" then
|
||||
return @labels[m.to_s] #return @labels[m.to_s[2..]] if @labels.member?(m.to_s[2..])
|
||||
#raise "label doesn't exist #{m.to_s}"
|
||||
if m.to_s[0, 2] == "l_" then
|
||||
return @labels[m.to_s[2..]] if @labels.member?(m.to_s[2..])
|
||||
raise "label doesn't exist #{m.to_s}"
|
||||
else
|
||||
super
|
||||
end
|
||||
|
@ -81,13 +67,10 @@ class Assembler
|
|||
@first_pass = true
|
||||
@labels = {}
|
||||
@bytes = []
|
||||
@sub_labels = {}
|
||||
@last_label_subs = {}
|
||||
binding.eval source
|
||||
|
||||
@first_pass = false
|
||||
@bytes = []
|
||||
@last_label_subs = {}
|
||||
binding.eval source
|
||||
|
||||
puts "assembled 0x#{@bytes.length.to_s 16} (#{@bytes.length}) bytes"
|
||||
|
@ -249,7 +232,6 @@ file_size = 0x800 * 3
|
|||
|
||||
f = File.new "exe-header.asm.rb", "r"
|
||||
exe_header = Assembler.new(base_addr, 0x800).assemble f.read
|
||||
# puts f.path
|
||||
f.close
|
||||
|
||||
f = File.new "main.asm.rb", "r"
|
||||
|
|
Loading…
Reference in New Issue