We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, I am writting a function, which involves complicated algorithm, I want to have a lot of general purpose registers to keep the routine speed. I have read some article that r13-r15 are special registers, but can be used as general purpose registers. Can I do it like this stmfd sp!, {r4-r15,lr}:: ldmfd sp!, {r4-r15,pc}Thank you very much!
my_fct: movw r12, #:lower16:.save_zone movt r12, #:upper16:.save_zone stmia r12, {r4 - r11, sp, lr} ... movw r12, #:lower16:.save_zone movt r12, #:upper16:.save_zone ldmia r12, {r4 - r11, sp, pc} .data.save_zone: .word 0, 0, 0, 0, 0, 0, 0 .word 0, 0, 0, 0, 0, 0, 0
I read some ARM document, it saysA called routine need not preserve the values of r0-r3, IP (r12) and LR (r14)so when subroutine returns, does it mean that it will automatically restore the value of r0-r3, and r12, in the caller function? Thank you.
If you don't need stack operation during a period of time, will this save one more register?str sp, [pc, #?]...//use sp as gp reg...ldr sp, [pc, #??] // you should know the offset from where you put sp value
On ARM, interrupts have a separate banked stack pointer. You don't have to worry about sharing the stack with them and are therefore free to use r13 for anything you want so long as you preserve it before returning.
my_fct: push {r0 - r12, lr} movw r12, #:lower16:.save_zone movt r12, #:upper16:.save_zone ldr r11, [r12], #4 str sp, [r12, r11, lsl #2] add r11, #1 str r11, [r12, #-4]! ... movw r12, #:lower16:.save_zone movt r12, #:upper16:.save_zone ldr r11, [r12], #4 sub r11, r11, #1 ldr sp, [r12, r11, lsl #2] str r11, [r12, #-4]! pop {r0 - r12, pc}.data.save_zone: .word 0 .word 0, 0, 0, 0, 0, 0, 0
But it's important to understand that that code is not re-entrant: that is, if my_fct is interrupted and the interrupt calls (possibly indirectly) my_fct again then the when the outer call to my_fct tries to return, bad things™ will happen.