I am doing an energy profile of an ARM processor for an academic project. I managed to measure the power consumption of several assembly instructions by running them in a ~200 insts loop, e.g.:
.rept 200
add r1, r2, r3
.endr
However, when coming to stack instructions, I wondered: what happens if I do something like this?
.rept 200
pop {r1}
.endr
Notice that the control flow isn't affected, since the loop uses an absolute jump at the end, and the code is running bare metal, without an OS.
What happens when the stack finishes? Does the sp
simply overflow and wrap around, going to 0x00000000
and starting popping from there?
My power sensor doesn't see anything strange; it is a constant power drain like any other instruction. Then, the question also arises: what if I keep pushing instead?
CPSID
would turn them off.push
andpop
. Such asldr r1, [sp,#4]!
andldr r1, [sp], #4
. You can substitute another register for 'sp'. Also, you can save 'sp' on the routine entry and point it to an array of know size. An issue is that the power consumption may include the memory access (DDR/SRAM,internal SRAM, bus type, etc). Also, the forms of the instructions maybe consume more/less power. Especially consult TRM for cycle time advice as the extra cycles will often consume more power as well.