fix the putstring sys call indexing

index 0 is the marker word , so like in some, all indexes 1 based
works :-)
This commit is contained in:
Torsten Ruger 2015-11-15 22:03:06 +02:00
parent 8e82da0b61
commit f50d7b57a4
4 changed files with 4 additions and 6 deletions

View File

@ -1,6 +1,6 @@
GIT GIT
remote: git://github.com/salama/salama-arm.git remote: git://github.com/salama/salama-arm.git
revision: 72fcf371bc42279676533142c82e34713e77ea75 revision: c711d34418f08bb2d7c5fea3cbe4149bdd22aa61
specs: specs:
salama-arm (0.3.0) salama-arm (0.3.0)

View File

@ -128,9 +128,8 @@ module Arm
end end
def putstring int_code def putstring int_code
codes = ArmMachine.ldr( :r1 , Register.message_reg, 4 * Register.resolve_index(:message , :receiver) - 4) codes = ArmMachine.ldr( :r2 , :r1 , 8 ) # String length
codes.append ArmMachine.ldr( :r2 , :r1 , 4 ) # String length codes.append ArmMachine.add( :r1 , :r1 , 12 ) # adjust for object header
codes.append ArmMachine.add( :r1 , :r1 , 8 ) # adjust for object header
codes.append ArmMachine.mov( :r0 , 1 ) # write to stdout == 1 codes.append ArmMachine.mov( :r0 , 1 ) # write to stdout == 1
syscall(int_code , codes ) syscall(int_code , codes )
end end

View File

@ -66,7 +66,6 @@ module Register
compiler.add_code RegisterTransfer.new(source, r8 , Register.message_reg ) compiler.add_code RegisterTransfer.new(source, r8 , Register.message_reg )
# save the return value into the message # save the return value into the message
compiler.add_code Register.set_slot( source , return_tmp , :message , :return_value ) compiler.add_code Register.set_slot( source , return_tmp , :message , :return_value )
# and "unroll" self and frame
end end
end end
extend ClassMethods extend ClassMethods

View File

@ -15,7 +15,7 @@ class HelloTest < MiniTest::Test
@string_input = <<HERE @string_input = <<HERE
class Object class Object
int main() int main()
"Hello again\n".putstring() return "Hello again\n".putstring()
end end
end end
HERE HERE