What is the equivalent instruction for PUSH{lr}
and POP{lr}
in ARM Arch64 instruction set .
Is STR X30, [SP, #8]
correct ? could y
STR X30, [SP, #8]
is totally wrong.
The most important point about Aarch64 stack is that SP
MUST BE 16 Byte aligned.
Stack is descending. So SP
should be moved left. sub sp, sp, #CONST
. In your example you actually mess up data of parent function.
If you need to preserve LR
which is actually x30
in Aarch64 use
str x30, [sp,#-16]!
Technically, it's possible to preserve on register only by
str x30, [sp,#-8] // sp is not changed here! but data is written in permitted area
but with assumption that your function doesn't call any other subfunctions. But why on Earth save LR
in this case?
Also Aarch64 could use any other register to perform return from a function. For example:
mov x7, x30 // preserve LR
blr .L.my.bloody.subroutine // blr will mess up LR/x30
...
ret x7 // returning from function by using preserved req
In case you need to preserve more than 2 registers use example provided by @BitBank
Finally, you could not modify pc
, so there is only one way to return by using ret