ARM Instruction Set: Single Data Transfer (LDR, STR)

ARM 아키텍처에서는 메모리에서 데이터를 로드하거나 메모리에 데이터를 저장하는 데 사용되는 LDR (Load Register)와 STR (Store Register) 명령어가 있다. 이 글에서는 LDRSTR 명령어에 대해 알아본다.

Single data transfer instructions

Syntax

<LDR|STR>{cond}{B}{T} Rd,<Address>

기본적인 Load/Store 명령이다.

  • Word(4 bytes) : LDR, STR
  • Halfword(2 bytes) : LDRH, STRH
  • Byte(1 bytes) : LDRB, STRB

<Address> 에는 다음이 올 수 있다.

  • <expression> : PC를 base로 Immediate offset을 반영한 값
  • pre-indexing addressing : []안은 계산 전에 미리 주소를 반영하여 접근
    • [Rn]
    • [Rn, <#expression>]{!}
    • [Rn, {+/-}Rm{,<shift>}]{!}
  • post-indexing addressing : [] 밖은 계산 후 주소를 더해 준다.
    • [Rn], <#expression>
    • [Rn], {+/-}Rm{,<shift>}
  • <shift> : shift 연산
  • {!} : write back 여부

Examples

STR R1,[R2,R4]! ; Store R1 at R2+R4 (both of which are registers) and write back address to R2.
 
STR R1,[R2],R4  ; Store R1 at R2 and write back R2+R4 to R2.
 
LDR R1,[R2,#16] ; Load R1 from contents of R2+16, but don’t write back.
 
LDR R1,[R2,R3,LSL#2] ; Load R1 from contents of R2+R3*4.
 
LDREQB R1,[R6,#5] ; Conditionally load byte at R6+5 into R1 bits 0 to 7, filling bits 8 to 31 with zeros.

참고

답글 남기기