6. Instruction Set
6์ฅ Instruction Set ๊ฐ์
ARM Cortex-M0์ Thumb Instruction Set์ ์ข ๋ฅ๋ณ๋ก ์ ๋ฆฌํ๋ค. Data processing, Load/Store, Branch, Control flow ๋ฑ ์นดํ ๊ณ ๋ฆฌ์ ๊ฐ ๋ช ๋ น์ด์ ๋ฌธ๋ฒ ๋ฐ encoding์ ๋ค๋ฃฌ๋ค.
Thumb Instruction Set ๋ถ๋ฅ
ARM Cortex-M0๋ ๋ค์ ์นดํ ๊ณ ๋ฆฌ์ ๋ช ๋ น์ด๋ฅผ ์ง์:
- Data processing: ADD, SUB, MUL, AND, ORR, EOR, CMP, MOV
- Data transfer (Load/Store): LDR, STR, LDRB, STRB, LDRH, STRH, LDM, STM
- Branch: B, BL, BX, BLX
- System: SVC, WFI, WFE, DSB, DMB, ISB, MRS, MSR
Data Processing Instructions
Register-Register
ADD Rd, Rn, Rm: Rd = Rn + RmSUB Rd, Rn, Rm: Rd = Rn - RmADC Rd, Rn: Rd = Rd + Rn + CSBC Rd, Rn: Rd = Rd - Rn - ยฌC
Register-Immediate
ADD Rd, #imm: Rd = Rd + imm (0~255 for Rd=R0~R7)SUB Rd, #imm: Rd = Rd - immMOV Rd, #imm: Rd = immCMP Rd, #imm: flags๋ง set
Logical
AND Rd, Rn: Rd = Rd AND RnORR Rd, Rn: Rd = Rd OR RnEOR Rd, Rn: Rd = Rd XOR Rn (exclusive OR)BIC Rd, Rn: Rd = Rd AND NOT RnMVN Rd, Rn: Rd = NOT RnTST Rn, Rm: flags๋ง set (AND)
Shift
LSL Rd, Rn, #imm: Logical shift leftLSR Rd, Rn, #imm: Logical shift rightASR Rd, Rn, #imm: Arithmetic shift right (sign-extend)ROR Rd, Rn: Rotate right
Multiply
MUL Rd, Rn: Rd = Rd ร Rn (32-bit, lower 32-bit only)- Single-cycle or 32-cycle multiplier (์ต์ )

Load/Store Instructions
ARM์ load/store architecture โ ๋ฉ๋ชจ๋ฆฌ์ register ๊ฐ ์ ์ก์ LDR/STR๋ก๋ง.
Basic
LDR Rt, [Rn, #imm]: Rt = mem[Rn + imm] (word, 32-bit)STR Rt, [Rn, #imm]: mem[Rn + imm] = RtLDRB Rt, [Rn, #imm]: byte load (zero-extended)STRB Rt, [Rn, #imm]: byte storeLDRH Rt, [Rn, #imm]: halfword loadSTRH Rt, [Rn, #imm]: halfword storeLDRSB,LDRSH: signed byte/halfword load
Register Offset
LDR Rt, [Rn, Rm]: Rt = mem[Rn + Rm]
Multiple Load/Store
LDMIA Rn!, {Rlist}: Rn์์ ์์, reg list์ ์์ฐจ load, Rn updateSTMIA Rn!, {Rlist}: ์ ์ฅ ๋ฒ์ PUSH {Rlist}: Stack์ push (STMDB SP!, {Rlist})POP {Rlist}: Stack์์ pop (LDMIA SP!, {Rlist})
PC-Relative Load
LDR Rt, [PC, #imm]: ์์ ํ ์ด๋ธ ๋ก๋

Branch Instructions
Unconditional Branch
B label: PC = label (ยฑ2 KB)BL label: LR PC+4, PC label (ยฑ16 MB) โ function callBX Rm: PC = Rm (register indirect, Thumb/ARM state switch)BLX Rm: LR PC+4, PC Rm
Conditional Branch
B{cond} label: condition true์ผ ๋๋ง branch- BEQ, BNE, BCS/BHS, BCC/BLO, BMI, BPL, BVS, BVC
- BHI, BLS, BGE, BLT, BGT, BLE
Return from Subroutine
BX LR: return from function (LR์ ์ ์ฅ๋ ์ฃผ์๋ก)POP {PC}: PC๋ฅผ stack์์ ๋ณต์

System Instructions
SVC #imm: Supervisor Call (OS service)WFI: Wait For Interrupt (sleep)WFE: Wait For EventSEV: Send EventDMB: Data Memory BarrierDSB: Data Synchronization BarrierISB: Instruction Synchronization Barrier
Status Register Access
MRS Rd, <reg>: Read special register (APSR, IPSR, EPSR, MSP, PSP, PRIMASK, CONTROL)MSR <reg>, Rn: Write special register

Miscellaneous
NOP: No Operation (pipeline bubble)BKPT #imm: Breakpoint (debug)YIELD: Multi-threading hintREV Rd, Rn: Reverse byte order in word (endian swap)REV16,REVSH: halfword ๋จ์ swap
์์ ์ค์
- 32-bit ์์๋ MOVS + LDR [PC, ...] ๋๋ ์ฌ๋ฌ ๋ช ๋ น์ด๋ก ์กฐ๋ฆฝ
- Thumb-2์์๋ MOVW/MOVT๋ก 16-bit์ฉ ๋ก๋
์์
MOV R0, #0x12 ; R0 = 0x12
LSL R0, R0, #24 ; R0 = 0x12000000
ADD R0, #0x34 ; R0 = 0x12000034
๋๋ LDR pseudo-instruction:
LDR R0, =0x12345678 ; assembler๊ฐ literal pool ์์ฑ

Encoding Format
Thumb 16-bit ๋ช ๋ น์ด๋ opcode + register fields + immediate๋ก ๊ตฌ์ฑ.
์: ADD R0, R1, R2 encoding:
- opcode[15:9]:
0001100 - Rm[8:6]: R2
- Rn[5:3]: R1
- Rd[2:0]: R0
32-bit Thumb-2 ๋ช
๋ น์ด๋ 2๊ฐ์ 16-bit word๋ก ๊ตฌ์ฑ, ์ฒซ word์ ์์ 5-bit๊ฐ 11101, 11110, ๋๋ 11111์ด๋ฉด 32-bit์์ ๋ํ๋.
์ ๋ฆฌ
| ์นดํ ๊ณ ๋ฆฌ | ์ |
|---|---|
| Data processing | ADD, SUB, MUL, AND, ORR, LSL, LSR |
| Load/Store | LDR, STR, PUSH, POP, LDMIA, STMIA |
| Branch | B, BL, BX, B{cond} |
| System | SVC, WFI, DMB, MRS, MSR |
| Misc | NOP, BKPT, REV |
ARM Cortex-M0์ Thumb ๋ช ๋ น์ด๋ ๋จ์ํ๊ณ ๊ณ ์ ๊ธธ์ด (16-bit) ๋ผ์ decode๊ฐ ์ฝ๊ณ ์ฝ๋ ํจ์จ์ด ์ข๋ค. ๋๋ถ๋ถ์ ์๋ฒ ๋๋ ์ฝ๋๊ฐ ์ด ๋ช ๋ น์ด ์งํฉ๋ง์ผ๋ก ๊ตฌํ ๊ฐ๋ฅํ๋ค.

Comments (0)
No comments yet. Be the first to comment!
Please to write a comment.