fixing address resolution cleans up hello world

This commit is contained in:
Torsten Ruger
2014-04-22 23:55:47 +03:00
parent 7ff8fa8802
commit b240dc5100
5 changed files with 40 additions and 51 deletions

View File

@ -31,7 +31,7 @@ module Asm
@opcode = opcode.downcase.to_sym
@args = args
end
attr_reader :opcode, :args
attr_reader :opcode, :args , :position
def affect_status
@s
@ -55,7 +55,7 @@ module Asm
builder.cond = COND_CODES[@cond]
builder.rd = reg_ref(args[0])
builder.rn = reg_ref(args[1])
builder.build_operand args[2]
builder.build_operand args[2] , self.position
builder.assemble io, as
when :cmn, :cmp, :teq, :tst
builder = NormalBuilder.new(OPC_DATA_PROCESSING, OPCODES[opcode], 1)

View File

@ -43,7 +43,14 @@ module Asm
end
# Build representation for source value
def build_operand(arg)
def build_operand(arg , position = 0)
#position only needed for calculating relative addresses to data objects
#there is a design stink here which makes my head ache. But shanti shanti
if arg.is_a?(Asm::DataObject)
# do pc relative addressing with the difference to the instuction
# 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute)
arg = Asm::NumLiteralNode.new( arg.position - position - 8 )
end
if (arg.is_a?(Asm::NumLiteralNode))
if (arg.value.fits_u8?)
# no shifting needed
@ -82,10 +89,7 @@ module Asm
end
@operand = rm_ref | (shift_op << 4) | (shift_imm << 4+3)
elsif arg.is_a?(Asm::DataObject)
# do pc relative addressing with the difference to the instuction
else
puts "#{self.inspect}"
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG + " " + arg.inspect, arg)
end
end

View File

@ -4,6 +4,10 @@ module Asm
@data = data
end
def position
throw "Not set" unless @address
@address
end
def at address
@address = address
end