pushregs : Registers -> Stack
popregs : Stack -> Registers
Affected Flags |
|||
C | V | N | Z |
The pushregs and popregs instructions purpose is saving and restoring registers to (or from) stack. These instructions can save or restore all registers in one single instruction. The pushreg instruction is often used at the entry of a subroutine to save the registers used in it. Registers R0 to R14 can be saved with the exception of the R15 register because this particular register is the stack pointer. The popregs is often used at the exit of the subroutine to restore registers before the rts instruction. These two instructions take an argument in the form of register list.
registerlist =list of registers as the following example : r0/r1/r2/r5/r10-r12
Form | Effect |
pushregs regiserlist |
Registers -> Stack |
popregs registerlist |
Stack -> Registers |
M = Register List, 1 bit per register. Bit 0 = Register 0.
Instruction | Op Code |
Cycles | Encoding |
pushregs rx-rx/rx... | 0C | 1032 | 00001100 0MMMMMMM MMMMMMMM |
popregs rx-rx/rx... | 4C | 1032 | 01001100 0MMMMMMM MMMMMMMM |
// Example : Subroutine with pushregs/popregs
subroutine: pushregs r0/r1/r4-r8
; Some processing using registers r0/r1/r4/r5/r6/r7/r8 here
popregs r0/r1/r4-r8
rts