for (int i = 0; i < 10000; i++)
a[i] = b[i] + c[i]
What does the ARM assembly for this high level language look like?
Edit:
I’m also assuming the base address of A is in R8, the base
address of B is in R9, and the base address of C is in R10
and A,B,C are all int arrays
Much appreciated
I tried:
MOV R0, #0 ; Init r0 (i = 0)
Loop:
a[i] = b[i] + c[i] //How to fix this?
ADD R0, R0, #1 ;Increment it
CMP R0, #1000 ;Check the limit
BLE Loop ;Loop if not finished
Assuming this high level language doesn’t have anything conflicting with C, you can use an arm C compiler to create assembly code from your snippet. For example if you have the following in test.c,
you can run
to create a test.s file, which will contain assembly code for your test function as well as some extra stuff. You can see how your loop got compiled into to assembly below.
Now the problem with this approach is trusting the compiler generates the optimal code for your study, which might not be always the case but what you’ll get is fast answers to your questions like above instead of waiting for people 🙂
— extra —
GCC allows you to put variables into certain registers, see related documentation.
You can get arm instruction cheat sheet here.
Newer versions of GCC creates better arm code as one would expected. Above snipped is generated by version 4.4.3, and I can confirm Linaro‘s 4.7.1 proves my claim. So if you take my approach use the most recent tool chain you can get.