ARM Instruction Set: PSR Transfer (MRS, MSR)

ARM 아키텍처에서는 프로그램 상태 레지스터(Program Status Register, PSR)의 값을 읽거나 쓰는 데에 사용되는 명령어인 MRS (Move to Register from PSR)와 MSR (Move to PSR from Register)이 있다. 이 글에서는 MRS, MSR 명령어에 대해 알아본다.

Instruction Format

Syntax

MRS{cond} Rd,<psr>
MSR{cond} <psr>,Rm
MSR{cond} <psrf>,Rm
MSR{cond} <psrf>,<#expression>

MRS 명령어는 PSR의 값을 일반 레지스터로 이동시키고, MSR 명령어는 일반 레지스터의 값을 PSR로 이동시킨다.

  • {cond} : 두글자 상태(condition)
  • Rd and Rm : R15가 아닌 레지스터
  • psr : CPSR, CPSR_all, SPSR, or SPSR_all
  • psrf : CPSR_flg, SPSR_flg
  • #expresstion : 8bit 표현식

Example

Change Mode

아래는 모드를 #new_mode로 변경하는 예제 코드이다.

MRS R0,CPSR         ; Take a copy of the CPSR.
BIC R0,R0,#0x1F     ; Clear the mode bits.
ORR R0,R0,#new_mode ; Select new mode
MSR CPSR,R0         ; Write back the modified
                    ; CPSR.

Change Flag

MSR CPSR_flg,#0xF0000000 ; Set all the flags
                         ; regardless of their
                         ; previous state (does not
                         ; affect any control bits).

참고

답글 남기기