Assembly code:
.syntax unified @ -------------------------------- .global main main: @ Stack the return address (lr) in addition to a dummy register (ip) to @ keep the stack 8-byte aligned. push {ip, lr} @ Load the argument and perform the call. This is like 'printf("...")' in C. ldr r0, =message bl printf @ Exit from 'main'. This is like 'return 0' in C. mov r0, #0 @ Return 0. @ Pop the dummy ip to reverse our alignment fix, and pop the original lr @ value directly into pc — the Program Counter — to return. pop {ip, pc} @ -------------------------------- @ Data for the printf calls. The GNU assembler's ".asciz" directive @ automatically adds a NULL character termination. message: .asciz "Hello, world.\n"
It's successfully when I use armv7-a compiler to compile it.
Currently I have aarch64 compiler. Can I use it to compile the above code?
Hi,
Thanks for you answer.
Let me confirm again.
1. Whether the 32 bit code could execute is determined by OS.
2. Currently, I can not successfully compile the code.
According to the above answers, I think I should I have two cross toolchains while one is for aarch32 code, and the other is for aarch64 code. For the above code that I submitted, I should use the aarch32 cross compiler.
3. If the OS supports both aarch32 and aarch64, the OS will switch the CPU execution state between 32bit state and 64bit state.
For the above 3 questions, am I right?