ARM Architecture


 
* Update history

- 2012.9.11 : Ãʱâ Release



 
7. ARM Instruction Sets
   7.1 Understanding ARM Instruction set
   7.2 ARM Instruction sets
   7.3 Data Processing Instructions
   7.4 Multiply Instructions
   7.5 Load/Store Instructions
   7.6 Load/Store Multiple Instructions    
   7.7 Branch Instructions
   7.8 Status Register Access Instructions
   7.9 Software Interrupt Instruction
   7.10 SWP Instruction
   7.11 Conditional Execution
8. Thumb Instruction Sets
   8.1 Thumb Instruction Ư¡
   8.2 Thumb Instruction Á¦¾à »çÇ×
   8.3 Thumb, ARM Instruction ºñ±³
   8.4 ARM/Thumb Interworking
9. AAPCS
   9.1 Procedure Call Standard for the ARM Architecture
   9.2 Function Parameter Passing


 
7. ARM Instruction Sets
7.1 Understanding ARM Instruction set

ARM Instruction SetÀº ARM ¸í·É¾îµé Áï ¾î¼Àºí¸®¾î¸¦ À̾߱â ÇÏ´Â °ÍÀÔ´Ï´Ù. ´ëºÎºÐÀº C Äڵ带 ÀÌ¿ëÇؼ­ ÀÛ¾÷À» ÇÕ´Ï´Ù¸¸, ¾î¼Àºí¸®¾îµµ ¾î´ÀÁ¤µµ´Â ¼÷ÁöÇÏ°í ÀÖ¾î¾ß ÇÏ´Â ¸î°¡Áö ÀÌÀ¯°¡ ÀÖ½À´Ï´Ù.
(1) ARM ¾î¼Àºí¸®¾î¸¦ Àß ÆľÇÇÏ°í ÀÖÀ¸¸é ARMÀÇ ±¸Á¶¸¦ ´õ Àß ÀÌÇØÇÒ ¼ö ÀÖ½À´Ï´Ù.
(2) ÀüÅëÀûÀÎ ARMÀÇ Startup ÄÚµå´Â ½ºÅÃÀÌ Ãʱâ¿Í µÇ±â Àü¿¡´Â C·Î ÀÛ¼ºÀ» ÇÒ ¼ö°¡ ¾ø½À´Ï´Ù. ÃÖ±Ù Cortex °è¿­Àº Reset º¤ÅÍÀÇ Ãʱ⠹øÁö°¡ Stackaddress¿©¼­ CÄÚµå ¸¸À¸·Îµµ ºÎÆ®·Î´õ ÀÛ¼ºÀÌ °¡´É ÇÕ´Ï´Ù.
(3) CÄÄÆÄÀÏ·¯ÀÇ ÃÖÀûÈ­°¡ ¾ÆÁÖ Àß µÇ¾î ÀÖÁö¸¸, »ç¶÷ÀÌ ÁÖÀÇÇؼ­ ÀÛ¼ºÇÏ´Â ¾î¼Àºí¸® Äڵ庸´Ù´Â ÃÖÀûÈ­ ÇÒ ¼ö ¾ø½À´Ï´Ù.
(4) Debugging in detail (instruction level debugging)

ÀϹÝÀûÀÎ ARM ¾î¼Àºí¸®¾î Çü½Ä ÀÔ´Ï´Ù.



- Directive : ¾î¼Àºí¸® ÄÚµåÀÇ Æ¯¼ºÀ» ÁöÁ¤ÇÏ´Â Áö½Ã¾î ÀÔ´Ï´Ù.
- Label : ¹Ýµå½Ã Space¾øÀÌ Ã¹ ¹ø° Ä÷³¿¡ À§Ä¡ÇØ¾ß ÇÏ°í, Label ÀÚü°¡ Address°¡ µË´Ï´Ù.
- Comment : ÁÖ¼®Àº ";" ¹®ÀÚ ÀÌÈÄ·Î ÀÛ¼ºÀ» ÇÏ¸é µË´Ï´Ù.
- Instructions(ADD, MOV, LDR ...) : ¸í·É¾îµéÀº ¹Ýµå½Ã ¾Õ ºÎºÐ¿¡ Àû¾îµµ Çϳª ÀÌ»óÀÇ Space°¡ ÀÖ¾î¾ß ÇÕ´Ï´Ù.

7.2 ARM Instruction sets

ARM Processor´Â 2°¡Áö ¸í·É¾î ¼¼Æ®¸¦ Áö¿øÇϴµ¥ 32bit ARM ¸í·É¾î¿Í 16bit Thumb ¸í·É¾î°¡ ÀÖ½À´Ï´Ù. Thumb ¸í·É¾î´Â ¸ðµç ARM ÇÁ·Î¼¼¼­¿¡¼­ Áö¿øÇÏ´Â °ÍÀº ¾Æ´Ï°í Thumb Ư¼ºÀ» Áö¿øÇÏ´Â Core¿¡¼­¸¸ »ç¿ëÀÌ °¡´É ÇÕ´Ï´Ù. ÃÖ±Ù Cortex °è¿­¿¡¼­´Â 16bit, 32bit ¸í·É¾î¸¦ °°ÀÌ »ç¿ëÇÒ ¼ö ÀÖ´Â Thumb-2 Instructionµµ Áö¿ø ÇÕ´Ï´Ù. ½ÉÁö¾î Cortex-M3ÀÇ °æ¿ì¿¡´Â Thumb-2 Instruction¸¸ »ç¿ëÀÌ °¡´É ÇÕ´Ï´Ù. 8bit ±æÀÌÀÇ Jave Byte Codeµµ »ç¿ë ÇÒ ¼ö Àִµ¥ À̰͵µ Thumb ¸í·É¾î¿Í °°ÀÌ ¸ðµç ARM Processor°¡ Áö¿øÇÏ´Â °ÍÀº ¾Æ´Õ´Ï´Ù.

Instruction Type Instructions
Data Processing ADD, ADC, SUB, SBC, RSB, AND, ORR, BIC, MOV, CMP, TEQ, …
Multiply MUL, MULS, MLA, SMULL, UMLAL, …
Load/Store LDR, LDRB, LDRH, LDRSH, LDM, STR, STRB, STRH, STRSH, STM, …
Branch B, BL, BX, BLX, …
Status Access MRS, MSR
Swap SWP, SWPB
Coprocessor MRC, MCR, LDC, STC

7.3 Data Processing Instructions

(1) Instructions



< Cond >
ÇØ´ç ¸í·ÉÀÇ Á¶°Ç ½ÇÇà Ç÷¡±×ÀÔ´Ï´Ù. ÇØ´ç Ç÷¡±×¸¦ ÅëÇØ ¸í·ÉÀ» CPSRÀÇ Ç÷¡±× »óÅ¿¡ µû¶ó ¼±ÅÃÀûÀ¸·Î ½ÇÇàÀ» ÇÒ ¼ö ÀÖ½À´Ï´Ù. ARM¿¡¼­ Áö¿øÇÏ´Â ±²ÀåÈ÷ °­·ÂÇÑ ±â´ÉÀ¸·Î Á¶°ÇºÎ ½ÇÇàÀ» Àß ÀÌ¿ëÇÏ¸é ºÐ±â¹®À» ÃÖ´ëÇÑ ÁÙ¿© ½Ã½ºÅÛ ¼º´ÉÀ» Çâ»ó ½Ãų ¼ö ÀÖ½À´Ï´Ù.

< I >
Operland 2·Î ÁöÁ¤µÇ¾î ÀÖ´Â ºÎºÐÀÌ Immediate Operand ÀÎÁö ¾Æ´ÑÁö ¿©ºÎ¸¦ ³ªÅ¸³»´Â ºñÆ® ÀÔ´Ï´Ù. Áï 25¹øÇʵå[I] °¡ "0" À̸é [11 : 0] °¡ shifter operand·Î µ¿ÀÛÀ» ÇÏ°í "1" À̸é Immediate Operand·Î µ¿ÀÛ ÇÕ´Ï´Ù. Immediate Operand¶ó ÇÔÀº, ¿¹¸¦ µé¾î MOV R0, #0x01234 ¶ó°í ÇßÀ» °æ¿ì #0x1234¸¦ °¡¸®Å°´Â ¸»ÀÔ´Ï´Ù.

< Opcode >
µ¥ÀÌÅÍ ÇÁ·Î¼¼½Ì ¸í·É Áß ¾î¶² ¸í·ÉÀÎÁö¸¦ ³ªÅ¸³»´Â Çʵå ÀÔ´Ï´Ù. ÇØ´ç Çʵå¿Í ¸í·É¾î´Â ´ÙÀ½°ú °°½À´Ï´Ù.

Opcode Mnemonic Meaning Action
0000 AND Logical AND Rd = Rn AND shifter_operand
0001 EOR Logical Exclusive OR Rd = Rn EOR shifter_operand
0010 SUB Subtract Rd = Rn - shifter_operand
0011 RSB Reverse subtract Rd = shifter_operand - Rn
0100 ADD Add Rd = Rn + shifter_operand
0101 ADC Add with carry Rd = Rn + shifter_operand + Carry
0110 SBC Subract with carry Rd = Rn – shifter_operand – NOT(Carry)
0111 RSC Reverse Subract with carry Rd = shifter_operand - Rn – NOT(Carry)
1000 TST Test Update flags after Rn AND shifer_opernad
1001 TEQ Test Equivalence Update flags after Rn EOR shifer_opernad
1010 CMP Compare Update flags after Rn - shifer_opernad
1011 CMN Commom Update flags after Rn + shifer_opernad
1100 ORR Logical OR Rd = Rn OR shifter_operand
1101 MOV Move Rd = shifter_operand
1110 BIC Bit clear Rd = Rn AND NOT(shifter_operand)
1111 MVN Move Not Rd = NOT(shifter_operand)

< S >
S ºñÆ®°¡ 1ÀÎ °æ¿ì´Â µ¥ÀÌÅÍ ÇÁ·Î¼¼½Ì ¸í·ÉÀÇ °á°ú°¡ CPSR¿¡ ¿µÇâ(RdÀÇ ·¹Áö½ºÅÍ°¡ PCÀÎ °æ¿ì SPSRÀÇ °ªÀ¸·Î CPSRÀ» º¹¿ø)À» ¹ÌĨ´Ï´Ù.
Áï, 0ÀÎ °æ¿ì¿¡´Â CPSRÀº º¯ÇÏÁö ¾Ê½À´Ï´Ù.

< Rn >
ARM µ¥ÀÌÅÍ ÇÁ·Î¼¼½Ì ¸í·ÉÀº ±× °á°ú¿Í ù ¹ø° ¿ÀÆÛ·£µå´Â Ç×»ó ·¹Áö½ºÅÍ·Î ÁöÁ¤ÇØ¾ß ÇÕ´Ï´Ù. RnÀº ù ¹ø° ¿ÀÆÛ·£µå¸¦ °¡¸®Å°´Â °ÍÀ¸·Î À§¿¡¼­ Op1À¸·Î Ç¥±âÇÑ °Í¿¡ ÇØ´çÇÕ´Ï´Ù. ARM¿¡¼­ Çѹø¿¡ º¼ ¼ö ÀÖ´Â ¹ü¿ë ·¹Áö½ºÅÍ´Â sp, lr, pc µîÀ» Æ÷ÇÔÇؼ­ r0~r15 ±îÁöÀÔ´Ï´Ù. Áï, 4Bit¸¦ ÅëÇØ ·¹Áö½ºÅ͸¦ ³ªÅ¸³»°Ô µË´Ï´Ù. ÇØ´ç Çʵå´Â ¸í·É¿¡ µû¶ó »ç¿ëµÇÁö ¾Ê±âµµ ÇÕ´Ï´Ù. MOV³ª MVNµîÀÌ ÀÌ¿¡ ÇØ´çÇÕ´Ï´Ù.

< Rd >
¿ÀÆÛ·¹À̼ÇÀÇ °á°ú°¡ ÀúÀåµÉ ·¹Áö½ºÅ͸¦ ÀǹÌÇÕ´Ï´Ù. ¿ª½Ã ·¹Áö½ºÅ͸¦ °¡¸®Å°¹Ç·Î 4Bit¸¦ »ç¿ëÇÏ°í ¸ðµç ¸í·É¿¡¼­ µðÆúÆ®·Î »ç¿ëµÇ´Â Çʵå. ARMÀÇ µ¥ÀÌÅÍ ÇÁ·Î¼¼½Ì ¸í·ÉÀÇ °á°ú´Â Ç×»ó ·¹Áö½ºÅÍ·Î µé¾î°©´Ï´Ù.

< Operand 2 >
Immediate Operand ȤÀº ·¹Áö½ºÅÍ Operand ÀÔ´Ï´Ù. <I> Çʵ尡 0ÀÏ °æ¿ì ·¹Áö½ºÅÍ ÀÔ´Ï´Ù.

(2) Syntax : <operation>{cond}{s} Rd, Rn, operand2

- Operand2 is a register
ADD R0, R1, R2

- Operand2 is immediate value
BIC R1, R2, #0xFF

- Operand2 shifted value
ADD R0, R1, R2, LSL #2
SUB R0, R1, R2, LSR R3

- Data movement
MOV R0, R1
MOV R0, #0x1

- Comparisons set flags only
CMP R0, R1
CMP R2, #0x01

(3) Immediate value




Immediate value(»ó¼ö °ª)= ROR immed_8 by 2*rot

MOV R0, #0xFF000000
MOV R0, #0x12
MOV R0, #0x104 ; 100000100 --> permitted
MOV R0, #0x102 ; 100000010 --> not permitted
MOV R0, #0x12345678 ; 10010001101000101011001111000--> not permitted

À§ÀÇ ¿¹Á¦¿¡¼­ »ó¼ö °ªÀ¸·Î "#0x104" ´Â »ç¿ëÇÒ ¼ö Àִµ¥ "#0x102", "#0x12345678" °ªÀ¸·Î ¿Ã¼ö ¾ø´Â ÀÌÀ¯´Â ¹«¾ù Àϱî¿ä?
"ROR immed_8 by 2*rot" ÀÇ ¼ö½ÄÀ» Àß »ìÆì º¸½Ã±â ¹Ù¶ø´Ï´Ù. ¾î·Æ´Ù±¸¿ä ? ^^ ³×. ½¬¿î °è»êÀÌ ¾Æ´Ò ¼ö ÀÖ½À´Ï´Ù.
¿ì¼± "#0x12345678" °ªÀº ½±°Ô ÆÇ´ÜÀÌ µÉ°Í °°Àºµ¥¿ä. Rotate¾øÀÌ Ç¥Çö °¡´ÉÇÑ °ªÀÇ ¹üÀ§°¡ 8bit ¸¦ ³Ñ¾ú½À´Ï´Ù.
"#0x102" ´Â ¿Ö ¾ÈµÉ°¡¿ä ? ½±°Ô »ý°¢Çϸé 8-bit immediate °ªÀ» #rot °ªÀ» 2¹è ÇѸ¸Å­ ¿À¸¥ÂÊÀ¸·Î ·ÎÅ×À̼ÇÀ»(ROR) Çؼ­ Immediate valueÀ» ¸¸µé ¼ö ÀÖ´Â °ªÀ» ¹Ýµå½Ã »ó¼ö·Î »ç¿ëÇØ¾ß ÇÑ´Ù´Â ¸»ÀÔ´Ï´Ù. ¿ª½Ã ¸»·Î´Â Àß ¼³¸íÀÌ µÇÁö ¾Ê³×¿ä. ¾Æ·¡ ±×¸²µéÀ» ÂüÁ¶ ÇϽñ⠹ٶø´Ï´Ù.





¾Æ·¡ Immediate valueÀÇ ¶Ç ´Ù¸¥ ¿¹Á¦ ÀÔ´Ï´Ù.
MOV r0, #0xfc000003 ; 11111100000000000000000000000011
r0¿¡ »ó¼ö °ª 0xfc000003À» ³Ö´Â ¸í·ÉÀÔ´Ï´Ù. ÇØ´ç °ªÀº 8Bit °ª 0xFF¸¦ 32Bit·Î È®ÀåÇÏ°í ¿À¸¥ÂÊÀ¸·Î 6¹ø Rotate ½ÃŲ °ªÀÔ´Ï´Ù. ±×·¡¼­ ¿¡·¯°¡ ³ªÁö ¾Ê½À´Ï´Ù.

(4) 32-bit Instruction format

MOV R0, #1

±²ÀåÈ÷ ´Ü¼øÇÑ ¿¹Á¦ Àä. À§¿¡¼­ ¹è¿î 32-bit Instructions Æ÷¸ËÀ» ºÐ¼®ÇØ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. Äڵ带 Disassebly Çغ¸¸é
"0xE3A00001(1110 001 1101 0 0000 0000 0000 00000001)" ÀÔ´Ï´Ù.



Instruction Æ÷¸ËÀ» ´Ù½ÃÇѹø »ìÆì º¸¸é ¾Æ·¡¿Í °°½À´Ï´Ù.



[31:28] : 1110 - 7.11 Conditional Execution ¿¡¼­ ¹è¿ï ¿¹Á¤ ÀÔ´Ï´Ù. ¿ì¼±Àº ±×³É "1110" Àº Always execution flag ¶ó°í ¾Ë¾Æ µÎ½Ã±â ¹Ù¶ø´Ï´Ù.
[27:25] : 001 - Operland 2·Î ÁöÁ¤µÇ¾î ÀÖ´Â ºÎºÐÀÌ Immediate OperandÀ̹ǷΠ25¹ø ºñÆ®°¡ "1" ÀÔ´Ï´Ù.
[24:21] : 1101 - Opcode "MOV" ´Â "1101" ÀÔ´Ï´Ù.
[20] : 0 - ¸í·É¾î Opcode¿¡ "S" °¡ ºÙÁö ¾Ê¾ÒÀ¸¹Ç·Î CPSR¿¡ ¿µÇâÀ» ¹ÌÄ¡´Â ¸í·É¾î´Â ¾Æ´Õ´Ï´Ù.
[19:16] : 0000 - Rn ºÎºÐÀ¸·Î ·¹Áö½ºÅÍ ¹øÈ£¸¦ Ç¥Çö ÇÕ´Ï´Ù. ¸¸¾à "MOV R2, #1" ¿´´Ù¸é Rn ÀÌ "0000" ÀÌ ¾Æ´Ï¶ó "0010" ÀÏ °ÍÀÔ´Ï´Ù.
[15:12] : 0000 - Rd ºÎºÐÀÌ ¾øÀ¸¹Ç·Î "0000" ÀÔ´Ï´Ù.
[11:0] : 8bit Immediate value ·Î¼­ "#1" ¿¡ ÇØ´çÇÏ´Â "00000001" ÀÔ´Ï´Ù.

* Âü°í
MOV R2, #1 ¸í·É¿¡ ´ëÇÑ 32-bit Instruction Æ÷¸Ë = 0xE3A02001(1110 001 1101 0 0000 0010 0000 00000001)

(5) Examples

R0 = 0x00
R1 = 0x22
R2 = 0x02
R3 = 0x00
R4 = 0x00



·¹Áö½ºÅÍÀÇ °ªµéÀÌ À§¿Í °°À»¶§ ¾Æ·¡ ¿¹Á¦µéÀ» Â÷·Ê´ë·Î ¼öÇà ÇßÀ»¶§ÀÇ °¢°¢ÀÇ ·¹Áö½ºÅÍ °ªÀº ?

AND R0, R0, #0xFF ; 0x00 & 0xff = R0ÀÇ °ªÀº º¯È¯ ¾øÀ½



ADD R0, R0, #1 ; R0 = R0 + 1 = 0x1



ADD R0, R0, R1 ; R0 = R0 + R1 = 0x01 + 0x22 = 0x23



LSL R1, R0, #2 ; 0x23(100011) LSL #2 = 0x8C(10001100) -> Âü°í·Î ¿ÞÂÊÀ¸·Î 2¹ø ½¬ÇÁÆ® Çϸé *4 ¸¦ ÇÑ°Í°ú °°½À´Ï´Ù.



SUB R3, R2, R1, LSR R2

R3ÀÇ °ªÀÌ 0xFFFFFFDF ·Î º¹ÀâÇÑ °ªÀÌ ³ª¿Ô½À´Ï´Ù. ¿Ö ÀÌ·± °á°ú°¡ ³ª¿ÔÀ»±î¿ä ?
¿ì¼± R1À» ¿À¸¥ÂÊÀ¸·Î 2¹ø ½¬ÇÁÆ® ½ÃÅ°¸é 0x23ÀÌ µÇ°í R2(0x02) ¿¡¼­ R1(0x23) À» »©¸é °á°ú°ªÀÌ -0x21°¡ µÇ°í ÀÌ °ªÀ» 2ÀÇ º¸¼ö·Î Ç¥½ÃÇϸé
0xFFFFFFDF °¡ µË´Ï´Ù.

  0x21 = 00000000000000000000000000100001
-0x21 = 11111111111111111111111111011111 --> 0x21ÀÇ 2ÀÇ º¸¼ö

Âü°í·Î 2ÀÇ º¸¼ö¸¦ ÃëÇÏ´Â ¹æ¹ýÀº ¿ø·¡ÀÇ 2Áø¼ö¿¡¼­ 0->1, 1->0 À¸·Î ¹Ù²ÛÈÄ¿¡ 1À» ´õÇÏ¸é µÇ°ÚÁö¿ä.



BIC R0, R1, #0xFF00

R1(0x8C) =         0000000010001100
0xFF00(65280) = 1111111100000000
BIC =                0000000010001100   ; 0xFF00 ·Î Bit clear¸¦ Çصµ R1ÀÇ °ªÀº º¯È­°¡ ¾ø³×¿ä.




RSB R0, R1, #0 ; #0 - R1(0x8C) = 0xFFFFFF74(0x8C ÀÇ 2ÀÇ º¸¼ö °ª)

RSB ¸í·É¾î´Â SUB¿Í´Â ¹Ý´ë·Î ¸¶À̳ʽº ¿¬»êÀ» ¼öÇà ÇÕ´Ï´Ù.




7.4 Multiply Instructions

(1) Multiply (Accumulate) Syntax
MUL{<cond>}{S} Rd, Rm, Rs ; Rd = Rm * Rs
MUA{<cond>}{S} Rd, Rm, Rs, Rn ; Rd = (Rm * Rs) + Rn

(2) Examples

R0 = 0x01
R1 = 0x02
R2 = 0x03
R3 = 0x04



·¹Áö½ºÅÍÀÇ °ªµéÀÌ À§¿Í °°À»¶§ ¾Æ·¡ ¿¹Á¦µéÀ» Â÷·Ê´ë·Î ¼öÇà ÇßÀ»¶§ÀÇ °¢°¢ÀÇ ·¹Áö½ºÅÍ °ªÀº ?

MUL R2, R0, R1 ; R2 = R0*R1 = 0x02



MULS R2, R0, R1 ; R2 = R0*R1 = 0x02

MUL ¸í·É°ú °°Àº ¸í·ÉÀÔ´Ï´Ù. ÇÏÁö¸¸ MULµÚ¿¡ "S" °¡ ºÙÀ¸¸é ¸í·É¾î 󸮰¡ ³¡³­ ÀÌÈÄ¿¡ CPSRÀÇ Flag Field °¡ ¿¬»ê °á°ú¿¡ µû¶ó¼­ ¾÷µ¥ÀÌÆ®°¡ µË´Ï´Ù.
ÀÚ¼¼ÇÑ »çÇ×Àº 7.11 Conditional Execution ¿¡¼­ ÀÚ¼¼È÷ ´Ù·çµµ·Ï ÇÏ°Ú½À´Ï´Ù.



MLA R3, R2, R1, R0 ; R3 = R2*R1 + R0

Âü È¿À²ÀûÀ̳׿ä. ¸í·É¾î Çϳª·Î °öÇϱ⠿¬»ê°ú ´õÇϱ⠿¬»êÀ» °°ÀÌ ÇÒ ¼ö ÀÖ½À´Ï´Ù.



SMULL R3, R2, R1, R0 ; R3,R2 = R1*R0

ºÎÈ£ÀÖ´Â 64ºñÆ® °ö¼À ¸í·É¾î ÀÔ´Ï´Ù. R1*R0 ÇÏ¿© »óÀ§ 32ºñÆ®´Â R2¿¡ ÇÏÀ§ 32ºñÆ®´Â R3¿¡ ÀúÀå ÇÕ´Ï´Ù.



À§¿¡¼­ ºÎÈ£ÀÖ´Â ¿¬»êÀÌ ³ª¿Ô´Âµ¥, Á»´õ º¹ÀâÇÑ ¿¹Á¦¸¦ Ç®¾î º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

R0 = 0xF0000002
R1 = 0x02

R2 = 0x00
R3 = 0x00


Ãʱ⠷¹Áö½ºÅÍÀÇ °ªÀÌ À§¿Í °°À»¶§ SMULL ¿¬»ê ÀÌÈÄÀÇ R2, R3 ÀÇ °ªÀº ¾î¶»°Ô µÉ±î¿ä ?

¿ì¼± 0xF0000002°¡ À½¼ö À̱⠶§¹®¿¡ ¿¬»êÀ» Çϱâ À§Çؼ­´Â 2ÀÇ º¸¼ö°ª(F0000002ÀÇ 2ÀÇ º¸¼ö = 0xFFFFFFE)À» ¸ÕÀú ÃëÇÕ´Ï´Ù. ±×¸®°í ³ª¼­ 0xFFFFFFE * 0x02 = 0x1FFFFFFC ¸¦ ÇÕ´Ï´Ù. ¿¬»êÀÌ ³¡³ª°í ³ª¼­ À½¼ö¸¦ Ç¥ÇöÇϱâ À§Çؼ­ ´Ù½Ã 0x1FFFFFFC ÀÇ 2ÀÇ º¸¼ö¸¦ ÃëÇÕ´Ï´Ù. À̶§ SMULLÀÌ 64ºñÆ® °ö¼À ¸í·É¾î À̹ǷΠ64ºñÆ®·Î È®Àå ÇÕ´Ï´Ù. ÀÌ·¸°Ô ÇÏ¸é »óÀ§ 32ºñÆ®´Â 0xFFFFFFFF ÀÌ°í ÇÏÀ§ 32ºñÆ®´Â 0x04°¡ µË´Ï´Ù.



À§ÀÇ ±×¸²¿¡¼­ "MOV R0, #-268435454" ¶ó°í R0¸¦ ÃʱâÈ­ ÇÏ°í ÀÖ½À´Ï´Ù. ÀÌ°ÍÀº 0xf0000002ÀÇ °ªÀÌ À½¼ö(ÃÖ»óÀ§ ºñÆ®°¡ 1À̸é À½¼öÀÌÁÒ)À̱⠶§¹®¿¡ ÄÄÆÄÀÏ·¯¿¡¼­ ¾Ë±â ½±µµ·Ï À½¼ö 10Áø¼ö·Î Ç¥ÇöÀ» ÇØÁØ°Í ÀÔ´Ï´Ù.

7.5 Load/Store Instructions

MemoryÀÇ ³»¿ëÀ» ·¹Áö½ºÅÍ·Î À̵¿(Load)Çϰųª ·¹Áö½ºÅÍÀÇ ³»¿ëÀ» ¸Þ¸ð¸®¿¡ ÀúÀå(Store) ÇÏ´Â ¸í·É¾î ÀÔ´Ï´Ù. µ¥ÀÌÅÍ Access´ÜÀ§¿¡ µû¶ó¼­ ¾Æ·¡¿Í °°ÀÌ ºÐ·ù µË´Ï´Ù. Load, Store´Â ARM ¸í·É¾î °¡¿îµ¥ °¡Àå ¸¹ÀÌ »ç¿ëµÇ´Â ¸í·É¾î ÀÌ¸ç ±²ÀåÈ÷ Áß¿äÇÕ´Ï´Ù. ¹Ýµå½Ã ¼÷Áö ÇÏ°í ÀÖ¾î¾ß ÇÕ´Ï´Ù.

- Word : LDR, STR
- Byte : LDRB, STRB
- Halfword : LDRH, STRH
- Signed byte : LDRSB
- Signed halfword : LDRSH

(1) Syntax
LDR{cond}{size} Rd, <address>
STR{cond}{size} Rd, <address>

(2) Addressing Mode

- Pre Index : Rd ·¹Áö½ºÅÍ¿¡ µ¥ÀÌÅ͸¦ ¸ÕÀú À̵¿½ÃŲ ÈÄ <address> offsetÀ» Áõ°¡ ȤÀº °¨¼Ò ÇÕ´Ï´Ù.

R0 = 0x31000000
R1 = 0x00
R2 = 0x00



·¹Áö½ºÅÍÀÇ °ªµé°ú ¸Þ¸ð¸®(¸Þ¸ð¸® ¹è¿­Àº ¸®Æ² ¿£µð¾ð) °ªÀÌ À§¿Í °°À»¶§ ¾Æ·¡ ¿¹Á¦µéÀ» Â÷·Ê´ë·Î ¼öÇà ÇßÀ»¶§ÀÇ °¢°¢ÀÇ ·¹Áö½ºÅÍ¿Í ¸Þ¸ð¸®ÀÇ °ªÀº ?

LDR R1, [R0] ; R1 <-- M[R0]

R0°¡ °¡¸£Å°°í ÀÖ´Â 0x31000000 ¹øÁöÀÇ ¸Þ¸ð¸® °ªÀº 0x67452301 ÀÔ´Ï´Ù. ±×·¯¹Ç·Î LDR ¿¬»ê ÀÌÈÄ¿¡ R1¿¡´Â 0x67452301 °ªÀÌ ÀúÀå µË´Ï´Ù.



STR R1, [R0, #4] ; R1 <-- M[R0+4]

R0°¡ °¡¸£Å°´Â 0x31000000 ¹øÁö¿¡¼­ 4-byte ¸¦ ´õÇÑ ¹øÁöÀÇ ¸Þ¸ð¸® À§Ä¡¿¡ R1(0x67452301) °ªÀ» ÀúÀå ÇÕ´Ï´Ù.



STR R1, [R0, #4]! ; R1 <-- M[R0+4], then R0 <-- R0+4



R1¿¡ 0x31000004¹øÁöÀÇ ¸Þ¸ð¸® ³»¿ë 0x67452301À» ÀúÀåÇÏ°í ³­ ÀÌÈÄ¿¡ R0ÀÇ ·¹Áö½ºÅÍ°ª + 0x04 ¸¦ ¼öÇà ÇÕ´Ï´Ù.
¿¹Á¦¿¡¼­ 0x30000000, 0x30000004 ¹øÁöÀÇ ³»¿ëÀÌ µ¿ÀÏÇؼ­ È¥µ¿ µÜ¼öµµ ÀÖÁö¸¸ R1¿¡´Â R0·¹Áö½ºÅÍ°ª + 0x04 = 0x30000004 ¹øÁöÀÇ °ªÀÌ ÀúÀåÀÌ µÈ´Ù´Â °ÍÀ» ±â¾ï ÇϽñ⠹ٶø´Ï´Ù.



- Post Index: Offset calculation after data transfer

R0 = 0x31000000
R1 = 0x00
R2 = 0x04



·¹Áö½ºÅÍÀÇ °ªµé°ú ¸Þ¸ð¸®(¸Þ¸ð¸® ¹è¿­Àº ¸®Æ² ¿£µð¾ð) °ªÀÌ À§¿Í °°À»¶§ ¾Æ·¡ ¿¹Á¦µéÀ» Â÷·Ê´ë·Î ¼öÇà ÇßÀ»¶§ÀÇ °¢°¢ÀÇ ·¹Áö½ºÅÍ¿Í ¸Þ¸ð¸®ÀÇ °ªÀº ?

LDR R1, [R0], R2 ; R1 <-- M[R0], then R0 <-- R0+R2

R1¿¡ R0 °¡ °¡¸£Å°´Â 0x31000000¹øÁöÀÇ ¸Þ¸ð¸®°ª 0x67452301ÀÇ °ªÀ» ÀúÀåÇÏ°í ³ª¼­ R0 = R0(0x31000000) + R2(0x04) °¡ µË´Ï´Ù.
Preindex ¹æ½Ä¿¡¼­´Â R0¸¦ ¸ÕÀú °è»êÇÏ°í ³ª¼­ ¸Þ¸ð¸® ¹øÁöÀÇ °ªÀ» R1¿¡ ÀúÀåÇÏ¿´À¸³ª Postindex ¹æ½Ä¿¡¼­´Â ¼ø¼­°¡ ¹Ý´ë°¡ µË´Ï´Ù.



STR R1, [R0], #4 ; R1 <-- M[R0], then R0 <-- R0+4



·¹Áö½ºÅÍ R1ÀÇ °ª 0x67452301À» ¸Þ¸ð¸® 0x31000004 ¹øÁö¿¡ ÀúÀåÀ» ÇÏ°í³­ ÀÌÈÄ¿¡ R0 = R0(0x310000004) + 0x04 ¸¦ ¼öÇà ÇÕ´Ï´Ù.



(3) Literal Pool
32bitÀÇ ¸ðµç °ªÀ» °¡Áú ¼ö ¾ø°í 12bit¸¦ °¡Áö°í ÀÏÁ¤ Çü½Ä¿¡ ¸ÂÃ߾ »ç¿ëÇØ¾ß ÇÕ´Ï´Ù. Immediate value ¿¡¼­ ÀÚ¼¼È÷ ¼³¸í Çß´ø ³»¿ëÀÔ´Ï´Ù.

MOV R0, #0x12345678 ; illegal (build error)
LDR R0, =0x12345678 ; legal (build success)
MOV R0, #0x104 ; legal
MOV R0, #0x102 ; illegal

À§ÀÇ ¿¹Á¦¿¡¼­ 0x12345678 °ªÀ» LDR ¸í·É¾î¸¦ »ç¿ëÇϸé Á¦¾à ¾øÀÌ »ç¿ëÀÌ °¡´ÉÇÑ °ÍÀ» ¾Ë¼ö ÀÖ½À´Ï´Ù. LDR¸í·É¾î¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ÆíÇغ¸À̱â´Â ÇÏÁö¸¸ ¸Þ¸ð¸®¿¡ Á¢±ÙÇϱ⠶§¹®¿¡ ¼Óµµ´Â ¸¹ÀÌ ´À·ÁÁö°ÚÁö¿ä..

7.6 Load/Store Multiple Instructions

LDR, STR ¸í·É¾î¿Í ±â´ÉÀº µ¿ÀÏ ÇÏÁö¸¸ Rn·¹Áö½ºÅÍ °ªÀÌ °¡¸£Å°´Â ¸Þ¸ð¸® À§Ä¡¾Ö ¿©·¯°³ ·¹Áö½ºÅÍ °ªµéÀ» ÀúÀå ÇÒ ¼ö ÀÖ½À´Ï´Ù.

(1) Syntax
LDM{cond}{addr_mode} Rn{!}, <register_list>{^}
STM{cond}{addr_mode} Rn{!}, <register_list>{^}

(2) Addressing Mode
- IA : increment after
- IB : increment before
- DA : decrement after
- DB : decrement before

(3) Examples

* ·¹Áö½ºÅÍ °ªµé

R0 = 0x000A

R4 = 0x000B

R5 = 0x000C

R13 = 0xFFF0


STMIA R13!, {R0,R4-R5} ¿¬»êÀÇ °á°ú´Â ?



STMIB R13!, {R0,R4-R5} ¿¬»êÀÇ °á°ú´Â ?



STMDA R13!, {R0,R4-R5} ¿¬»êÀÇ °á°ú´Â ?




STMDB R13!, {R0,R4-R5} ¿¬»êÀÇ °á°ú´Â ?



Âü°í·Î ARM Compiler´Â Stack µ¿À۽à Full Descending Stack ¹æ½ÄÀ¸·Î µ¿ÀÛ ÇÏ°í ÀÖ½À´Ï´Ù. STMDA ¸í·É¾î¿Í µ¿ÀÏÇÑ ¹æ½Ä ÀÔ´Ï´Ù. Áï Stack Pointer´Â Ç×»ó À¯È¿ÇÑ µ¥ÀÌÅ͸¦ °¡¸£Å°°í ÀÖ°í ÁÖ¼Ò°¡ °¨¼ÒÇÏ´Â ¹æÇâÀ¸·Î ÀúÀåÀÌ µË´Ï´Ù.

- Stack ¿¡¼­ PUSH, STMDB ´ë½Å¿¡ ¾Æ·¡¿Í °°ÀÌ »ç¿ëÀÌ °¡´É ÇÕ´Ï´Ù.
STMFD SP!, {R4-R12, LR}


- Stack ¿¡¼­ POP, LDMIA ´ë½Å¿¡ ¾Æ·¡¿Í °°ÀÌ »ç¿ëÀÌ °¡´É ÇÕ´Ï´Ù.
LDMFD SP!, {R4-R12, PC}
LDMFD SP!, {R0-R12, PC}^

"^" ¿¬»êÀÚ´Â ¸ñÀûÁöÀÇ ·¹Áö½ºÅÍ(Rd)°¡ PCÀÎ °æ¿ì¿¡ SPSRÀ» CPSR·Î ºÏ±¸±îÁö Ç϶ó´Â ¸í·É ÀÔ´Ï´Ù.

7.7 Branch Instructions

Ȥ½Ã ¼­ºê ÇÔ¼ö¿Í ¼­ºê ÇÁ·Î½ÃÁ®ÀÇ Â÷ÀÌÁ¡À» ¾Ë°í ÀÖ³ª¿ä ? 2°¡Áö ¸ðµÎ ¸ÞÀÎ ÇÁ·Î±×·¥ È帧¿¡¼­ ¹þ¾î(ºÐ±âÇÏ¿©)³ª ƯÁ¤ ÀÛ¾÷À» ¼öÇàÇÏ´Â °ÍÀº µ¿ÀÏ ÇÕ´Ï´Ù. ÇÏÁö¸¸ ¾ö¹ÐÇÏ°Ô Â÷ÀÌÁ¡À» À̾߱â ÇÏ¸é ¼­ºê ÇÁ·Î½ÃÁ®´Â ºÐ±â ÀÌÈÄ¿¡ ºÐ±âÇϱâ ÀÌÀüÀÇ È帧À¸·Î µÇµ¹¾Æ ¿ÀÁö ¾Ê°í ºÐ±âÇÑ ÁÖ¼Ò¿¡¼­ ºÎÅÍ ÇÁ·Î±×·¥ ¼öÇàÀÌ °è¼Ó µÉ °æ¿ì¿¡ »ç¿ëÀ» ÇÏ°í ¼­ºê ÇÔ¼ö´Â ºÐ±âÇÑ ÁÖ¼Ò¿¡¼­ ƯÁ¤ ÀÛ¾÷À» ¼öÇàÇÏ´Ù°¡ ºÐ±â ÀÌÀüÀÇ ÁÖ¼Ò·Î º¹±ÍÇÏ¿© ÇÁ·Î±×·¥À» ¼öÇà Çϵµ·Ï ÇÕ´Ï´Ù. ¼³¸íÀÌ ±æ¾î Á³³×¿ä. ±×¸²À» ÅëÇؼ­ Â÷ÀÌÁ¡À» ±¸ºÐÇØ º¸µµ·Ï ÇսôÙ.

* ¼­ºê ÇÁ·Î½ÃÁ® È£Ãâ½Ã ÇÁ·Î±×·¥ È帧


* ¼­ºê ÇÔ¼ö È£Ãâ½Ã ÇÁ·Î±×·¥ È帧




(1) Syntax
B{L}{cond} <target_addr>
target_addr <-- pc + SignExtended(immed_24)<<2

- ¿©±â¼­ PC´Â Pipeline ¿¡¼­ ¼³¸í Çßµå½Ã Branch Instruction ÀÇ ÁÖ¼Ò¿¡¼­ 8À» ´õÇÑ À§Ä¡°¡ µË´Ï´Ù.

(2) Branch Range
-32MB ~ +32MB

ºÐ±â ¹üÀ§°¡ +- 32MB ±îÁö·Î Á¦ÇÑÀÌ µÇ´Â ÀÌÀ¯´Â 2^24 = 16MB << 2 ¸¦ Çϸé 64MB ÀÌ°í À̸¦ +- ·Î Çϸé 32MB ±îÁö°¡ µÇ´Â °ÍÀÔ´Ï´Ù.

(3) Examples
B Label
MOV PC, #0
MOV PC, LR

·¹Á¦½ºÅÍ R15(PC) ¿¡ Á÷Á¢ ºÐ±âÇÒ ÁÖ¼Ò¸¦ ÀúÀåÇÏ¿©µµ ºÐ±â°¡ °¡´É ÇÕ´Ï´Ù.

LDR PC, =func

Âü°í·Î LDR ¸í·É¾î¸¦ »ç¿ëÇϸé Branch¸í·É¾î¸¦ »ç¿ëÇßÀ»¶§º¸´Ù 1°¡Áö ÀÕÁ¡ÀÌ Àִµ¥ 4GBÀ̳»¿¡¼­´Â ¾îµðµçÁö ºÐ±â°¡ °¡´É ÇÏ´Ù´Â °ÍÀÔ´Ï´Ù.
Branch ¸í·É¾îÀÇ ºÐ±â range´Â -32MB ~ +32MBÀÇ Á¦¾àÀÌ ÀÖ½À´Ï´Ù. ¹°·Ð ¸Þ¸ð¸®¿¡¼­ ÁÖ¼Ò¸¦ Àоî¿Í¾ß ÇϹǷΠ¼º´É¸é¿¡¼­´Â ÁÁÁö ¾Ê°ÚÁö¿ä.

(5) ÇÔ¼ö È£Ãâ(BL)
- ÇÔ¼ö È£Ãâ½Ã
BL func --> B ¸í·É¾î¿Í ´Ù¸¥Á¡Àº LR·¹Áö½ºÅÍ¿¡ PC-4 ÀÇ Address°ªÀÌ H/WÀûÀ¸·Î ÀúÀåÀÌ µË´Ï´Ù.

- ARM ¸ðµå ÇÔ¼ö Á¾·á½Ã
MOV PC, LR --> LR ¿¡´Â ÀÌ¹Ì BL ¸í·É¾îÀÇ ÁÖ¼Ò +4 ÀÇ °ªÀÌ ÀúÀåÀÌ µÇ¾î ÀÖ¾î BL ¸í·É¾î ´ÙÀ½ºÎÅÍ ¸í·ÉÀ» ¼öÇàÇÒ ¼ö ÀÖµµ·Ï ÇÕ´Ï´Ù.

- Thumb ¸ðµå ÇÔ¼ö Á¾·á½Ã
BX LR

(6) Subsequent Function Calls
ÇÔ¼ö¾È¿¡¼­ ÇÔ¼ö¸¦ ´Ù½Ã È£ÃâÀ» ÇÏ¸é ¾î¶²ÀÏÀÌ ¹ß»ýÀ» ÇÒ°¡¿ä. ¿¹Á¦ Äڵ带 °¡Áö°í ºÐ¼®ÇØ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.


À§ÀÇ ¿¹Á¦¿¡¼­ ¼­ºêÇÔ¼ö¸¦ È£ÃâÇÏ°í³­ ÀÌÈÄ¿¡ main ·çƾ¿¡ ÀÖ´Â R2¿¡´Â #3ÀÌ ÀúÀåÀÌ µÇ¾î ÀÖ¾î¾ß ÇÕ´Ï´Ù. ¾ð¶æ º¸±â¿¡ #11ÀÌ ÀúÀåÀÌ µÇ¾î ÀÖÀ»°Í °°½À´Ï´Ù.
R0, R1Àº func1¿¡¼­ °¢°¢ #3, #4 °¡ ÀúÀåÀÌ µÇ°í func2¸¦ °ÅÄ¡¸é¼­ #5, #6ÀÌ ÀúÀåÀÌ µË´Ï´Ù. ±×·¡¼­ #11ÀÌ µÉ°ÍÀ̶ó°í ¿¹»óÀÌ µÉ¼ö ÀÖÁö¸¸ »ç½ÇÀº func1ÀÇ ADD ¸í·É¾î¸¸ ¹Ýº¹Çؼ­ ½ÇÇàÀÌ µÉ°ÍÀÔ´Ï´Ù. ¿Ö³ÄÇϸé main¿¡¼­ func1À¸·Î branchÇÒ¶§±îÁö´Â LR¿¡´Â BL¸í·É¾î Address+4 °¡ ÀúÀåÀÌ µÇ°í func1¿¡¼­ func2·Î ºÐ±â ÇÒ¶§ ´Ù½Ã LR¿¡´Â func2·Î ºÐ±âÇÏ´Â BL¸í·É¾î Address+4°¡ ÀúÀåÀÌ µÇ¾î ÃÖÁ¾ func2¿¡¼­ MOV PC, LR À» ½ÇÇàÀ» Çϸé func1ÀÇ ADD ¸í·É¾î·Î PC°¡ À̵¿À» ÇÏ°í ´Ù½Ã func1¿¡¼­ MOV PC, LR ÀÌ ½ÇÇàÀÌ µÇ¸é LR °ª¿¡ ÀÇÇؼ­ ´Ù½Ã func1ÀÇ ADD ¸í·É¾î°¡ ¹Ýº¹Çؼ­ ½ÇÇàÀÌ µÉ°ÍÀÔ´Ï´Ù. Á¶±Ý º¹ÀâÇѵí ÇÏÁö¸¸ Àß µû¶ó°¡ º¸¸é ¾Ë ¼ö ÀÖ½À´Ï´Ù. ÀÌ ¿¹Á¦¿¡¼­ ¾Ë¼ö Àִ°ÍÀº ¼­ºê ÇÔ¼ö¸¦ È£ÃâÇÒ °æ¿ì¿¡´Â ¼­ºêÇÔ¼ö³»¿¡¼­ ¹Ýµå½Ã LR°ú ¼­ºêÇÔ¼ö¿¡¼­ »ç¿ëÇÒ ·¹Áö½ºÅ͵éÀ» Stack¿¡ ¹é¾÷À» ÇÏ°í ¼­ºêÇÔ¼ö¿¡¼­ º¹±ÍÀü¿¡ ´Ù½Ã Stack¿¡¼­ º¹¿øÀ» ÇØ¾ß ÇÑ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù. ±×·¯¸é À§ÀÇ ¿¹Á¦¸¦ main ·çƾ¿¡ ÀÖ´Â R2¿¡ #3ÀÌ ÀúÀåÀÌ µÇµµ·Ï ¼öÁ¤À» ÇÏ¸é ¾î¶»°Ô µÉ±î¿ä ?



À§ÀÇ ±×¸²¿¡¼­ MOV SP, #98304 ¸¦ ÇÏ´Â ÀÌÀ¯´Â StackÀ» »ç¿ëÇϱâ À§Çؼ­ Supervisor ¸ðµåÀÇ Stack Æ÷ÀÎÅ͸¦ ÃʱâÈ­ ÇÏ´Â °ÍÀÔ´Ï´Ù. Âü°í·Î Stack Æ÷ÀÎÅÍÀÇ ÁÖ¼Ò´Â ½ÇÁ¦ Ÿ°Ù¸¶´Ù ´Ù¸¦ ¼ö ÀÖ½À´Ï´Ù. Stack Æ÷ÀÎÅÍ´Â ÁÖ·Î ½Ã½ºÅÛÀÇ ÁÖ ¸Þ¸ð¸®¿¡ À§Ä¡ ÇÕ´Ï´Ù.

(7) Veneer
º£´Ï¾î¶ó´Â ¿ë¾î°¡ ³ª¿À³×¿ä. Ȥ½Ã º£´Ï¾î ÇÕÆÇ À̶ó´Â ¸»À» µé¾î º¸¼Ì³ª¿ä? ÀÛÀº ³ª¹« Á¶°¢µéÀ» °ã°ãÀÌ ºÙ¿©¼­ ¸¸µç ÇÕÆÇ ÀÔ´Ï´Ù. ¿©±â ³ª¿À´Â Veneer¶ó´Â °³³äÀÌ Èí»ç º£´Ï¾î ÇÕÆÇÀ» ¸¸µå´Â°Í°ú À¯»çÇÑ°Í °°½À´Ï´Ù. »ç½Ç Veneer¶ó´Â °ÍÀº ARMÀÇ Æ¯¼ºÀº ¾Æ´Ï°í ÄÄÆÄÀÏ·¯¿¡¼­ Áö¿øÇÏ´Â ±â´É ÀÔ´Ï´Ù.¿ø·¡ B, BL µîÀÇ ºÐ±â ¸í·É¾î´Â -32MB ~ 32MB ¹üÀ§³»¿¡¼­ ºÐ±â°¡ °¡´ÉÇÏ´Ù°í ÇÏ¿´½À´Ï´Ù. ÇÏÁö¸¸ ¾Æ·¡ ±×¸²°ú °°ÀÌ MyFunc2À» È£ÃâÇÒ¶§ ÄÄÆÄÀÏ·¯¿¡¼­ ÀÚµ¿À¸·Î Veneer¶ó´Â Áß°£ ºÐ±âÁ¡À» ¸¸µé¾î¼­ 32MB ¹üÀ§¸¦ ¹þ¾î³ªµµ ¼­ºê ÇÔ¼ö¸¦ È£Ãâ °¡´ÉÇϵµ·Ï ¸¸µé¾î ÁÝ´Ï´Ù.



À§ÀÇ ±â´É ÀÌ¿Ü¿¡µµ Ãß°¡·Î ¾Æ·¡¿Í °°Àº ±â´ÉÀÌ ÀÖ½À´Ï´Ù.

- ARM to ARM or Thumb to Thumb À¸·Î ºÐ±â : Long branch capability
- ARM to Thumb or Thumb to ARM À¸·Î ºÐ±â : Long branch capability and interworking capability

7.8 Status Register Access Instructions

(1) Syntax
MRS{cond} Rd, CPSR ; CPSRÀÇ °ªÀ» Rd ·¹Áö½ºÅÍ·Î ÀÐ¾î ¿É´Ï´Ù.
MRS{cond} Rd, SPSR ; SPSRÀÇ °ªÀ» Rd ·¹Áö½ºÅÍ·Î ÀÐ¾î ¿É´Ï´Ù.

MSR{cond} CPSR_<fields>, #<immediate>
MSR{cond} CPSR_<fields>, <Rm> ; Rm ·¹Áö½ºÅÍÀÇ °ªÀ» CPSR¿¡ ÀúÀå ÇÕ´Ï´Ù.
MSR{cond} SPSR_<fields>, #<immediate>
MSR{cond} SPSR_<fields>, <Rm> ; Rm ·¹Áö½ºÅÍÀÇ °ªÀ» SPSR¿¡ ÀúÀå ÇÕ´Ï´Ù.

ÀÌÀü¿¡µµ ¼³¸í ÇßÁö¸¸ CPSR ·¹Áö½ºÅÍÀÇ ±¸Á¶¸¦ ´Ù½ÃÇѹø È®ÀÎ ¹Ù¶ø´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º

(2) Examples

- IRQ ¸¦ Enable ÇÏ´Â ÄÚµå ÀÔ´Ï´Ù.

¾Æ·¡ ¸í·É¾î µéÀÌ ¼öÇàµÇ´Â µ¿¾ÈÀÇ CPSR·¹Áö½ºÅÍÀÇ º¯È­°ªÀ» È®ÀÎÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.

MRS R0, CPSR
BIC R0, R0, #0x80 ; 7¹ø ºñÆ®¸¦ clear Çϸé ÀÎÅÍ·´Æ®°¡ È°¼ºÈ­ µË´Ï´Ù.
MSR CPSR, R0

¼ÒÇÁÆ®¿þ¾î ±¸¼º¼ÒÇÁÆ®¿þ¾î ±¸¼º

BIC, MSR ¸í·É¿¡ ÀÇÇؼ­ CPSRÀÇ I °¡ "0" À¸·Î º¯°æ(Unmask) µÇ¾î Interrupt°¡ °¡´ÉÇÏ°Ô µÇ¾ú½À´Ï´Ù. Âü°í·Î CPSR_fc ¿Í CPSRÀº °°Àº ·¹Áö½ºÅÍ ÀÔ´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º

- IRQ ¸¦ Disable ÇÏ´Â ÄÚµå ÀÔ´Ï´Ù.
MRS R0, CPSR
ORR R0, R0, #0x80 ; 7¹ø ºñÆ®¸¦ set Çϸé ÀÎÅÍ·´Æ®¸¦ »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.
MSR CPSR, R0

°£È¤ MSR_c, MRS_x µîÀ¸·Î »ç¿ëµÇ´Â ¿¹Á¦µéÀÌ Àִµ¥ ¹ØÁÙ ´ÙÀ½¿¡ ¿À´Â flagÀÇ Àǹ̴ ¾Æ·¡¿Í °°½À´Ï´Ù. ±×¸®°í ¹ØÁÙ ´ÙÀ½ÀÇ _c, _x µîÀº Àǹ̸¦ ¸íÈ®ÇÏ°Ô Çϱâ À§Çؼ­ »ç¿ëÇÏ´Â °ÍÀÏ»Ó »ý·«Çصµ ¾Æ¹« ¹®Á¦°¡ µÇÁö´Â ¾Ê½À´Ï´Ù.
c = PSR[7:0]
x = PSR[15:8]
s = PSR[23:16]
F = PSR[31:24]

7.9 Software Interrupt Instruction


(1) Syntax
SWI{cond} <immed_24>

SEI ¸í·É¾î´Â S/W ÀûÀ¸·Î °­Á¦ÀûÀ¸·Î ARM¿¡ IRQ ¿¹¿Ü¸¦ ¹ß»ý ½Ãŵ´Ï´Ù. ÁÖ·Î OS¿¡¼­ User applicationµéÀÌ ¿î¿µÃ¼Á¦ ¼­ºñ½º ·çƾÀ» È£ÃâÇÒ °æ¿ì¿¡ Ư±Ç¸ðµå¿¡¼­ ÄÝÇϱâ À§Çؼ­ ¸¹ÀÌ »ç¿ëµË´Ï´Ù.

(2) Examples
SWI #0x123456

7.10 SWP Instruction

(1) Syntax
SWP{cond}{B} Rd, Rm, [Rn]

(2) Operation
Temp <-- [Rn]
[Rn] <-- Rm
Rd <-- Temp

(3) Semaphore Instruction
¸í·É¾î ¼öÇàÁß¿¡ ÀÎÅÍ·´Æ®¾øÀÌ ¸Þ¸ð¸®ÀÇ Read, Write ¸¦ ÇÒ ¼ö ÀÖ´Â Atomic µ¿ÀÛÀ» ÇÒ¼ö ÀÖ½À´Ï´Ù. AtmoicÀ̶ó´Â ¿ë¾î°¡ ³ª¿À´Âµ¥¿ä, ÀÌ°ÍÀº ¾î¶² µ¿ÀÛÀ» 1°³ÀÇ ¿ÀÆÛ·¹À̼ÇÀ¸·Î ¿Ï·áÇÏ´Â °ÍÀ» ÀǹÌÇÕ´Ï´Ù. Áï Atmoic ¿ÀÆÛ·¹À̼ÇÀÌ ¼öÇàµÇ´Â µ¿¾È¿¡´Â ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇÏÁö ¾Ê´Â °ÍÀÔ´Ï´Ù.

(4) Examples

R0 = 0x01
R1 = 0x02
R2 = 0x31000000



·¹Áö½ºÅÍÀÇ °ªµéÀÌ À§¿Í °°À»¶§ ¾Æ·¡ ¿¹Á¦µéÀ» Â÷·Ê´ë·Î ¼öÇà ÇßÀ»¶§ÀÇ °¢°¢ÀÇ ·¹Áö½ºÅÍ °ªÀº ?

SWP R0, R1, [R2]

R2 °¡ °¡¸£Å°´Â ÁÖ¼Ò(0x31000000)ÀÇ °ª 0x78563412ÀÇ °ªÀÌ R0¿¡ ÀúÀåÀÌ µÇ¾ú°í,



R1ÀÇ °ª 0x02°¡ R2°¡ °¡¸£Å°´Â 0x31000000 ¸Þ¸ð¸®¿¡ ÀúÀåÀÌ µÇ¾ú½À´Ï´Ù.



¾Æ·¡ÀÇ ¿¹´Â ¹ÙÀÌÆ® ¸í·É¾î ÀÔ´Ï´Ù. SWPB ¸í·É¾î¸¦ »ç¿ëÇßÀ» °æ¿ì R0 ¿¡´Â ¾î¶² °ªÀÌ ÀúÀåÀÌ µÉ±î¿ä ?

SWPB R0, R1, [R2]





µ¿ÀÛÀº SWP¿Í µ¿ÀÏÇÏ°í ´ÜÁö ¹ÙÀÌÆ® ´ÜÀ§·Î SWP°¡ µÈ´Ù´Â °Í¸¸ ´Ù¸¨´Ï´Ù. À§ÀÇ ±×¸²µéÀ» ÂüÁ¶ ÇϽñ⠹ٶø´Ï´Ù.


7.11 Conditional Execution

ARM¸ðµå ¿¡¼­ ±²ÀåÀÌ °­·ÂÇÑ ±â´ÉÀ¸·Î ¸í·É¾îµéÀ» ƯÁ¤ Á¶°ÇÀÌ ¸¸Á·ÇßÀ» ¶§¿¡¸¸ ½ÇÇà ½Ãų ¼ö ÀÖ½À´Ï´Ù. ÀÌ·¸°Ô Á¶°ÇºÎ ½ÇÇàÀÌ °¡´ÉÇÏ¸é ¼º´É¸é¿¡¼­ ¾Æ·¡¿Í °°Àº ÀÕÁ¡ÀÌ ÀÖ½À´Ï´Ù.

- Increase code density
- Decrease the number of branches

Thumb¸ðµå¿¡¼­´Â ºÐ±â¸í·É¾î ÀÌ¿Ü¿¡´Â ÀÌ Á¶°ÇºÎ ½ÇÇà ±â´ÉÀ» »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù. ±× ÀÌÀ¯´Â ¸í·É¾îÀÇ ±æÀÌ°¡ Thumb ¸ðµå¿¡¼­´Â 16bit·Î Á¦ÇÑÀÌ µÇ¾î¼­ Á¶°ÇºÎ ½ÇÇàÀ» ÇÒ¸¸Å­ ·¹Áö½ºÅÍ °ø°£ÀÌ ÃæºÐÇÏÁö ¸øÇϱ⠶§¹®ÀÔ´Ï´Ù. ±×·¯¸é ½ÇÇà °¡´ÉÇÑ Á¶°ÇÀ̶ó´Â °ÍÀº ¾î¶²°ÍµéÀÌ ÀÖÀ»±î¿ä?
ARM ¸í·É¾î ¼³¸íÇÒ¶§ ¸ÇóÀ½¿¡ ³ª¿Ô´ø ±×¸²Àä¾Æ·¡ ±×¸²À» º¸°í ½ÇÇà Á¶°Ç¿¡ ´ëÇؼ­ ¼³¸íÇϵµ·Ï ÇÏ°Ú½À´Ï´Ù.



< Cond >
ÇØ´ç ¸í·ÉÀÇ Á¶°Ç ½ÇÇà Ç÷¡±×ÀÔ´Ï´Ù. µ¥ÀÌÅÍ ÇÁ·Î¼¼½Ì ¸í·É¾î¿¡µµ ´ç¿¬È÷ Æ÷ÇԵ˴ϴÙ.
ÇØ´ç Ç÷¡±×¸¦ ÅëÇØ ¸í·ÉÀ» ÇöÀç Ç÷¡±× ·¹Áö½ºÅÍ(CPSR)ÀÇ »óÅ¿¡ µû¶ó ½ÇÇà ¿©ºÎ¸¦ °áÁ¤Çϴµ¥ »ç¿ëµÇ´Â Ç÷¡±×ÀÔ´Ï´Ù.

ARM ¸í·É¾îÀÇ ±æÀÌ´Â 32bit¶ó°í ÇÏ¿´½À´Ï´Ù. 32bitÁß¿¡¼­ 4bit¸¦ Á¶°ÇºÎ ½ÇÇàÀ» Çϴµ¥ ÇÒ´çÇÏ°í ÀÖ½À´Ï´Ù. [31:28] bit°¡ ¹Ù·Î <Cond> ºñÆ® ÀÔ´Ï´Ù.
±×¸®°í <Cond> Çʵ忡 ¿Ã¼ö ÀÖ´Â °ÍµéÀº ¾Æ·¡ Ç¥¿Í °°½À´Ï´Ù.

Cond Mnemonic Meaning Condition flag state
0000 EQ Equal Z = 1
0001 NE Not Equal Z = 0
0010 CS/HS Carry set / unsigned >= C = 1
0011 CC/LO Carry clear / unsigned < C = 0
0100 MI Minus/Negative N = 1
0101 PL Plus/Positive or Zero N = 0
0110 VS Overflow O = 1
0111 VC No overflow O = 0
1000 HI Unsigned higher C = 1 & Z = 0
1001 LS Unsigned lower or same C = 0 | Z = 1
1010 GE Signed >= N == V
1011 LT Signed < N != V
1100 GT Signed > Z == 0, N == V
1101 LE Signed <= Z == 1 or N! = V
1110 AL Always  
1111 (NV) Unpredictable  

Âü°í·Î ¿ì¸®°¡ Áö±Ý±îÁö »ç¿ëÇØ ¿Ô´ø MOV, ADD ¸í·É¾î µÚ¿¡ Mnemonic ¾øÀÌ »ç¿ëÀ» Çϸé "Always" °¡ Àû¿ëµÇ¾î¼­ ½ÇÇàÀÌ µÈ °ÍÀÔ´Ï´Ù.

(1) Condition Flag Change

Condition Flagº¯°æÀº Data Processing Instructions ¿¡ ÀÇÇؼ­¸¸ ¿µÇâÀ» ¹ÞÀ¸¸é ¸í·É¾î µÚ¿¡ "S" Prefix¸¦ »ç¿ëÇؾ߸¸ ÇÕ´Ï´Ù.
Condition Flag´Â CPSR·¹Áö½ºÅÍÀÇ [31:24] ºñÆ® Çʵ忡 Á¤ÀÇ µÇ¾î ÀÖ½À´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º

¼³¸íÀÌ Á¶±Ý º¹ÀâÇÑ°¡¿ä. ¿¹Á¦¸¦ ÅëÇؼ­ »ìÆì º¸µµ·Ï ÇսôÙ.

(1) Examples1
NZCV Ç÷¡±×°¡ º¯È­ÇÏ´Â ¿¹Á¦ µéÀÔ´Ï´Ù. ¿©±â¼­ N(Negative), Z(Zero result) ±îÁö´Â ¸íÈ®ÇÑ°Í °°Àºµ¥ Carry, Overflower ´Â ¾î¶»°Ô ´Ù¸¥ °ÍÀÏ ±î¿ä ?
¾Æ·¡ ¿¹Á¦µéÀ» ¼öÇàÇϸ鼭 Â÷ÀÌÁ¡À» ºñ±³ÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º ¼ÒÇÁÆ®¿þ¾î ±¸¼º

- N : ¿¬»êÀÇ °á°ú R2(0x40000000)ÀÇ ÃÖ»óÀ§ ºñÆ®°¡ "1" ÀÌ ¾Æ´Ô
- Z : ¿¬»êÀÇ °á°ú R2°¡ 0x0 ÀÌ ¾Æ´Ô
- C : 32-bit ¸¦ ³Ñ¾î ¼¹À¸¹Ç·Î Carry °¡ ¹ß»ý
- V : ARM ¿¡¼­ Overflow ¸¦ °ËÃâÇÏ´Â ¹æ½ÄÀº MSB ÀÌÀü ºñÆ®¿¡¼­ ¹ß»ýÇÑ Carry("0" °ú "1" À» ´õÇصµ Carry°¡ ¹ß»ýÇÏÁö ¾Ê¾ÒÀ¸¹Ç·Î "0")¿Í MSB¿¡¼­ ¹ß»ýÇÑ Carry("1" °ú "1" À» ´õÇؼ­ Carry °¡ ¹ß»ý ÇßÀ¸¹Ç·Î "1")ÀÇ °ªÀÌ ´Þ¶óÁö´Â °æ¿ì¿¡ Overflow°¡ °ËÃ⠵˴ϴÙ.

¼ÒÇÁÆ®¿þ¾î ±¸¼º ¼ÒÇÁÆ®¿þ¾î ±¸¼º

- N : ¿¬»êÀÇ °á°ú R2(0x00000000)ÀÇ ÃÖ»óÀ§ ºñÆ®°¡ "0" À̹ǷΠNegative ¹ß»ýÇÏÁö ¾ÊÀ½
- Z : ¿¬»êÀÇ °á°ú R2°¡ 0x0 À̹ǷΠ¼¼ÆÃ
- C : 32-bit ¸¦ ³Ñ¾î ¼¹À¸¹Ç·Î Carry °¡ ¹ß»ý
- V : MSB ÀÌÀü ºñÆ®¿¡¼­ ¹ß»ýÇÑ Carry("0" °ú "0" À» ´õÇصµ Carry°¡ ¹ß»ýÇÏÁö ¾Ê¾ÒÀ¸¹Ç·Î "0")¿Í MSB¿¡¼­ ¹ß»ýÇÑ Carry("1" °ú "1" À» ´õÇؼ­ Carry °¡ ¹ß»ý ÇßÀ¸¹Ç·Î "1")ÀÇ °ªÀÌ ´Þ¶óÁö´Â °æ¿ì¿¡ Overflow°¡ °ËÃ⠵˴ϴÙ.

¼ÒÇÁÆ®¿þ¾î ±¸¼º ¼ÒÇÁÆ®¿þ¾î ±¸¼º

- N : ¿¬»êÀÇ °á°ú R2(0x80000000)ÀÇ ÃÖ»óÀ§ ºñÆ®°¡ "1" À̹ǷΠNegative ¹ß»ý
- Z : ¿¬»êÀÇ °á°ú R2°¡ 0x0 ÀÌ ¾Æ´Ô
- C : 32-bit ¸¦ ³Ñ¾î ¼¹À¸¹Ç·Î Carry °¡ ¹ß»ý
- V : MSB ÀÌÀü ºñÆ®¿¡¼­ ¹ß»ýÇÑ Carry("1" °ú "1" À» ´õÇؼ­ Carry°¡ ¹ß»ýÇßÀ¸¹Ç·Î "1")¿Í MSB¿¡¼­ ¹ß»ýÇÑ Carry("1" °ú "1" À» ´õÇؼ­ Carry °¡ ¹ß»ý ÇßÀ¸¹Ç·Î "1")ÀÇ °ªÀÌ ´Ù¸£Áö ¾ÊÀ¸¹Ç·ÎOverflow°¡ °ËÃâ µÇÁö ¾Ê½À´Ï´Ù.


(2) Examples2

ADD R0, R1, R2 --> does not update the flags( "S" Prefix °¡ ¾øÀ½ )
ADDS R0, R1, R2 --> update the flags ( "S" Prefix °¡ ÀÖÀ½ )

¼ÒÇÁÆ®¿þ¾î ±¸¼º

SUBS R2, R1, R0 -- SUBS ¸í·É ½ÇÇà ÀÌÈÄ¿¡ CPSRÀÇ condition flag°¡ ¾÷µ¥ÀÌÆ® µË´Ï´Ù.
ADDEQ R3, R1, R0 -- condition field ¿¡ Z flag °¡ Set µÇ¾î ÀÖÀ¸¸é ½ÇÇàÀÌ µÇ°í ±×·¸Áö ¾ÊÀ¸¸é NOP(´Ü¼øÈ÷ CPUÀÇ 1ClockÀ» ¼Òºñ)¸í·ÉÀÌ ½ÇÇà µË´Ï´Ù.
condition field ¿¡ Z flag °¡ Set µÇ¾ú´Ù´Â Àǹ̴ R1, R0 ÀÇ °ªÀÌ °°¾Æ¼­ R3¿¡ "0" ÀÌ ÀúÀåÀÌ µÇ¾ú´Ù´Â ÀÇ¹Ì ÀÔ´Ï´Ù.

Âü°í·Î CMP, TST, CMN, TEQ instructions µîÀÇ ºñ±³, °Ë»ç ¸í·É¾î µéÀº "S" Prefix °¡ ¾øÀ̵µ CPSRÀÇ condition flag °¡ ¾÷µ¥ÀÌÆ® ÀÔ´Ï´Ù.

´ÙÀ½ ±¸¹®À» Conditional ExecutionÀ» »ç¿ëÇßÀ» °æ¿ì¿Í ¾ÈÇßÀ» °æ¿ì·Î ±¸ºÐÇؼ­ ºñ±³ÇØ º¸¼¼¿ä.

if(a==0) a = a + 1;
else a = a – 1;

Non Conditional Execution Conditional Execution
      cmp r0, #0
      bne AAA
      add r0, r0, #1
      b BBB
AAA
      sub r0, r0, #1
BBB
cmp r0, #0
addeq r0, r0, #1
subne r0, r0, #1

5 instructions
1 branch execution
3 instructions
0 branch execution

Á¶°ÇºÎ ¸í·ÉÀ» »ç¿ëÇÔÀ¸·Î¼­ instructions À» 2°³³ª ÁÙ¿´°í °¡Àå Áß¿äÇÑ °ÍÀº branch ¸í·É¾øÀÌ ±¸ÇöÀ» Çß´Ù´Â °ÍÀÔ´Ï´Ù.
branch ¸í·ÉÀº ARM pipelineÀ» ¹«³Ê¶ß¸®±â ¶§¹®¿¡ ¼º´É¿¡¼­ ±²ÀåÈ÷ Ä¡¸íÀûÀÔ´Ï´Ù.

8. Thumb Instruction Sets
Thumb ¸í·É¾î´Â ARM ¸í·É¾î¿¡ ºñÇؼ­ 16bit¶ó´Â ¸í·É¾îÀÇ ±æÀÌ ¶§¹®¿¡ ¸¹Àº Á¦¾àÀÌ ÀÖ½À´Ï´Ù. °¡Àå ´ÜÁ¡Àº Á¶°ÇºÎ ½ÇÇà ¸í·ÉÀ» »ç¿ëÇÒ ¼ö°¡ ¾ø´Ù´Â °ÍÀÔ´Ï´Ù.
Thumb ¸í·É¾î´Â ARMÀ» ÀÌÇØÇÏ´Â À־ Å« ºÎºÐÀ» Â÷ÁöÇÏÁö´Â ¾Ê´Ù°í »ý°¢ µÇ±â ¶§¹®¿¡ °£´ÜÇÏ°Ô Æ¯¼º Á¤µµ¸¸ È®ÀÎÇÏ°í ³Ñ¾î °¡µµ·Ï ÇÏ°Ú½À´Ï´Ù.

8.1 Thumb Instruction Ư¡
(1) 16-bit length instruction set
(2) ARM ¸í·É¾îº¸´Ù ÄÚµåÀÇ ÁýÀûµµ°¡ ³ô½À´Ï´Ù.( about 65% of ARM instruction )
(3) ÀϹÝÀûÀ¸·Î´Â 32bit ARM¸í·É¾î º¸´Ù´Â ¼Óµµ°¡ ´À¸®Áö¸¸ 16bit memory ½Ã½ºÅÛ¿¡¼­´Â ±×·¸Áö ¾ÊÀ» ¼öµµ ÀÖ½À´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º

8.2 Thumb Instruction Á¦¾à »çÇ×

- Limited Access to Registers : R0-R7 registers are accessible.
- Narrow Range of Immediate Value
- Not Flexible for Exception Mode
- Exception Handler should be executed in ARM mode. : ExceptionÀÌ ¹ß»ýÇϸé Ç×»ó ARM ¸ðµå·Î ÀüȯÀÌ µË´Ï´Ù.
- Limited conditional instruction.
- Branch instructions can be executed conditionally.
- Inline Barrel Shifter is not used.

8.3 Thumb, ARM Instruction ºñ±³

¾Æ·¡ Äڵ带 ARM ¸í·É¾î¿Í Thumb ¸í·É¾î·Î ÀÛ¼ºÇÏ°í ºñ±³ÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù.

if(x>=0) return x;
else return –x;

ARM Instruction Thumb Instruction
abs_rtn
      CMP r0, #0
      RSBLT r0, r0, #0
      MOV pc, lr
abs_rtn
      CMP r0, #0       
      BGE return
      NEG r0 r0
return
      MOV pc, lr
- Instructions : 3
- Size : 12Bytes
- 16-bit bus : 6access
- 32-bit bus : 3access
- Instructions : 4
- Size : 8Bytes
- 16-bit bus : 4access
- 32-bit bus : 4access

À§ÀÇ Ç¥¿¡¼­ 16-bit bus ÀÏ°æ¿ìÀÇ access Ƚ¼ö¸¦ º¸¸é ¿ÀÈ÷·Á Thumb ¸í·É¾î°¡ È¿À²À» º¸À̱⵵ ÇÕ´Ï´Ù.

8.4 ARM/Thumb Interworking

ARM ¸ðµå¿Í Thumb ¸ðµå¸¦ °°ÀÌ »ç¿ë ÇÒ ¼ö°¡ ÀÖ½À´Ï´Ù. ÇÏÁö¸¸ µ¿½Ã¿¡ ¸í·É¾î µéÀ» ¼¯¾î¼­ »ç¿ëÇÒ ¼ö Àִ°ÍÀº ¾Æ´Ï°í ARM ¸ðµå¿¡¼­ BX branch¸í·É¾î¿¡ ÀÇÇؼ­ Thumb ¸ðµå·Î ÀüȯÀ» ÇÒ¼ö°¡ ÀÖ°í ´Ù½Ã Thumb ¸ðµå¿¡¼­ BX ¸í·É¾î¸¦ ÀÌ¿ëÇؼ­ ARM ¸ðµå·Î º¹±Í ÇÒ ¼ö ÀÖ½À´Ï´Ù.

(1) BX Instruction
BX{cond} Rm
CPSR.T <-- Rm[0], PC <-- Rm & 0xFFFFFFFE

BX¸í·É¾î´Â ÀÏ¹Ý ºÐ±â¸í·É¾î¿Í ºñ½ÁÇÑ°Í °°Áö¸¸ Á¶±Ý ´Ù¸¨´Ï´Ù. ÀÌÀ¯´Â 32bit ARM ¸ðµå¿¡¼­ Thumb ¸ðµå·Î ÀüȯÀ» ÇÒ¶§ 32bit ¸í·É¾î ¿¡¼­ 16bit ·Î º¯°æµÇ¸é¼­ PCÀÇ ÁÖ¼Ò Áõ°¡ÇÏ´Â °ªÀÌ 4byte¿¡¼­ 2byte·Î ¹Ù²î±â ¶§¹®¿¡ ±×·± °ÍÀÔ´Ï´Ù. ´ç¿¬È÷ Thumb ¸ðµå¿¡¼­ ARM ¸ðµå·Î ´Ù½Ã º¹±Í ÇÒ¶§´Â ¹Ý´ëÀÇ °æ¿ì ÀÌ°ÚÁÒ? Á¶±Ý ¾î·ÆÁÒ ? ¿¹¸¦ µé¾î¼­ ¼³¸í Çϵµ·Ï ÇÏ°Ú½À´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º


À§ÀÇ ±×¸²¿¡¼­ ºÓÀº ¹Ú½º¸¦ Àß º¸½Ã¸é armcode ºÎºÐÀº 32ºñÆ® ÄÚµå »çÀÌÁîÀÌ°í, thumbcode ºÎºÐÀº 16ºñÆ® ±æÀÌÀÇ ÄÚµå »çÀÌÁîÀÓÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù.
0x5C addressÀÇ ÄÚµå BX, R0 Äڵ尡 ¼öÇàÀÌ µÇ¾úÀ»¶§ ·¹Áö½ºÅÍÀÇ »óŸ¦ º¸¸é ¾Æ·¡¿Í °°½À´Ï´Ù.

thumbcode °¡ ½ÃÀ۵Ǵ ÁÖ¼Ò´Â 0x6C Àε¥, armcodeÀÇ "BX, R0(0x6d)" Äڵ忡 ÀÇÇؼ­ 0x6C°¡ ¾Æ´Ñ 0x6D ·Î ºÐ±â Ç϶ó°í µÇ¾î ÀÖ½À´Ï´Ù. ¿Ã¹Ù¸£°Ô ¼öÇàÀÌ µÉ±î¿ä ? ¹°·Ð Àß ¼öÇàÀÌ µË´Ï´Ù. ÀÌ°ÍÀÇ ºñ¹ÐÀº À§¿¡¼­ ¼³¸íÇÑ "CPSR.T <-- Rm[0], PC <-- Rm & 0xFFFFFFFE" ¿¡ ÀÖ½À´Ï´Ù.
¿ì¼± CPSR.T = 1 ·Î º¯°æÀÌ µÇ´Â °ÍÀº Rm(1101101) ÀÇ ÃÖÇÏÀ§ ºñÆ®°¡ "1" À̱⠶§¹®ÀÔ´Ï´Ù. ¶ÇÇÑ Rm(1101101) & 0xFFFFFFFE ¿¡ ÀÇÇؼ­ ½ÇÁ¦ BXºÐ±â ¸í·É¾î¿¡ ÀÇÇؼ­ ºÐ±âµÇ´Â ÁÖ¼Ò´Â 0x6C °¡ µË´Ï´Ù. BX ¸í·É¾î¿¡¼­ Rm(1101101) & 0xFFFFFFFE Çؼ­ ºÐ±â¸¦ ÇÏ´Â ÀÌÀ¯´Â ARM ¸ðµå(32ºñÆ®)ÀÌ°Ç Thumbmode(16ºñÆ®) ÀÌ°Ç PCÀÇ ÁÖ¼Ò¸¦ Ç×»ó 2ÀÇ ¹è¼ö¸¦ À¯Áö Çϱâ À§Çؼ­ ÀÔ´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º


9. AAPCS
9.1 Procedure Call Standard for the ARM Architecture

½±°Ô À̾߱â Çϸé ARM¿¡¼­ ¼­ºê ·çƾÀ» È£ÃâÇÒ¶§ÀÇ ·¹Áö½ºÅÍ, ½ºÅà »ç¿ë ¹æ¹ý¿¡ ´ëÇÑ °ÍÀÔ´Ï´Ù. ¾Æ·¡ Ç¥´Â Procedure call½Ã »ç¿ëµÇ´Â ·¹Áö½ºÅ͵éÀ» Ç¥·Î Á¤¸®ÇÑ °ÍÀÔ´Ï´Ù.

Register Synonym Special Role in ther procedure call standard
r15   PC Program Count
r14   LR Link Register
r13   SP Stack Pointer
r12   IP The Intra-procedure-call scratch register
r11 v8   Variable register8
r10 v7   Variable register7
r9 v6   Variable register6
Platform register
Ther meaning of the register is defined by the platform standad
r8 v5   Variable register5
r7 v4   Variable register4
r6 v3   Variable register3
r5 v2   Variable register2
r4 v1   Variable register1
r3 a4   Argument / scratch register4
r2 a3   Argument / scratch register3
r1 a2   Argument / scratch register2
r0 a1   Argument / result / scratch register1

* Âü°í·Î scratch registerµéÀº ¼­ºê·çƾ È£Ãâ½Ã º¯°æÀÌ ÀÖÀ» ¼ö ÀÖ´Â À§ÇèÀÌ ÀÖ´Â ·¹Áö½ºÅÍ ÀÔ´Ï´Ù. ±×·¯¹Ç·Î ¼­ºê·çƾ È£Ãâ½Ã Stack¿¡ ¹é¾÷ÇÑ ÀÌÈÄ ¼­ºê·çƾÀ» È£Ãâ ÇØ¾ß ÇÕ´Ï´Ù.

À§ÀÇ Ç¥¿¡¼­ ¾Ë¼ö ÀÖ´Â °ÍÀº ÇÔ¼ö¸¦ È£ÃâÇÒ¶§ ÇÔ¼öÀÇ ÀÎÀÚ 4°³ ±îÁö´Â r0 ~ r3¿¡ ÀúÀåÀÌ µÇ¾î È£ÃâÀÌ µÇ°í ÇÔ¼ö ¿¡¼­ return¿¡ ÀÇÇÑ °á°ú °ªÀº r0¿¡ ´ã¾Æ¼­ ÇÔ¼ö¸¦ È£ÃâÇÑ ¸ÞÀÎ ÇÔ¼ö·Î °ªÀ» Àü´ÞÇÏ°í ÀÖÀ½À» ¾Ë¼ö ÀÖ½À´Ï´Ù. ±×·³ ÇÔ¼öÀÇ ÀÎÀÚ°¡ 4°³ ÀÌ»óÀÎ °æ¿ì¿¡´Â ¾î¶»°Ô µÇ´Â °ÍÀϱî¿ä? 5¹ø° ÀÎÀÚ ºÎÅÍ´Â Stack¿¡ ÀúÀåÇÑÈÄ ÇÔ¼ö ¿¡¼­ POPÇؼ­ »ç¿ëÇÕ´Ï´Ù. StackÀº ¸ÞÀÎ ¸Þ¸ð¸®¸¦ »ç¿ëÇϹǷΠ°¡´ÉÇϸé ÇÔ¼ö ÀÎÀÚ´Â 4°³ ±îÁö¸¸ »ç¿ëÇÏ´Â °ÍÀÌ ¼º´É Çâ»ó¿¡ µµ¿òÀÌ µË´Ï´Ù.


9.2 Function Parameter Passing


void main(void)
{
      int sum;

      // R0 ·¹Áö½ºÅÍ¿¡ a+b+c+d+e ÀÇ ÇÕÀÌ ÀúÀåµÇ¾î returnÀÌ µË´Ï´Ù.
      sum = func1(0, 1, 2, 3, 99);
}

int a --> R0
int b --> R1
int c --> R2
int d --> R3
int e --> Stack
Return Value --> R0

int func1(int a, int b, int c, int d, int e)
{
      return a+b+c+d+e;
}

À§ÀÇ C Äڵ带 Disassembly Çغ¸¸é ´ÙÀ½°ú °°½À´Ï´Ù. ¿À¸¥ÂÊ ¼³¸íÀ» ÂüÁ¶ ÇϽñ⠹ٶø´Ï´Ù.

¼ÒÇÁÆ®¿þ¾î ±¸¼º