fixin up mov arguments
This commit is contained in:
@@ -36,9 +36,9 @@ module Arm
|
||||
end
|
||||
|
||||
def string_load block , str_lit , reg
|
||||
block << add( "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit
|
||||
block << add( "r#{reg}".to_sym , str_lit , nil ) #right is pc, implicit
|
||||
#second arg is a hack to get the stringlength without coding
|
||||
block << mov( "r#{reg+1}".to_sym , right: str_lit.length )
|
||||
block << mov( "r#{reg+1}".to_sym , str_lit.length )
|
||||
str_lit
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ module Arm
|
||||
end
|
||||
|
||||
def main_start entry
|
||||
entry << mov( :fp , right: 0 )
|
||||
entry << mov( :fp , 0 )
|
||||
end
|
||||
def main_exit exit
|
||||
syscall(exit , 1)
|
||||
@@ -66,9 +66,9 @@ module Arm
|
||||
# assumes string in r0 and r1 and moves them along for the syscall
|
||||
def write_stdout block
|
||||
block.instance_eval do
|
||||
mov( :r2 , right: :r1 )
|
||||
mov( :r1 , right: :r0 )
|
||||
mov( :r0 , right: 1 ) # 1 == stdout
|
||||
mov( :r2 , :r1 )
|
||||
mov( :r1 , :r0 )
|
||||
mov( :r0 , 1 ) # 1 == stdout
|
||||
end
|
||||
syscall( block , 4 )
|
||||
end
|
||||
@@ -97,7 +97,7 @@ module Arm
|
||||
end
|
||||
|
||||
def syscall block , num
|
||||
block << mov( :r7 , right: num )
|
||||
block << mov( :r7 , num )
|
||||
block << swi( 0 , {})
|
||||
Vm::Integer.new(0) #small todo, is this actually correct for all (that they return int)
|
||||
end
|
||||
|
@@ -3,8 +3,8 @@ module Arm
|
||||
class MoveInstruction < Vm::MoveInstruction
|
||||
include Arm::Constants
|
||||
|
||||
def initialize(first , attributes)
|
||||
super(first , attributes)
|
||||
def initialize(to , from , attributes)
|
||||
super(to , from , attributes)
|
||||
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
||||
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
||||
@attributes[:opcode] = attributes[:opcode]
|
||||
@@ -20,7 +20,7 @@ module Arm
|
||||
end
|
||||
|
||||
def build
|
||||
right = @attributes[:right]
|
||||
right = @from
|
||||
if right.is_a?(Vm::StringConstant)
|
||||
# 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)
|
||||
@@ -55,7 +55,7 @@ module Arm
|
||||
build
|
||||
instuction_class = 0b00 # OPC_DATA_PROCESSING
|
||||
val = shift(@operand , 0)
|
||||
val |= shift(reg_code(@first) , 12)
|
||||
val |= shift(reg_code(@to) , 12)
|
||||
val |= shift(reg_code(@rn) , 12+4)
|
||||
val |= shift(@attributes[:update_status] , 12+4+4)#20
|
||||
val |= shift(op_bit_code , 12+4+4 +1)
|
||||
|
@@ -42,13 +42,13 @@ module Core
|
||||
reg1 = Vm::Integer.new(1)
|
||||
itos_fun = context.program.get_or_create_function(:utoa)
|
||||
block.instance_eval do
|
||||
mov( reg1 , right: str_addr ) #move arg up
|
||||
mov( reg1 , str_addr ) #move arg up
|
||||
add( str_addr , buffer ,nil ) # string to write to
|
||||
add( str_addr , str_addr , (buffer.length-3))
|
||||
call( itos_fun , {})
|
||||
# And now we "just" have to print it, using the write_stdout
|
||||
add( str_addr , left: buffer ) # string to write to
|
||||
mov( reg1 , right: buffer.length )
|
||||
add( str_addr , buffer , nil ) # string to write to
|
||||
mov( reg1 , buffer.length )
|
||||
end
|
||||
ret = Vm::CMachine.instance.write_stdout(block)
|
||||
function
|
||||
|
@@ -51,7 +51,7 @@ module Vm
|
||||
define_instruction_three(inst , LogicInstruction)
|
||||
end
|
||||
[:mov, :mvn].each do |inst|
|
||||
define_instruction_one(inst , MoveInstruction)
|
||||
define_instruction_two(inst , MoveInstruction)
|
||||
end
|
||||
[:cmn, :cmp, :teq, :tst].each do |inst|
|
||||
define_instruction_two(inst , CompareInstruction)
|
||||
|
@@ -13,7 +13,7 @@ module Vm
|
||||
|
||||
def load_args into
|
||||
args.each_with_index do |arg , index|
|
||||
if arg.is_a? IntegerConstant
|
||||
if arg.is_a?(IntegerConstant) or arg.is_a?(StringConstant)
|
||||
Vm::Integer.new(index).load into , arg
|
||||
else
|
||||
Vm::Integer.new(index).move( into, arg ) if arg.register != index
|
||||
|
@@ -64,8 +64,9 @@ module Vm
|
||||
end
|
||||
end
|
||||
class MoveInstruction < Instruction
|
||||
def initialize first , options
|
||||
@first = first
|
||||
def initialize to , from , options
|
||||
@to = to
|
||||
@from = from
|
||||
super(options)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user