ARM Instruction Set: Data Processing

ARM 아키텍처에서는 데이터 처리 명령어를 사용하여 레지스터 간의 연산을 수행할 수 있다. 데이터 처리 명령어는 산술 연산, 논리 연산, 시프트 연산 등을 포함한다. 이 글에서는 ARM Data Processing 명령어에 대해 알아본다.

Instruction Format

Syntax

<Operation>{<cond>}{S} Rd, Rn, Operand2

<Operation> 구성

  • Arithmetic (산술) : ADD, ADC, SUB, SBC, RSB, RSC
  • Logic (로직) : AND, ORR, EOR, BIC
  • Comparisons (비교) : CMP, CMN, TST, TEQ
  • Data Movement (데이터 이동) : MOV, MVN

연산은 메모리상이 아닌 레지스터 상에서 동작한다.

First operand인 Rd는 항상 레지스터이고, Second operand(Operand2)는 barrel shifter를 통해 ALU로 보내진다.

Flexible second operand (Operand2)

Constant (상수)

#constant

32비트 워드 내에서 짝수의 비트만큼 8비트 값을 오른쪽으로 회전(ROR)시켜 생성할 수 있는 모든 값을 가질 수 있다.

MOV R0, #4096               ; uses 0x40 ROR 26
ADD R1, RR2, #0xFF0000      ; uses 0xFF ROR 16
 
MOV R0, #0xFFFFFFFF         ; = MVN R0, #0

Register with optional shift

Rm {, shift}
  • Rm : 데이터를 담을 레지스터
  • shift
    • ASR #n : arithmetic shift right n bits
    • LSL #n : logical shift left n bits
    • LSR #n : logical shift right n bits
    • ROR #n : rotate right n bits
LDR R0, [R1, R2, LSL#2]

Shifts

LSL (Logical Shift Left)

2의 제곱으로 곱하기

LSR (Logical Shift Right)

2의 제곱으로 나누기

ASR (Arithmetic Shift Right)

2의 제곱으로 나누고, 부호 비트는 보존

ROR (Rotate Right)

LSB에서 MSB까지 wrap around로 비트 회전

RRX (Rotate Right Extended)

CF에서 MSB까지 랩 어라운드로 단일 비트 회전

Arithmetic Operations (산술 연산)

OpcodeOPOperationDescription
0100ADDRd := Rn + Op2Add
0101ADCRd := Rn + Op2 + CarryAdd with Carry
0011RSBRd := Op2 – Rn Reverse subtract
0111RSCRd := Op2 – Rn + Carry – 1Reverse subtract with Carry
0010SUBRd := Rn – Op2Substract
0110SBCRd := Rn – Op2 + Carry – 1Substract with Carry
ADDS    r4, r0, r2      ; adding the least significant words
ADC     r5, r1, r3      ; adding the most significant words
 
SUBS    r8, r6, #240    ; sets the flags based on the result
 
RSB     r4, r4, #1280   ; subtracts contents of R4 from 1280

Comparisons Operations (비교 연산)

OpcodeOPOperationDescription
1010CMNCPSR flags := Rn + Op2Compare Negative
1011CMPCPSR flags := Rn – Op2Compare
1000TEQCPSR flags := Rn EOR Op2Test bitwise equaility
1001TSTCPSR flags := Rn AND Op2Test bits
CMP     r2, r9
CMN     r0, #6400
CMPGT   sp, r7, LSL #2
 
TST     r0, #0x3F8
TSTNE   r1, r5, ASR r1

Logical Opeations (로직 연산)

OpcodeOPOperationDescription
0000ANDRd := Rn AND Op2AND
1100ORRRd := Rn OR Op2OR
0001EORRd := Rn XOR Op2Exclusive OR
1110BICRd := Rn AND (NOT Op2)Bit Clear
EORS    r0,r0,r3,ROR r6
EORS    r7, r11, #0x18181818
 
BIC     r0, r1, #0xab

참고

답글 남기기