Webcentive RISC-V Reference

Zcmp instructions

Complex PUSH/POP and Double Move

The Zcmp extension is a set of instructions which may be executed as a series of existing 32-bit RISC-V instructions.

This extension reuses some encodings from c.fsdsp. Therefore it is incompatible with Zcd, which is included when C and D extensions are both present.

Note: Zcmp is primarily targeted at embedded class CPUs due to implementation complexity. Additionally, it is not compatible with architecture class profiles.

The Zcmp extension depends on the Zca extension.

The PUSH/POP assembly syntax uses several variables, the meaning of which are:

  • _reg_list_ is a list containing 1 to 13 registers (ra and 0 to 12 s registers)
  • valid values: {ra}, {ra, s0}, {ra, s0-s1}, {ra, s0-s2}, ..., {ra, s0-s8}, {ra, s0-s9}, {ra, s0-s11}
  • note that {ra, s0-s10} is not valid, giving 12 lists not 13 for better encoding
  • _stack_adj_ is the total size of the stack frame.
  • valid values vary with register list length and the specific encoding, see the instruction pages for details.
RV32
RV64
Mnemonic
Instruction
yes
yes
cm.push _{reg_list}, -stack_adj_
#insns cm push
yes
yes
cm.pop _{reg_list}, stack_adj_
#insns cm pop
yes
yes
cm.popret _{reg_list}, stack_adj_
#insns cm popret
yes
yes
cm.popretz _{reg_list}, stack_adj_
#insns cm popretz
yes
yes
cm.mva01s rs1', rs2'
#insns cm mva01s
yes
yes
cm.mvsa01 r1s', r2s'
#insns cm mvsa01

Extension description from riscv-unified-db, reformatted.

Specification chapter: The RISC-V Instruction Set Manual, src/unpriv/zcmp.adoc.

Instructions (6)

MnemonicName (riscv-unified-db)XLEN
cm.mva01sMove two s0-s7 registers into a0-a1RV32 and RV64
cm.mvsa01Move a0-a1 into two registers of s0-s7RV32 and RV64
cm.popDestroy function call stack frameRV32 and RV64
cm.popretDestroy function call stack frame and return to `ra`RV32 and RV64
cm.popretzDestroy function call stack frame, move zero to `a0` and return to `ra`RV32 and RV64
cm.pushCreate function call stack frameRV32 and RV64