Reputation: 11
Here's my code, before I explain my problem:
I'm new to ARM by the way, so I'm a super newbie. For now, I just cut out the unnecessary bits of my code. x0 - x7 being the "argument" registers, x29 is the frame pointer and x30 is the link register. x19 and x20 are just callee saved registers.
string1: .string "constant = %d low value = %d \n\n"
string2: .string "constant = %d \n"
.balign 4
.global main
main: stp x29, x30, [sp, -16]!
mov x29, sp
mov x20, -1000 // Setting values
mov x19, 5
print: adrp x0, string1
add x0, x0, :lo12:string1
mov x1, x19
mov x2, x20
bl printf
print2: adrp x0, string2
add x0, x0, :lo12:string2
mov x3, x19
bl printf
done: mov x0, 0
end: ldp x29, x30, [sp], 16
ret
Now for some reason, during "print", it prints out "constant = 5" just fine. However when it goes to "print2", it prints out "constant = 0". What's happening and why does it not print to 5 even though I haven't manipulated register x19 yet? I don't have quite the full grasp of how these work.
Result:
constant = 5 low value = -1000
constant = 0
thanks
Upvotes: 0
Views: 1777
Reputation: 822
In the event you want to create regular functions, as compared to inserting such functions within the body of your main code section, here's some code to prime the ARMv8 pump. My .include is just for my macros (i.e., push2 & pop2, etc); which is the same code you are using.
.data
string1: .string "constant = %d low value = %d\n\n"
string2: .string "constant = %d \n"
.text
.global main
.include "mymac_armv8.s" // for push2, pop2, and _exit macros
main:
movn x20, 1000
mov x19, 5
bl write1
bl write2
_exit
write1:
push2 x29, x30
push2 x1, x2
ldr x0,=string1
mov x1, x19
mov x2, x20
bl printf
pop2 x1, x2
pop2 x29, x30
ret
write2:
push2 x29, x30
push2 x1, x2
ldr x0,=string2
mov x1, x19
mov x2, x20
bl printf
pop2 x1, x2
pop2 x29, x30
ret
Upvotes: 1