fixin up mov arguments

This commit is contained in:
Torsten Ruger 2014-05-18 12:30:49 +03:00
parent 2be96dccdc
commit 9fc8bfbb55
9 changed files with 26 additions and 25 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -4,11 +4,11 @@ class TestMoves < MiniTest::Test
include ArmHelper
def test_mov
code = @machine.mov :r0, right: 5
code = @machine.mov :r0, 5
assert_code code , :mov , [0x05,0x00,0xa0,0xe3] #e3 a0 10 05
end
def test_mvn
code = @machine.mvn :r1, right: 5
code = @machine.mvn :r1, 5
assert_code code , :mvn , [0x05,0x10,0xe0,0xe3] #e3 e0 10 05
end
end

View File

@ -5,7 +5,7 @@ def fibonaccit(n) # n == r0
tmp = a # r3 <- r1
a = b # r1 <- r2
b = tmp + b # r4 = r2 + r3 (r4 transient) r2 <- r4
tmp = inttos(b)
tmp = putint(b)
putstring(tmp)
n = n - 1 # r2 <- 0 ???? #call ok
end #r5 <- r0 - 1 # r0 <- r5

View File

@ -14,7 +14,7 @@ class TestSmallProg < MiniTest::Test
def test_loop
@program.main.instance_eval do
mov :r0, right: 5 #1
mov :r0, 5 #1
start = Vm::Block.new("start")
add_code start
start.instance_eval do
@ -29,10 +29,10 @@ class TestSmallProg < MiniTest::Test
hello = Vm::StringConstant.new "Hello Raisa\n"
@program.add_object hello
@program.main.instance_eval do
mov :r7, right: 4 # 4 == write
mov :r0 , right: 1 # stdout
mov :r7, 4 # 4 == write
mov :r0 , 1 # stdout
add :r1 , hello , nil # address of "hello Raisa"
mov :r2 , right: hello.length
mov :r2 , hello.length
swi 0 , {} #software interupt, ie kernel syscall
end
write(7 + hello.length/4 + 1 , 'hello')