ARM Instruction Set: Block Data Transfer (LDM, STM)

ARM 아키텍처에서는 여러 개의 레지스터를 한 번에 메모리에 읽거나 메모리에 쓰는 데 사용되는 LDM (Load Multiple)과 STM (Store Multiple) 명령어를 제공한다. 이 글에서는 LDMSTM 명령어에 대해 알아본다.

Block data transfer instructions

Syntax

<LDM|STM>{addr_mode}{cond} Rn{!}, reglist{^}
  • addr_mode
    • IA : Increment address After each transfer (default)
    • ID : Increment address Before each transfer
    • DA : Decrement address After each transfer
    • DB : Decrement address Before each transfer
  • cond
  • Rn : base 주소
  • reglist : 레지스터 리스트 (Ex. {R0, R2-R7, R10})
  • ! : write-back
  • ^
    • reglistPC가 포함되어 있으면, SPSRCPSR로 copy하는데 이는 exception handler에서 복귀하기 위한 것으로 exception mode에서 사용해야 한다.
    • 그렇지 않으면, 데이터는 current mode register가 아니라 user mode register로 전송된다.

Examples

; R12 points to the start of the source data
; R14 points to the end of the source data
; R13 points to the start of the distination data
loop    LDMIA R12!, {R0-R11}    ; load 48 bytes
        STMIA R13!, {R0-R11}    ; and store them
        CMP R12, R14            ; check for the end
        BNE loop                ; and loop until done

Addressing mode

명령어가 스택을 지원하는데 사용되는지 아니면 다른 목적으로 사용되는지에 따라 Addressing 모드에 대해 명령어 표기를 다르게 한다. 명령어의 비트 이름과 값 사이의 Addressing 모드는 아래 표와 같다.

  • FD, ED, FA, EA는 필요한 스택 형태를 참조하여 pre 또는 post 인덱싱과 up/down 비트를 정의한다.
  • F와 E는 가득찬(full) 또는 빈(empty)를 나타낸다.
  • A와 D는 오름차순(ascending), 내림차순(descending)을 나타낸다.
  • 오름차순의 경우, STM은 올라가고, LDM은 내려간다. 내림차순이면 그 반대도 마찬가지이다.
  • IA, IB, DA, DB 는 LDM/STM이 스택에 사용되지 않을 때 사용된다.

Examples

STMED SP!,{R0-R3,R14}   ; Save R0 to R3 to use as workspace
                        ; and R14 for returning.
 
BL somewhere            ; This nested call will overwrite R14
 
LDMED SP!,{R0-R3,R15}   ; restore workspace and return.

참고

답글 남기기