diff --git a/lib/asm/data_object.rb b/lib/asm/data_object.rb index 8c2a01cc..c081b6ab 100644 --- a/lib/asm/data_object.rb +++ b/lib/asm/data_object.rb @@ -3,7 +3,13 @@ module Asm def initialize(data) @data = data end - + + def at address + @address = address + end + def length + @data.length + end def assemble(io, as) io << @data end diff --git a/test/label_test.rb b/test/label_test.rb index 8f2bcc69..b469d1e7 100644 --- a/test/label_test.rb +++ b/test/label_test.rb @@ -10,23 +10,32 @@ class TestExtern < MiniTest::Test def test_extern @generator.instance_eval { - push lr - ldr r0, "hello world".to_sym - mov r7, 4 #4 is write - swi 0 - pop pc + mov r7, 4 #4 == write + mov r0 , 1 #stdout + add r1 , pc , 12 # address of "hello Raisa" + mov r2 , 12 # length of hello + swi 0 mov r7, 1 #1 == exit swi 0 } - - write(7 , 'label') + @generator.add_data("Hello Raisa"+ "\n\x00") + write(7 , 'label') end #helper to write the file def write len ,name writer = Asm::ObjectWriter.new(Elf::Constants::TARGET_ARM) assembly = @generator.assemble_to_string - assert_equal len * 4 , assembly.length + #assert_equal len * 4 , assembly.length writer.set_text assembly writer.save("#{name}_test.o") end end +# _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