rubyx/test/arm/test_fibo.rb

27 lines
772 B
Ruby
Raw Normal View History

2014-05-19 16:32:41 +02:00
require_relative 'helper'
class TestFibo < MiniTest::Test
def setup
@program = Vm::Program.new "Arm"
end
# a hand coded version of the fibonachi numbers
# not my hand off course, found in the net from a basic introduction
def test_fibo
int = Vm::Integer.new(1) # the one is funny, but the fibo is _really_ tight code and reuses registers
fibo = @program.get_or_create_function(:fibo)
2014-05-19 16:32:41 +02:00
@program.main.mov( int , 10 )
@program.main.call( fibo )
# putint = @program.get_or_create_function(:putint)
# @program.main.call( putint )
2014-05-19 16:32:41 +02:00
write 20 , "fibo"
end
#helper to write the file
def write len ,name
writer = Elf::ObjectWriter.new(@program , Elf::Constants::TARGET_ARM)
writer.save("#{name}_test.o")
end
end