2014-04-19 22:25:46 +02:00
|
|
|
require "asm/arm/code_generator"
|
2014-04-14 17:09:56 +02:00
|
|
|
|
|
|
|
if (__FILE__ == $0)
|
2014-04-21 20:13:14 +02:00
|
|
|
gen = Asm::Arm::ArmAssembler.new
|
2014-04-14 17:09:56 +02:00
|
|
|
|
|
|
|
gen.instance_eval {
|
|
|
|
mov r0, 5
|
|
|
|
loop_start = label
|
|
|
|
loop_start.set!
|
|
|
|
subs r0, r0, 1
|
|
|
|
bne loop_start
|
2014-04-19 23:13:58 +02:00
|
|
|
mov r7, 1
|
|
|
|
swi 0
|
2014-04-14 17:09:56 +02:00
|
|
|
}
|
|
|
|
|
2014-04-21 20:13:14 +02:00
|
|
|
gen.add_data("printf"+ "\x00")
|
2014-04-19 22:25:46 +02:00
|
|
|
require 'asm/object_writer'
|
2014-04-14 17:09:56 +02:00
|
|
|
writer = Asm::ObjectWriter.new(Elf::Constants::TARGET_ARM)
|
2014-04-21 20:13:14 +02:00
|
|
|
writer.set_text gen.assemble_to_string
|
2014-04-14 17:09:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
writer.save('arm_as_generated.o')
|
|
|
|
rescue => err
|
|
|
|
puts 'as: cannot save output file: ' + err.message
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|