I need to write a function that after work sets all registers except r0-r3 to their initial values. I use push and pop, but I can't find which register stores the value of CMP.
UPD. Thank you. It seems I am wrong. I had an assignment that had a hint: "Don't forget about callee-save registers", so it wasn't suggesting treating flags as callee saved)
cmp
, like all ARM instructions with an s
suffix like subs
, set flags / condition codes. These condition codes live in a register called CPSR
, the Current Program Status Register. Also https://en.wikipedia.org/wiki/ARM_architecture#Registers
In all standard function-calling conventions, flags / condition codes are call-clobbered. You don't need to save/restore the caller's CPSR. Just let it be call-clobbered, along with r0..3.
But if you did, see https://heyrick.eu/armwiki/The_Status_register for examples like
MRS R0, CPSR ; Copy CPSR into R0
...
MSR CPSR, R0 ; Copy R0 into CPSR