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
|
2014-05-19 20:04:15 +02:00
|
|
|
fibo = @program.get_or_create_function(:fibo)
|
2014-05-19 16:32:41 +02:00
|
|
|
@program.main.mov( int , 10 )
|
|
|
|
@program.main.call( fibo )
|
2014-05-19 20:04:15 +02:00
|
|
|
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
|