rubyx/test/label_test.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2014-04-20 22:47:02 +02:00
require_relative 'helper'
#try to call an extern function
class TestExtern < MiniTest::Test
# need a code generator, for arm
def setup
@generator = Asm::Arm::ArmAssembler.new
2014-04-20 22:47:02 +02:00
end
2014-04-21 16:27:05 +02:00
def test_extern
2014-04-22 21:24:22 +02:00
hello = "Hello Raisa"+ "\n\x00"
2014-04-20 22:47:02 +02:00
@generator.instance_eval {
2014-04-22 13:39:47 +02:00
mov r7, 4 #4 == write
mov r0 , 1 #stdout
2014-04-22 21:24:22 +02:00
add r1 , pc , hello # address of "hello Raisa"
2014-04-22 13:39:47 +02:00
mov r2 , 12 # length of hello
swi 0
2014-04-21 16:27:05 +02:00
mov r7, 1 #1 == exit
swi 0
2014-04-20 22:47:02 +02:00
}
2014-04-22 21:24:22 +02:00
@generator.add_string(hello)
2014-04-22 13:39:47 +02:00
write(7 , 'label')
2014-04-21 16:27:05 +02:00
end
#helper to write the file
def write len ,name
2014-04-20 22:47:02 +02:00
writer = Asm::ObjectWriter.new(Elf::Constants::TARGET_ARM)
assembly = @generator.assemble_to_string
2014-04-22 13:39:47 +02:00
#assert_equal len * 4 , assembly.length
2014-04-20 22:47:02 +02:00
writer.set_text assembly
2014-04-21 16:27:05 +02:00
writer.save("#{name}_test.o")
2014-04-20 22:47:02 +02:00
end
end
2014-04-22 13:39:47 +02:00
# _start copied from dietc
# mov fp, #0 @ clear the frame pointer
# ldr a1, [sp] @ argc
# add a2, sp, #4 @ argv
# ldr ip, .L3
# add a3, a2, a1, lsl #2 @ &argv[argc]
# add a3, a3, #4 @ envp
# str a3, [ip, #0] @ environ = envp
# bl main