msr

Move Register to Status Register (Thumb)

MSR <spec_reg>, <Rn>

Writes a general-purpose register to fields of the CPSR or SPSR (Thumb).

Pseudocode Operation

target ← SPSR if R == 1 else CPSR    // the APSR is the flag bits of the CPSR
if mask[3] then target[31:24] ← Rn[31:24]    // f
if mask[2] then target[23:16] ← Rn[23:16]    // s
if mask[1] then target[15:8] ← Rn[15:8]      // x
if mask[0] then target[7:0] ← Rn[7:0]        // c

Example

MSR APSR_nzcvq, r1

Encoding

Binary Layout
11110011100
31:21
R
20
Rn
19:16
10
15:14
0
13
0
12
mask
11:8
0
7
0
6
0
5
0
4
0
3
0
2
0
1
0
0
 
Format Thumb System
Opcode 0xF3808000
Extension T32 (System)

Operands

  • spec_reg
    Status register and the fields to write: APSR_<bits>, CPSR_<fields> or SPSR_<fields>
  • Rn
    General-purpose register holding the value to write

Related

Other forms of msr

  • msr Move to System Register
  • msr Move to Special Register (Banked)
  • msr Move Immediate to Special Register (A32)
  • msr Move Register to Status Register

Across architectures

Enable and Disable Interrupts : how x86, ARM, RISC-V, and PowerISA each do this.

More in T32 (System)

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0x0120F200 MSR{<c>}{<q>} <banked_reg>, <Rn> A32 cond | 00010 | R | 1 | 0 | M1 | 1111 | 0 | 0 | 1 | M | 0000 | Rn
0xF3808020 MSR{<c>}{<q>} <banked_reg>, <Rn> T32 11110011100 | R | Rn | 10 | 0 | 0 | M1 | 0 | 0 | 1 | M | 0 | 0 | 0 | 0
0x0320F000 MSR{<c>}{<q>} <spec_reg>, #<imm> A32 cond | 00110 | R | 10 | mask | 1 | 1 | 1 | 1 | imm12
0x0120F000 MSR{<c>}{<q>} <spec_reg>, <Rn> A32 cond | 00010 | R | 1 | 0 | mask | 1111 | 0 | 0 | 0 | 0 | 0000 | Rn
0xF3808000 MSR{<c>}{<q>} <spec_reg>, <Rn> T32 11110011100 | R | Rn | 10 | 0 | 0 | mask | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0

Description

Move general-purpose register to Special register moves selected bits of a general-purpose register to the APSR, CPSR or SPSR_<current_mode>. Because of the Do-Not-Modify nature of its reserved bits, a read-modify-write sequence is normally required when the MSR instruction is being used at Application level and its destination is not APSR_nzcvq (CPSR_f). If an MSR (register) moves selected bits of an immediate value to the CPSR, the PE checks whether the value being written to PSTATE.M is legal. See Illegal changes to PSTATE.M. An MSR (register) executed in User mode: An MSR (register) executed in System mode is unpredictable if it attempts to update the SPSR. The CPSR.E bit is writable from any mode using an MSR instruction. Arm deprecates using this to change its value.

Operation

if ConditionPassed() then
    EncodingSpecificOperations();
    if write_spsr then
        if PSTATE.M IN {M32_User,M32_System} then
            UNPREDICTABLE;
        else
            SPSRWriteByInstr(R[n], mask);
    else
        // Attempts to change to an illegal mode will invoke the Illegal Execution state mechanism
        CPSRWriteByInstr(R[n], mask);