Uvision
Uvision
Uvision
06 for µVision®
Version 5
Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights reserved.
ARM DUI0379G
ARM® Compiler v5.06 for µVision®
Document History
Your access to the information in this document is conditional upon your acceptance that you will not use or permit others to use
the information for the purposes of determining whether implementations infringe any third party patents.
THIS DOCUMENT IS PROVIDED “AS IS”. ARM PROVIDES NO REPRESENTATIONS AND NO WARRANTIES,
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, SATISFACTORY QUALITY, NON-INFRINGEMENT OR FITNESS FOR A PARTICULAR PURPOSE
WITH RESPECT TO THE DOCUMENT. For the avoidance of doubt, ARM makes no representation with respect to, and has
undertaken no analysis to identify or understand the scope and content of, third party patents, copyrights, trade secrets, or other
rights.
TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL ARM BE LIABLE FOR ANY DAMAGES,
INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR
CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
OUT OF ANY USE OF THIS DOCUMENT, EVEN IF ARM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
This document consists solely of commercial items. You shall be responsible for ensuring that any use, duplication or disclosure of
this document complies fully with any relevant export laws and regulations to assure that this document or any portion thereof is
not exported, directly or indirectly, in violation of such export laws. Use of the word “partner” in reference to ARM’s customers is
not intended to create or refer to any partnership relationship with any other company. ARM may make changes to this document at
any time and without notice.
If any of the provisions contained in these terms conflict with any of the provisions of any signed written agreement covering this
document with ARM, then the signed written agreement prevails over and supersedes the conflicting provisions of these terms.
This document may be translated into other languages for convenience, and you agree that if there is any conflict between the
English version of this document and any translation, the terms of the English version of the Agreement shall prevail.
Words and logos marked with ® or ™ are registered trademarks or trademarks of ARM Limited or its affiliates in the EU and/or
elsewhere. All rights reserved. Other brands and names mentioned in this document may be the trademarks of their respective
owners. Please follow ARM’s trademark usage guidelines at http://www.arm.com/about/trademark-usage-guidelines.php
Copyright © [2007, 2008, 2011, 2012, 2014, 2015], ARM Limited or its affiliates. All rights reserved.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2
reserved.
Non-Confidential
ARM® Compiler v5.06 for µVision®
LES-PRE-20349
Confidentiality Status
This document is Non-Confidential. The right to use, copy and disclose this document may be subject to license restrictions in
accordance with the terms of the agreement entered into by ARM and the party that ARM delivered this document to.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 3
reserved.
Non-Confidential
Contents
ARM® Compiler v5.06 for µVision® armasm User
Guide
Preface
About this book ..................................................... ..................................................... 20
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4
reserved.
Non-Confidential
2.13 Program Counter .................................................. .................................................. 2-43
2.14 Application Program Status Register ................................... ................................... 2-44
2.15 The Q flag ................................................................................................................ 2-45
2.16 Current Program Status Register ............................................................................ 2-46
2.17 Saved Program Status Registers ............................................................................ 2-47
2.18 ARM and Thumb instruction set overview ............................... ............................... 2-48
2.19 Access to the inline barrel shifter ...................................... ...................................... 2-49
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5
reserved.
Non-Confidential
5.7 Benefits of using conditional execution ................................ ................................ 5-103
5.8 Example showing the benefits of using conditional instructions ............................ 5-104
5.9 Optimization for execution speed .......................................................................... 5-107
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6
reserved.
Non-Confidential
7.27 Operator precedence .............................................. .............................................. 7-158
7.28 Difference between operator precedence in assembly language and C ....... ....... 7-159
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7
reserved.
Non-Confidential
9.19 --diag_remark=tag[,tag,…] .......................................... .......................................... 9-215
9.20 --diag_style={arm|ide|gnu} .......................................... .......................................... 9-216
9.21 --diag_suppress=tag[,tag,…] ........................................ ........................................ 9-217
9.22 --diag_warning=tag[,tag,…] ......................................... ......................................... 9-218
9.23 --dllexport_all .................................................... .................................................... 9-219
9.24 --dwarf2 ........................................................ ........................................................ 9-220
9.25 --dwarf3 ........................................................ ........................................................ 9-221
9.26 --errors=errorfile .................................................. .................................................. 9-222
9.27 --execstack, --no_execstack .................................................................................. 9-223
9.28 --execute_only ................................................... ................................................... 9-224
9.29 --exceptions, --no_exceptions ....................................... ....................................... 9-225
9.30 --exceptions_unwind, --no_exceptions_unwind .......................... .......................... 9-226
9.31 --fpmode=model .................................................. .................................................. 9-227
9.32 --fpu=list ........................................................ ........................................................ 9-228
9.33 --fpu=name ............................................................................................................ 9-229
9.34 -g ............................................................. ............................................................. 9-231
9.35 --help .......................................................... .......................................................... 9-232
9.36 -idir[,dir, …] ............................................................................................................ 9-233
9.37 --keep .......................................................... .......................................................... 9-234
9.38 --length=n .............................................................................................................. 9-235
9.39 --li ............................................................. ............................................................. 9-236
9.40 --library_type=lib .................................................................................................... 9-237
9.41 --liclinger=seconds ................................................ ................................................ 9-238
9.42 --licretry .................................................................................................................. 9-239
9.43 --list=file ........................................................ ........................................................ 9-240
9.44 --list= ...................................................................................................................... 9-241
9.45 --littleend ................................................................................................................ 9-242
9.46 -m ............................................................. ............................................................. 9-243
9.47 --maxcache=n ........................................................................................................ 9-244
9.48 --md ........................................................... ........................................................... 9-245
9.49 --no_code_gen ................................................... ................................................... 9-246
9.50 --no_esc ........................................................ ........................................................ 9-247
9.51 --no_hide_all .......................................................................................................... 9-248
9.52 --no_regs ....................................................... ....................................................... 9-249
9.53 --no_terse .............................................................................................................. 9-250
9.54 --no_warn ....................................................... ....................................................... 9-251
9.55 -o filename ...................................................... ...................................................... 9-252
9.56 --pd ........................................................................................................................ 9-253
9.57 --predefine "directive" ............................................................................................ 9-254
9.58 --reduce_paths, --no_reduce_paths ...................................................................... 9-255
9.59 --regnames ............................................................................................................ 9-256
9.60 --report-if-not-wysiwyg ............................................. ............................................. 9-257
9.61 --show_cmdline .................................................. .................................................. 9-258
9.62 --split_ldm .............................................................................................................. 9-259
9.63 --thumb .................................................................................................................. 9-260
9.64 --thumbx ........................................................ ........................................................ 9-261
9.65 --unaligned_access, --no_unaligned_access ........................................................ 9-262
9.66 --unsafe ........................................................ ........................................................ 9-263
9.67 --untyped_local_labels ............................................. ............................................. 9-264
9.68 --version_number ................................................. ................................................. 9-265
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8
reserved.
Non-Confidential
9.69 --via=filename ........................................................................................................ 9-266
9.70 --vsn ........................................................... ........................................................... 9-267
9.71 --width=n ................................................................................................................ 9-268
9.72 --xref ...................................................................................................................... 9-269
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9
reserved.
Non-Confidential
10.45 LDR (register-relative) ............................................ ............................................ 10-353
10.46 LDR pseudo-instruction ........................................... ........................................... 10-356
10.47 LDR, unprivileged ................................................................................................ 10-358
10.48 LDREX ........................................................ ........................................................ 10-360
10.49 LSL ...................................................................................................................... 10-362
10.50 LSR ...................................................................................................................... 10-364
10.51 MCR and MCR2 .................................................................................................. 10-366
10.52 MCRR and MCRR2 .............................................. .............................................. 10-367
10.53 MLA .......................................................... .......................................................... 10-368
10.54 MLS .......................................................... .......................................................... 10-369
10.55 MOV .......................................................... .......................................................... 10-370
10.56 MOV32 pseudo-instruction .................................................................................. 10-372
10.57 MOVT .................................................................................................................. 10-373
10.58 MRC and MRC2 .................................................................................................. 10-374
10.59 MRRC and MRRC2 .............................................. .............................................. 10-375
10.60 MRS (PSR to general-purpose register) .............................................................. 10-376
10.61 MRS (system coprocessor register to ARM register) .......................................... 10-378
10.62 MSR (ARM register to system coprocessor register) .......................................... 10-379
10.63 MSR (general-purpose register to PSR) .............................................................. 10-380
10.64 MUL .......................................................... .......................................................... 10-382
10.65 MVN .......................................................... .......................................................... 10-384
10.66 NEG pseudo-instruction ........................................... ........................................... 10-386
10.67 NOP .......................................................... .......................................................... 10-387
10.68 ORN (Thumb only) ............................................... ............................................... 10-388
10.69 ORR .......................................................... .......................................................... 10-389
10.70 PKHBT and PKHTB .............................................. .............................................. 10-391
10.71 PLD and PLI ........................................................................................................ 10-393
10.72 POP .......................................................... .......................................................... 10-395
10.73 PUSH ......................................................... ......................................................... 10-397
10.74 QADD .................................................................................................................. 10-398
10.75 QADD8 ................................................................................................................ 10-399
10.76 QADD16 .............................................................................................................. 10-400
10.77 QASX ......................................................... ......................................................... 10-401
10.78 QDADD ................................................................................................................ 10-402
10.79 QDSUB ................................................................................................................ 10-403
10.80 QSAX ......................................................... ......................................................... 10-404
10.81 QSUB ......................................................... ......................................................... 10-405
10.82 QSUB8 ........................................................ ........................................................ 10-406
10.83 QSUB16 ....................................................... ....................................................... 10-407
10.84 RBIT .......................................................... .......................................................... 10-408
10.85 REV .......................................................... .......................................................... 10-409
10.86 REV16 ........................................................ ........................................................ 10-410
10.87 REVSH ........................................................ ........................................................ 10-411
10.88 RFE .......................................................... .......................................................... 10-412
10.89 ROR .......................................................... .......................................................... 10-414
10.90 RRX .......................................................... .......................................................... 10-416
10.91 RSB .......................................................... .......................................................... 10-418
10.92 RSC .......................................................... .......................................................... 10-420
10.93 SADD8 ........................................................ ........................................................ 10-422
10.94 SADD16 ....................................................... ....................................................... 10-423
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10
reserved.
Non-Confidential
10.95 SASX ......................................................... ......................................................... 10-424
10.96 SBC .......................................................... .......................................................... 10-426
10.97 SBFX ......................................................... ......................................................... 10-428
10.98 SDIV .................................................................................................................... 10-429
10.99 SEL ...................................................................................................................... 10-430
10.100 SETEND .............................................................................................................. 10-432
10.101 SEV .......................................................... .......................................................... 10-433
10.102 SHADD8 .............................................................................................................. 10-434
10.103 SHADD16 ............................................................................................................ 10-435
10.104 SHASX ........................................................ ........................................................ 10-436
10.105 SHSAX ........................................................ ........................................................ 10-437
10.106 SHSUB8 .............................................................................................................. 10-438
10.107 SHSUB16 ............................................................................................................ 10-439
10.108 SMC .......................................................... .......................................................... 10-440
10.109 SMLAxy ....................................................... ....................................................... 10-441
10.110 SMLAD ................................................................................................................ 10-443
10.111 SMLAL ........................................................ ........................................................ 10-444
10.112 SMLALD .............................................................................................................. 10-445
10.113 SMLALxy ...................................................... ...................................................... 10-446
10.114 SMLAWy .............................................................................................................. 10-447
10.115 SMLSD ................................................................................................................ 10-448
10.116 SMLSLD .............................................................................................................. 10-449
10.117 SMMLA ................................................................................................................ 10-450
10.118 SMMLS ................................................................................................................ 10-451
10.119 SMMUL ................................................................................................................ 10-452
10.120 SMUAD ................................................................................................................ 10-453
10.121 SMULxy ....................................................... ....................................................... 10-454
10.122 SMULL ........................................................ ........................................................ 10-455
10.123 SMULWy .............................................................................................................. 10-456
10.124 SMUSD ................................................................................................................ 10-457
10.125 SRS .......................................................... .......................................................... 10-458
10.126 SSAT ......................................................... ......................................................... 10-460
10.127 SSAT16 ....................................................... ....................................................... 10-461
10.128 SSAX ......................................................... ......................................................... 10-462
10.129 SSUB8 ........................................................ ........................................................ 10-463
10.130 SSUB16 ....................................................... ....................................................... 10-464
10.131 STC and STC2 .................................................................................................... 10-465
10.132 STM .......................................................... .......................................................... 10-467
10.133 STR (immediate offset) ........................................................................................ 10-469
10.134 STR (register offset) ............................................................................................ 10-472
10.135 STR, unprivileged ................................................................................................ 10-475
10.136 STREX ........................................................ ........................................................ 10-477
10.137 SUB .......................................................... .......................................................... 10-479
10.138 SUBS pc, lr .......................................................................................................... 10-481
10.139 SVC .......................................................... .......................................................... 10-483
10.140 SWP and SWPB .................................................................................................. 10-484
10.141 SXTAB ........................................................ ........................................................ 10-485
10.142 SXTAB16 ...................................................... ...................................................... 10-486
10.143 SXTAH ........................................................ ........................................................ 10-487
10.144 SXTB ......................................................... ......................................................... 10-488
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11
reserved.
Non-Confidential
10.145 SXTB16 ....................................................... ....................................................... 10-489
10.146 SXTH ......................................................... ......................................................... 10-490
10.147 SYS .......................................................... .......................................................... 10-492
10.148 TBB and TBH ................................................... ................................................... 10-493
10.149 TEQ .......................................................... .......................................................... 10-494
10.150 TST ...................................................................................................................... 10-496
10.151 UADD8 ........................................................ ........................................................ 10-497
10.152 UADD16 ....................................................... ....................................................... 10-498
10.153 UASX ......................................................... ......................................................... 10-499
10.154 UBFX ......................................................... ......................................................... 10-501
10.155 UDIV .................................................................................................................... 10-502
10.156 UHADD8 .............................................................................................................. 10-503
10.157 UHADD16 ............................................................................................................ 10-504
10.158 UHASX ................................................................................................................ 10-505
10.159 UHSAX ................................................................................................................ 10-506
10.160 UHSUB8 .............................................................................................................. 10-507
10.161 UHSUB16 ............................................................................................................ 10-508
10.162 UMAAL ................................................................................................................ 10-509
10.163 UMLAL ........................................................ ........................................................ 10-510
10.164 UMULL ........................................................ ........................................................ 10-511
10.165 UND pseudo-instruction ........................................... ........................................... 10-512
10.166 UQADD8 .............................................................................................................. 10-513
10.167 UQADD16 ............................................................................................................ 10-514
10.168 UQASX ................................................................................................................ 10-515
10.169 UQSAX ................................................................................................................ 10-516
10.170 UQSUB8 .............................................................................................................. 10-517
10.171 UQSUB16 ............................................................................................................ 10-518
10.172 USAD8 ........................................................ ........................................................ 10-519
10.173 USADA8 .............................................................................................................. 10-520
10.174 USAT ......................................................... ......................................................... 10-521
10.175 USAT16 ....................................................... ....................................................... 10-522
10.176 USAX ......................................................... ......................................................... 10-523
10.177 USUB8 ........................................................ ........................................................ 10-525
10.178 USUB16 ....................................................... ....................................................... 10-526
10.179 UXTAB ........................................................ ........................................................ 10-527
10.180 UXTAB16 ...................................................... ...................................................... 10-528
10.181 UXTAH ........................................................ ........................................................ 10-530
10.182 UXTB ......................................................... ......................................................... 10-531
10.183 UXTB16 ....................................................... ....................................................... 10-532
10.184 UXTH ......................................................... ......................................................... 10-533
10.185 WFE .......................................................... .......................................................... 10-534
10.186 WFI ...................................................................................................................... 10-535
10.187 YIELD .................................................................................................................. 10-536
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12
reserved.
Non-Confidential
11.6 VCVT (between floating-point and integer) .......................................................... 11-545
11.7 VCVT (between floating-point and fixed-point) .................................................... 11-546
11.8 VCVTB, VCVTT (half-precision extension) .......................................................... 11-547
11.9 VDIV .......................................................... .......................................................... 11-548
11.10 VFMA, VFMS, VFNMA, VFNMS (floating-point) .................................................. 11-549
11.11 VLDM (floating-point) ............................................. ............................................. 11-550
11.12 VLDR (floating-point) ............................................. ............................................. 11-551
11.13 VLDR (post-increment and pre-decrement, floating-point) .................................. 11-552
11.14 VLDR pseudo-instruction .......................................... .......................................... 11-553
11.15 VMLA (floating-point) ............................................. ............................................. 11-554
11.16 VMLS (floating-point) ............................................. ............................................. 11-555
11.17 VMOV (floating-point) .......................................................................................... 11-556
11.18 VMOV (between one ARM register and single precision VFP) ............. ............. 11-557
11.19 VMOV (between two ARM registers and one or two extension registers) ..... ..... 11-558
11.20 VMOV (between an ARM register and half a double precision VFP register) .. .. 11-559
11.21 VMRS ......................................................... ......................................................... 11-560
11.22 VMSR ......................................................... ......................................................... 11-561
11.23 VMUL (floating-point) ............................................. ............................................. 11-562
11.24 VNEG (floating-point) ............................................. ............................................. 11-563
11.25 VNMLA (floating-point) ............................................ ............................................ 11-564
11.26 VNMLS (floating-point) ............................................ ............................................ 11-565
11.27 VNMUL (floating-point) ........................................................................................ 11-566
11.28 VPOP (floating-point) ............................................. ............................................. 11-567
11.29 VPUSH (floating-point) ............................................ ............................................ 11-568
11.30 VSQRT ........................................................ ........................................................ 11-569
11.31 VSTM (floating-point) ............................................. ............................................. 11-570
11.32 VSTR (floating-point) ............................................. ............................................. 11-571
11.33 VSTR (post-increment and pre-decrement, floating-point) .................................. 11-572
11.34 VSUB (floating-point) ............................................. ............................................. 11-573
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 13
reserved.
Non-Confidential
12.20 DCI ........................................................... ........................................................... 12-598
12.21 DCQ and DCQU .................................................................................................. 12-599
12.22 DCW and DCWU ................................................ ................................................ 12-600
12.23 DN and SN ..................................................... ..................................................... 12-601
12.24 END .......................................................... .......................................................... 12-602
12.25 ENDFUNC or ENDP ............................................................................................ 12-603
12.26 ENTRY ........................................................ ........................................................ 12-604
12.27 EQU .......................................................... .......................................................... 12-605
12.28 EXPORT or GLOBAL .......................................................................................... 12-606
12.29 EXPORTAS .................................................... .................................................... 12-608
12.30 FIELD ......................................................... ......................................................... 12-609
12.31 FRAME ADDRESS .............................................................................................. 12-610
12.32 FRAME POP ........................................................................................................ 12-611
12.33 FRAME PUSH .................................................. .................................................. 12-612
12.34 FRAME REGISTER .............................................. .............................................. 12-613
12.35 FRAME RESTORE .............................................................................................. 12-614
12.36 FRAME RETURN ADDRESS .............................................................................. 12-615
12.37 FRAME SAVE ...................................................................................................... 12-616
12.38 FRAME STATE REMEMBER .............................................................................. 12-617
12.39 FRAME STATE RESTORE .................................................................................. 12-618
12.40 FRAME UNWIND ON .......................................................................................... 12-619
12.41 FRAME UNWIND OFF ........................................................................................ 12-620
12.42 FUNCTION or PROC ............................................. ............................................. 12-621
12.43 GBLA, GBLL, and GBLS .......................................... .......................................... 12-622
12.44 GET or INCLUDE ................................................................................................ 12-623
12.45 IF, ELSE, ENDIF, and ELIF .................................................................................. 12-624
12.46 IMPORT and EXTERN ........................................................................................ 12-626
12.47 INCBIN ........................................................ ........................................................ 12-628
12.48 INFO .................................................................................................................... 12-629
12.49 KEEP ......................................................... ......................................................... 12-630
12.50 LCLA, LCLL, and LCLS ........................................... ........................................... 12-631
12.51 LTORG ........................................................ ........................................................ 12-632
12.52 MACRO and MEND .............................................. .............................................. 12-633
12.53 MAP .......................................................... .......................................................... 12-636
12.54 MEXIT .................................................................................................................. 12-637
12.55 NOFP ......................................................... ......................................................... 12-638
12.56 OPT .......................................................... .......................................................... 12-639
12.57 RELOC ................................................................................................................ 12-641
12.58 REQUIRE ............................................................................................................ 12-642
12.59 REQUIRE8 and PRESERVE8 ...................................... ...................................... 12-643
12.60 RLIST ......................................................... ......................................................... 12-644
12.61 RN ........................................................... ........................................................... 12-645
12.62 ROUT ......................................................... ......................................................... 12-646
12.63 SETA, SETL, and SETS ...................................................................................... 12-647
12.64 SPACE or FILL .................................................................................................... 12-648
12.65 THUMB ................................................................................................................ 12-649
12.66 THUMBX ...................................................... ...................................................... 12-650
12.67 TTL and SUBT .................................................. .................................................. 12-651
12.68 WHILE and WEND .............................................................................................. 12-652
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 14
reserved.
Non-Confidential
Chapter 13 Via File Syntax
13.1 Overview of via files .............................................. .............................................. 13-654
13.2 Via file syntax rules .............................................................................................. 13-655
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 15
reserved.
Non-Confidential
List of Figures
ARM® Compiler v5.06 for µVision® armasm User
Guide
Figure 2-1 Organization of general-purpose registers and Program Status Registers ........................... 2-37
Figure 8-1 VFP extension register bank ............................................................................................... 8-166
Figure 8-2 VFPv2 register banks .......................................................................................................... 8-180
Figure 8-3 VFPv3 register banks .......................................................................................................... 8-180
Figure 10-1 ASR #3 .............................................................................................................................. 10-285
Figure 10-2 LSR #3 ............................................................................................................................... 10-286
Figure 10-3 LSL #3 ............................................................................................................................... 10-286
Figure 10-4 ROR #3 .............................................................................................................................. 10-286
Figure 10-5 RRX ................................................................................................................................... 10-287
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 16
reserved.
Non-Confidential
List of Tables
ARM® Compiler v5.06 for µVision® armasm User
Guide
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 17
reserved.
Non-Confidential
Table 6-5 Command-line options ......................................................................................................... 6-126
Table 6-6 armcc equivalent command-line options ............................................................................. 6-126
Table 7-1 Unary operators that return strings ...................................................................................... 7-150
Table 7-2 Unary operators that return numeric or logical values ......................................................... 7-150
Table 7-3 Multiplicative operators ........................................................................................................ 7-152
Table 7-4 String manipulation operators .............................................................................................. 7-153
Table 7-5 Shift operators ..................................................................................................................... 7-154
Table 7-6 Addition, subtraction, and logical operators ......................................................................... 7-155
Table 7-7 Relational operators ............................................................................................................ 7-156
Table 7-8 Boolean operators ............................................................................................................... 7-157
Table 7-9 Operator precedence in ARM assembly language .............................................................. 7-159
Table 7-10 Operator precedence in C ................................................................................................... 7-159
Table 8-1 VFP data type specifiers ...................................................................................................... 8-172
Table 8-2 Pre-UAL VFP mnemonics ................................................................................................... 8-187
Table 8-3 Floating-point values for use with FCONST ........................................................................ 8-188
Table 9-1 Compatible processor or architecture combinations ........................................................... 9-205
Table 9-2 Severity of diagnostic messages ......................................................................................... 9-214
Table 9-3 Specifying a command-line option and an AREA directive for GNU-stack sections ........... 9-223
Table 10-1 Summary of ARM and Thumb instructions ........................................................................ 10-274
Table 10-2 Condition code suffixes ..................................................................................................... 10-289
Table 10-3 PC-relative offsets ............................................................................................................. 10-295
Table 10-4 Register-relative offsets ..................................................................................................... 10-297
Table 10-5 B instruction availability and range .................................................................................... 10-305
Table 10-6 BL instruction availability and range .................................................................................. 10-312
Table 10-7 BLX instruction availability and range ................................................................................ 10-314
Table 10-8 BX instruction availability and range .................................................................................. 10-316
Table 10-9 BXJ instruction availability and range ................................................................................ 10-318
Table 10-10 Offsets and architectures, LDR, word, halfword, and byte ................................................ 10-344
Table 10-11 PC-relative offsets ............................................................................................................. 10-348
Table 10-12 Options and architectures, LDR (register offsets) ............................................................. 10-351
Table 10-13 Register-relative offsets ..................................................................................................... 10-353
Table 10-14 Offsets and architectures, LDR (User mode) .................................................................... 10-358
Table 10-15 Offsets and architectures, STR, word, halfword, and byte ................................................ 10-469
Table 10-16 Options and architectures, STR (register offsets) ............................................................. 10-472
Table 10-17 Offsets and architectures, STR (User mode) .................................................................... 10-475
Table 10-18 Range and encoding of expr ............................................................................................. 10-512
Table 11-1 Summary of VFP instructions ............................................................................................ 11-539
Table 12-1 List of directives ................................................................................................................. 12-576
Table 12-2 OPT directive settings ....................................................................................................... 12-639
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 18
reserved.
Non-Confidential
Preface
This preface introduces the ARM® Compiler v5.06 for µVision® armasm User Guide.
It contains the following:
• About this book on page 20.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 19
reserved.
Non-Confidential
Preface
About this book
Glossary
The ARM Glossary is a list of terms used in ARM documentation, together with definitions for those
terms. The ARM Glossary does not contain terms that are industry standard unless the ARM meaning
differs from the generally accepted meaning.
See the ARM Glossary for more information.
Typographic conventions
italic
Introduces special terminology, denotes cross-references, and citations.
bold
Highlights interface elements, such as menu names. Denotes signal names. Also used for terms
in descriptive lists, where appropriate.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 20
reserved.
Non-Confidential
Preface
About this book
monospace
Denotes text that you can enter at the keyboard, such as commands, file and program names,
and source code.
monospace
Denotes a permitted abbreviation for a command or option. You can enter the underlined text
instead of the full command or option name.
monospace italic
Denotes arguments to monospace text where the argument is to be replaced by a specific value.
monospace bold
Denotes language keywords when used outside example code.
<and>
Encloses replaceable terms for assembler syntax where they appear in code or code fragments.
For example:
MRC p15, 0, <Rd>, <CRn>, <CRm>, <Opcode_2>
SMALL CAPITALS
Used in body text for a few terms that have specific technical meanings, that are defined in the
ARM glossary. For example, IMPLEMENTATION DEFINED, IMPLEMENTATION SPECIFIC, UNKNOWN, and
UNPREDICTABLE.
Feedback
Feedback on content
If you have comments on content then send an e-mail to [email protected]. Give:
• The title ARM® Compiler v5.06 for µVision® armasm User Guide.
• The number ARM DUI0379G.
• If applicable, the page number(s) to which your comments refer.
• A concise explanation of your comments.
ARM also welcomes general suggestions for additions and improvements.
Note
ARM tests the PDF only in Adobe Acrobat and Acrobat Reader, and cannot guarantee the quality of the
represented document when used with any other PDF reader.
Other information
• ARM Information Center.
• ARM Technical Support Knowledge Articles.
• Support and Maintenance.
• ARM Glossary.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 21
reserved.
Non-Confidential
Chapter 1
Overview of the Assembler
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 1-22
reserved.
Non-Confidential
1 Overview of the Assembler
1.1 About the ARM Compiler toolchain assemblers
Note
Be aware of the following:
• Generated code might be different between two ARM Compiler releases.
• For a feature release, there might be significant code generation differences.
Note
The command-line option descriptions and related information in the individual ARM Compiler tools
documents describe all the features that ARM Compiler supports. Any features not documented are not
supported and are used at your own risk. You are responsible for making sure that any generated code
using unsupported features is operating correctly.
Related information
Using the Inline and Embedded Assemblers of the ARM Compiler.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 1-23
reserved.
Non-Confidential
1 Overview of the Assembler
1.2 Key features of the assembler
Related concepts
1.3 How the assembler works on page 1-25.
4.1 About the Unified Assembler Language on page 4-58.
4.21 Use of macros on page 4-85.
Related references
Chapter 12 Directives Reference on page 12-574.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 1-24
reserved.
Non-Confidential
1 Overview of the Assembler
1.3 How the assembler works
Related concepts
6.13 Two pass assembler diagnostics on page 6-124.
4.24 Instruction and directive relocations on page 4-89.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 1-25
reserved.
Non-Confidential
1 Overview of the Assembler
1.3 How the assembler works
Related references
1.4 Directives that can be omitted in pass 2 of the assembler on page 1-27.
9.18 --diag_error=tag[,tag,…] on page 9-214.
9.15 --debug on page 9-211.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 1-26
reserved.
Non-Confidential
1 Overview of the Assembler
1.4 Directives that can be omitted in pass 2 of the assembler
Note
Macros that appear only in pass 1 and not in pass 2 must contain only these directives.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 1-27
reserved.
Non-Confidential
1 Overview of the Assembler
1.4 Directives that can be omitted in pass 2 of the assembler
Related concepts
1.3 How the assembler works on page 1-25.
6.13 Two pass assembler diagnostics on page 6-124.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 1-28
reserved.
Non-Confidential
Chapter 2
Overview of the ARM Architecture
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-29
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.1 About the ARM architecture
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-30
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.2 ARM, Thumb, and ThumbEE instruction sets
Related references
2.18 ARM and Thumb instruction set overview on page 2-48.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-31
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.3 Changing between ARM, Thumb, and ThumbEE state
These directives do not change the instruction set state of the processor. To do this, you must use an
appropriate instruction, for example BX or BLX to change between ARM and Thumb states when
performing a branch.
Related references
10.22 BLX on page 10-314.
10.23 BX on page 10-316.
12.7 ARM or CODE32 on page 12-585.
12.65 THUMB on page 12-649.
12.66 THUMBX on page 12-650.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-32
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.4 Processor modes, and privileged and unprivileged software execution
Note
ARMv6-M and ARMv7-M do not support the same modes as other ARM architectures and profiles. The
processor modes listed here do not apply to ARMv6-M and ARMv7-M.
User mode is an unprivileged mode, and has restricted access to system resources. All other modes have
full access to system resources in the current security state, can change mode freely, and execute
software as privileged.
Applications that require task protection usually execute in User mode. Some embedded applications
might run entirely in any mode other than User mode. An application that requires full access to system
resources usually executes in System mode.
Modes other than User mode are entered to service exceptions, or to access privileged resources.
On an implementation that includes the Security Extensions, in all modes except Monitor mode and Hyp
mode, code can run in either a secure state or in a non-secure state. In Monitor mode, code can only run
in a secure state, and in Hyp mode, code can only run in a non-secure state.
Related concepts
2.5 Processor modes in ARMv6-M and ARMv7-M on page 2-34.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-33
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.5 Processor modes in ARMv6-M and ARMv7-M
Related concepts
2.4 Processor modes, and privileged and unprivileged software execution on page 2-33.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-34
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.6 VFP hardware
Related concepts
8.1 Architecture support for VFP on page 8-163.
8.2 Half-precision extension for VFP on page 8-164.
8.5 VFP views of the extension register bank on page 8-168.
Related references
Chapter 8 VFP Programming on page 8-161.
Related information
Vector Floating-Point (VFP) architectures.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-35
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.7 ARM registers
Note
The Link Register can also be used as a general-purpose register. The Stack Pointer can be used as a
general-purpose register in ARM state only.
Note
In privileged software execution, CPSR is an alias for APSR and gives access to additional bits.
The following figure shows how the registers are banked in the ARM architecture except ARMv6-M and
ARMv7-M:
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-36
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.7 ARM registers
Application
level view System level views
Privileged modes
Exception modes
APSR CPSR
SPSR_hyp† SPSR_svc SPSR_mon ‡ SPSR_abt SPSR_und SPSR_irq SPSR_fiq
ELR_hyp†
† Hyp mode and the associated banked registers are implemented only as part of the Virtualization Extensions
‡ Monitor mode and the associated banked registers are implemented only as part of the Security Extensions
In ARMv6-M and ARMv7-M based processors, SP is an alias for the two banked stack pointer registers:
• Main stack pointer register, which is only available in privileged software execution.
• Process stack pointer register.
Related concepts
2.8 General-purpose registers on page 2-38.
2.13 Program Counter on page 2-43.
2.14 Application Program Status Register on page 2-44.
2.17 Saved Program Status Registers on page 2-47.
2.16 Current Program Status Register on page 2-46.
2.4 Processor modes, and privileged and unprivileged software execution on page 2-33.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-37
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.8 General-purpose registers
Related concepts
2.13 Program Counter on page 2-43.
2.9 Register accesses on page 2-39.
Related references
2.10 Predeclared core register names on page 2-40.
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
Related information
--use_frame_pointer (compiler option).
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-38
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.9 Register accesses
Related concepts
2.8 General-purpose registers on page 2-38.
2.13 Program Counter on page 2-43.
2.14 Application Program Status Register on page 2-44.
2.16 Current Program Status Register on page 2-46.
2.17 Saved Program Status Registers on page 2-47.
4.19 The Read-Modify-Write operation on page 4-83.
Related references
2.10 Predeclared core register names on page 2-40.
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-39
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.10 Predeclared core register names
ip and IP Intra procedure call scratch register. This is a synonym for R12.
With the exception of a1-a4 and v1-v8, you can write the registers either in all upper case or all lower
case.
Related concepts
2.8 General-purpose registers on page 2-38.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-40
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.11 Predeclared extension register names
Related concepts
8.4 Extension register bank mapping in VFP on page 8-166.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-41
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.12 Predeclared coprocessor names
Related references
10.26 CDP and CDP2 on page 10-320.
10.51 MCR and MCR2 on page 10-366.
10.58 MRC and MRC2 on page 10-374.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-42
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.13 Program Counter
During execution, PC does not contain the address of the currently executing instruction. The address of
the currently executing instruction is typically PC–8 for ARM, or PC–4 for Thumb.
Note
ARM recommends you use the BX instruction to jump to an address or to return from a function, rather
than writing to the PC directly.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.16 B on page 10-305.
10.21 BL on page 10-312.
10.22 BLX on page 10-314.
10.23 BX on page 10-316.
10.24 BXJ on page 10-318.
10.25 CBZ and CBNZ on page 10-319.
10.148 TBB and TBH on page 10-493.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-43
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.14 Application Program Status Register
Related concepts
5.1 Conditional instructions on page 5-96.
5.4 Updates to the condition flags on page 5-99.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.99 SEL on page 10-430.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-44
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.15 The Q flag
The state of the Q flag cannot be tested directly by the condition codes. To read the state of the Q flag,
use an MRS instruction.
MRS r6, APSR
TST r6, #(1<<27); Z is clear if Q flag was set
Related concepts
4.19 The Read-Modify-Write operation on page 4-83.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.74 QADD on page 10-398.
10.121 SMULxy on page 10-454.
10.123 SMULWy on page 10-456.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-45
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.16 Current Program Status Register
Related concepts
5.4 Updates to the condition flags on page 5-99.
2.17 Saved Program Status Registers on page 2-47.
Related references
10.39 IT on page 10-338.
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.100 SETEND on page 10-432.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-46
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.17 Saved Program Status Registers
Related concepts
2.16 Current Program Status Register on page 2-46.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-47
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.18 ARM and Thumb instruction set overview
Data processing These instructions operate on the general-purpose registers. They can perform operations such as addition,
subtraction, or bitwise logic on the contents of two registers and place the result in a third register. They can
also operate on the value in a single register, or on a value in a register and an immediate value supplied within
the instruction.
Long multiply instructions give a 64-bit result in two registers.
Register load and These instructions load or store the value of a single register from or to memory. They can load or store a 32-
store bit word, a 16-bit halfword, or an 8-bit unsigned byte. Byte and halfword loads can either be sign extended or
zero extended to fill the 32-bit register.
A few instructions are also defined that can load or store 64-bit doubleword values into two 32-bit registers.
Multiple register load These instructions load or store any subset of the general-purpose registers from or to memory.
and store
Status register access These instructions move the contents of a status register to or from a general-purpose register.
Coprocessor These instructions support a general way to extend the ARM architecture. They also enable the control of the
CP15 System Control coprocessor registers.
Related concepts
4.13 Load and store multiple register instructions on page 4-75.
Related references
Chapter 10 ARM and Thumb Instructions on page 10-270.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-48
reserved.
Non-Confidential
2 Overview of the ARM Architecture
2.19 Access to the inline barrel shifter
Related concepts
4.3 Load immediate values on page 4-60.
4.4 Load immediate values using MOV and MVN on page 4-61.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 2-49
reserved.
Non-Confidential
Chapter 3
Structure of Assembly Language Modules
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 3-50
reserved.
Non-Confidential
3 Structure of Assembly Language Modules
3.1 Syntax of source lines in assembly language
Syntax
Each line of assembly language source code has this general form:
{symbol} {instruction|directive|pseudo-instruction} {;comment}
A comment is the final part of a source line. The first semicolon on a line marks the beginning of a
comment except where the semicolon appears inside a string literal. The end of the line is the end of the
comment. A comment alone is a valid line. The assembler ignores all comments. You can use blank lines
to make your code more readable.
To make source files easier to read, you can split a long line of source into several lines by placing a
backslash character (\) at the end of the line. The backslash must not be followed by any other
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 3-51
reserved.
Non-Confidential
3 Structure of Assembly Language Modules
3.1 Syntax of source lines in assembly language
characters, including spaces and tabs. The assembler treats the backslash followed by end-of-line
sequence as white space. You can also use blank lines to make your code more readable.
Note
Do not use the backslash followed by end-of-line sequence within quoted strings.
The limit on the length of lines, including any extensions using backslashes, is 4095 characters.
Related concepts
7.6 Labels on page 7-137.
7.10 Numeric local labels on page 7-141.
7.13 String literals on page 7-144.
Related references
3.2 Literals on page 3-53.
7.1 Symbol naming rules on page 7-132.
7.15 Syntax of numeric literals on page 7-146.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 3-52
reserved.
Non-Confidential
3 Structure of Assembly Language Modules
3.2 Literals
3.2 Literals
Assembly language source code can contain numeric, string, Boolean, and single character literals.
Literals can be expressed as:
• Decimal numbers, for example 123.
• Hexadecimal numbers, for example 0x7B.
• Numbers in any base from 2 to 9, for example 5_204 is a number in base 5.
• Floating point numbers, for example 123.4.
• Boolean values {TRUE} or {FALSE}.
• Single character values enclosed by single quotes, for example 'w'.
• Strings enclosed in double quotes, for example "This is a string".
Note
In most cases, a string containing a single character is accepted as a single character value. For example
ADD r0,r1,#"a" is accepted, but ADD r0,r1,#"ab" is faulted.
Related references
3.1 Syntax of source lines in assembly language on page 3-51.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 3-53
reserved.
Non-Confidential
3 Structure of Assembly Language Modules
3.3 ELF sections and the AREA directive
ELF sections are independent, named, indivisible sequences of code or data. A single code section is the
minimum required to produce an application.
The output of an assembly or compilation can include:
• One or more code sections. These are usually read-only sections.
• One or more data sections. These are usually read-write sections. They might be zero-initialized (ZI).
The linker places each section in a program image according to section placement rules. Sections that are
adjacent in source files are not necessarily adjacent in the application image
Use the AREA directive to name the section and set its attributes. The attributes are placed after the name,
separated by commas.
You can choose any name for your sections. However, names starting with any non-alphabetic character
must be enclosed in bars, or an AREA name missing error is generated. For example, |1_DataArea|.
The following example defines a single read-only section called ARMex that contains code:
AREA ARMex, CODE, READONLY ; Name this block of code ARMex
Related concepts
3.4 An example ARM assembly language module on page 3-55.
Related references
12.6 AREA on page 12-582.
Related information
Information about scatter files.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 3-54
reserved.
Non-Confidential
3 Structure of Assembly Language Modules
3.4 An example ARM assembly language module
Application entry
The ENTRY directive declares an entry point to the program. It marks the first instruction to be executed.
In applications using the C library, an entry point is also contained within the C library initialization
code. Initialization code and exception handlers also contain entry points.
Application execution
The application code begins executing at the label start, where it loads the decimal values 10 and 3 into
registers R0 and R1. These registers are added together and the result placed in R0.
Application termination
After executing the main code, the application terminates by returning control to the debugger. You do
this using the ARM semihosting SVC (0x123456 by default), with the following parameters:
• R0 equal to angel_SWIreason_ReportException (0x18).
• R1 equal to ADP_Stopped_ApplicationExit (0x20026).
Program end
The END directive instructs the assembler to stop processing this source file. Every assembly language
source module must finish with an END directive on a line by itself. Any lines following the END directive
are ignored by the assembler.
Related concepts
3.3 ELF sections and the AREA directive on page 3-54.
Related references
12.24 END on page 12-602.
12.26 ENTRY on page 12-604.
Related information
What is semihosting?.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 3-55
reserved.
Non-Confidential
Chapter 4
Writing ARM Assembly Language
Describes the use of a few basic assembly language instructions and the use of macros.
It contains the following sections:
• 4.1 About the Unified Assembler Language on page 4-58.
• 4.2 Register usage in subroutine calls on page 4-59.
• 4.3 Load immediate values on page 4-60.
• 4.4 Load immediate values using MOV and MVN on page 4-61.
• 4.5 Load immediate values using MOV32 on page 4-64.
• 4.6 Load immediate values using LDR Rd, =const on page 4-65.
• 4.7 Literal pools on page 4-66.
• 4.8 Load addresses into registers on page 4-68.
• 4.9 Load addresses to a register using ADR on page 4-69.
• 4.10 Load addresses to a register using ADRL on page 4-71.
• 4.11 Load addresses to a register using LDR Rd, =label on page 4-72.
• 4.12 Other ways to load and store registers on page 4-74.
• 4.13 Load and store multiple register instructions on page 4-75.
• 4.14 Load and store multiple register instructions in ARM and Thumb on page 4-76.
• 4.15 Stack implementation using LDM and STM on page 4-77.
• 4.16 Stack operations for nested subroutines on page 4-79.
• 4.17 Block copy with LDM and STM on page 4-80.
• 4.18 Memory accesses on page 4-82.
• 4.19 The Read-Modify-Write operation on page 4-83.
• 4.20 Optional hash with immediate constants on page 4-84.
• 4.21 Use of macros on page 4-85.
• 4.22 Test-and-branch macro example on page 4-86.
• 4.23 Unsigned integer division macro example on page 4-87.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-56
reserved.
Non-Confidential
4 Writing ARM Assembly Language
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-57
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.1 About the Unified Assembler Language
Related references
9.1 --16 on page 9-195.
12.7 ARM or CODE32 on page 12-585.
9.2 --32 on page 9-196.
9.4 --arm on page 9-199.
9.63 --thumb on page 9-260.
9.64 --thumbx on page 9-261.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-58
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.2 Register usage in subroutine calls
where destination is usually the label on the first instruction of the subroutine.
destination can also be a PC-relative expression.
The BL instruction:
• Places the return address in the link register.
• Sets the PC to the address of the subroutine.
After the subroutine code has executed you can use a BX LR instruction to return.
Note
Calls between separately assembled or compiled modules must comply with the restrictions and
conventions defined by the Procedure Call Standard for the ARM Architecture.
Example
The following example shows a subroutine, doadd, that adds the values of two arguments and returns a
result in R0:
AREA subrout, CODE, READONLY ; Name this block of code
ENTRY ; Mark first instruction to execute
start MOV r0, #10 ; Set up parameters
MOV r1, #3
BL doadd ; Call subroutine
stop MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC #0x123456 ; ARM semihosting (formerly SWI)
doadd ADD r0, r0, r1 ; Subroutine code
BX lr ; Return from subroutine
END ; Mark end of file
Related concepts
4.16 Stack operations for nested subroutines on page 4-79.
Related references
10.16 B on page 10-305.
Related information
Procedure Call Standard for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-59
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.3 Load immediate values
Related concepts
4.4 Load immediate values using MOV and MVN on page 4-61.
4.5 Load immediate values using MOV32 on page 4-64.
4.6 Load immediate values using LDR Rd, =const on page 4-65.
8.6 Load values to VFP registers on page 8-169.
Related references
10.46 LDR pseudo-instruction on page 10-356.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-60
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.4 Load immediate values using MOV and MVN
The following table shows the range of 16-bit values that can be loaded in a single MOV ARM instruction
in ARMv6T2 and later:
Note
These notes give extra information on both tables.
a
The MVN values are only available directly as operands in MVN instructions.
b
These values are available in ARM state only. All the other values in this table are also available
in 32-bit Thumb instructions.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-61
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.4 Load immediate values using MOV and MVN
c
These values are only available in ARMv6T2 and later. They are not available directly as
operands in other instructions.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-62
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.4 Load immediate values using MOV and MVN
The following table shows the range of 16-bit values that can be loaded by the MOV 32-bit Thumb
instruction:
Note
These notes give extra information on the tables.
a
The MVN values are only available directly as operands in MVN instructions.
b
These values are available directly as operands in ADD, SUB, and MOV instructions, but not in MVN
or any other data processing instructions.
c
These values are only available in MOV instructions.
In both ARM and Thumb, you do not have to decide whether to use MOV or MVN. The assembler uses
whichever is appropriate. This is useful if the value is an assembly-time variable.
If you write an instruction with an immediate value that is not available, the assembler reports the error:
Immediate n out of range for this operation.
Related concepts
4.3 Load immediate values on page 4-60.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-63
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.5 Load immediate values using MOV32
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.56 MOV32 pseudo-instruction on page 10-372.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-64
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.6 Load immediate values using LDR Rd, =const
You must ensure that there is a literal pool within range of the LDR instruction generated by the
assembler.
Related concepts
4.7 Literal pools on page 4-66.
Related references
10.46 LDR pseudo-instruction on page 10-356.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-65
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.7 Literal pools
Related concepts
4.6 Load immediate values using LDR Rd, =const on page 4-65.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-66
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.7 Literal pools
Related references
12.51 LTORG on page 12-632.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-67
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.8 Load addresses into registers
Related concepts
4.9 Load addresses to a register using ADR on page 4-69.
4.10 Load addresses to a register using ADRL on page 4-71.
4.5 Load immediate values using MOV32 on page 4-64.
4.11 Load addresses to a register using LDR Rd, =label on page 4-72.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-68
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.9 Load addresses to a register using ADR
The available range of addresses for the ADR instruction depends on the instruction set and encoding:
A32
Any value that can be produced by rotating an 8-bit value right by any even number of bits
within a 32-bit word. The range is relative to the PC.
32-bit T32 encoding
±4095 bytes to a byte, halfword, or word-aligned address.
16-bit T32 encoding
0 to 1020 bytes. label must be word-aligned. You can use the ALIGN directive to ensure this.
In this example, the function arithfunc takes three arguments and returns a result in R0. The first
argument determines the operation to be carried out on the second and third arguments:
argument1=0
Result = argument2 + argument3.
argument1=1
Result = argument2 – argument3.
The jump table is implemented with the following instructions and assembler directives:
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-69
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.9 Load addresses to a register using ADR
EQU
Is an assembler directive. You use it to give a value to a symbol. In this example, it assigns the
value 2 to num. When num is used elsewhere in the code, the value 2 is substituted. Using EQU in
this way is similar to using #define to define a constant in C.
DCD
Declares one or more words of store. In this example, each DCD stores the address of a routine
that handles a particular clause of the jump table.
LDR
The LDR PC,[R3,R0,LSL#2] instruction loads the address of the required clause of the jump
table into the PC. It:
• Multiplies the clause number in R0 by 4 to give a word offset.
• Adds the result to the address of the jump table.
• Loads the contents of the combined address into the PC.
Related concepts
4.11 Load addresses to a register using LDR Rd, =label on page 4-72.
4.10 Load addresses to a register using ADRL on page 4-71.
Related references
10.11 ADR (PC-relative) on page 10-295.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-70
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.10 Load addresses to a register using ADRL
Note
The label used with ADRL must be within the same code section. The assembler faults references to labels
that are out of range in the same section.
ADRL is not available in Thumb state on processors before ARMv6T2.
Related concepts
4.9 Load addresses to a register using ADR on page 4-69.
4.11 Load addresses to a register using LDR Rd, =label on page 4-72.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-71
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.11 Load addresses to a register using LDR Rd, =label
You must ensure that the literal pool is within range of the LDR pseudo-instruction that needs to access
it.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-72
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.11 Load addresses to a register using LDR Rd, =label
LDR, STR
The LDR and STR instructions use post-indexed addressing to update their address registers. For
example, the instruction:
LDRB r2,[r1],#1
loads R2 with the contents of the address pointed to by R1 and then increments R1 by 1.
The example also shows how, unlike the ADR and ADRL pseudo-instructions, you can use the LDR pseudo-
instruction with labels that are outside the current section. The assembler places a relocation directive in
the object code when the source file is assembled. The relocation directive instructs the linker to resolve
the address at link time. The address remains valid wherever the linker places the section containing the
LDR and the literal pool.
Related concepts
4.10 Load addresses to a register using ADRL on page 4-71.
4.6 Load immediate values using LDR Rd, =const on page 4-65.
Related references
10.46 LDR pseudo-instruction on page 10-356.
12.15 DCB on page 12-593.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-73
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.12 Other ways to load and store registers
Related concepts
4.13 Load and store multiple register instructions on page 4-75.
Related references
4.14 Load and store multiple register instructions in ARM and Thumb on page 4-76.
10.55 MOV on page 10-370.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-74
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.13 Load and store multiple register instructions
Note
The lowest numbered register is transferred to or from the lowest memory address accessed, and the
highest numbered register to or from the highest address accessed. The order of the registers in the
register list in the instructions makes no difference.
You can use the --diag_warning 1206 assembler command line option to check that registers in register
lists are specified in increasing order.
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
4.16 Stack operations for nested subroutines on page 4-79.
4.17 Block copy with LDM and STM on page 4-80.
Related references
4.14 Load and store multiple register instructions in ARM and Thumb on page 4-76.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-75
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.14 Load and store multiple register instructions in ARM and Thumb
4.14 Load and store multiple register instructions in ARM and Thumb
Instructions are available in both the ARM and Thumb instruction sets to load and store multiple
registers.
They are:
LDM
Load Multiple registers.
STM
Store Multiple registers.
PUSH
Store multiple registers onto the stack and update the stack pointer.
POP
Load multiple registers off the stack, and update the stack pointer.
In LDM and STM instructions:
• The list of registers loaded or stored can include:
— In A32 instructions, any or all of R0-R12, SP, LR, and PC.
— In 32-bit T32 instructions, any or all of R0-R12, and optionally LR or PC (LDM only) with some
restrictions.
— In 16-bit T32 instructions, any or all of R0-R7.
• The address must be word-aligned. It can be:
— Incremented after each transfer.
— Incremented before each transfer (A32 instructions only).
— Decremented after each transfer (A32 instructions only).
— Decremented before each transfer (not in 16-bit encoded T32 instructions).
• The base register can be either:
— Updated to point to the next block of data in memory.
— Left as it was before the instruction.
When the base register is updated to point to the next block in memory, this is called writeback, that is,
the adjusted address is written back to the base register.
In PUSH and POP instructions:
• The stack pointer (SP) is the base register, and is always updated.
• The address is incremented after each transfer in POP instructions, and decremented before each
transfer in PUSH instructions.
• The list of registers loaded or stored can include:
— In A32 instructions, any or all of R0-R12, SP, LR, and PC.
— In 32-bit T32 instructions, any or all of R0-R12, and optionally LR or PC (POP only) with some
restrictions.
— In 16-bit T32 instructions, any or all of R0-R7, and optionally LR (PUSH only) or PC (POP only).
Note
Use of SP in the list of registers in these ARM instructions is deprecated.
ARM STM and PUSH instructions that use PC in the list of registers, and ARM LDM and POP instructions
that use both PC and LR in the list of registers are deprecated.
Related concepts
4.13 Load and store multiple register instructions on page 4-75.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-76
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.15 Stack implementation using LDM and STM
Stack-oriented suffix For store or push instructions For load or pop instructions
The following table shows the load and store multiple instructions with the stack-oriented suffixes for the
various stack types:
Full descending STMFD (STMDB, Decrement Before) LDMFD (LDM, increment after)
Full ascending STMFA (STMIB, Increment Before) LDMFA (LDMDA, Decrement After)
Empty descending STMED (STMDA, Decrement After) LDMED (LDMIB, Increment Before)
Empty ascending STMEA (STM, increment after) LDMEA (LDMDB, Decrement Before)
For example:
STMFD sp!, {r0-r5} ; Push onto a Full Descending Stack
LDMFD sp!, {r0-r5} ; Pop from a Full Descending Stack
Note
The Procedure Call Standard for the ARM Architecture (AAPCS), and armcc always use a full
descending stack.
The PUSH and POP instructions assume a full descending stack. They are the preferred synonyms for
STMDB and LDM with writeback.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-77
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.15 Stack implementation using LDM and STM
Related concepts
4.13 Load and store multiple register instructions on page 4-75.
Related references
10.41 LDM on page 10-342.
Related information
Procedure Call Standard for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-78
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.16 Stack operations for nested subroutines
Note
Use this with care in mixed ARM and Thumb systems. In ARMv4T systems, you cannot change state by
popping directly into PC. In these cases you must pop the address into a temporary register and use the
BX instruction.
Related concepts
4.2 Register usage in subroutine calls on page 4-59.
4.13 Load and store multiple register instructions on page 4-75.
Related information
Procedure Call Standard for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-79
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.17 Block copy with LDM and STM
You can make this module more efficient by using LDM and STM for as much of the copying as possible.
Eight is a sensible number of words to transfer at a time, given the number of available registers. You can
find the number of eight-word multiples in the block to be copied (if R2 = number of words to be copied)
using:
MOVS r3, r2, LSR #3 ; number of eight word multiples
You can use this value to control the number of iterations through a loop that copies eight words per
iteration. When there are fewer than eight words left, you can find the number of words left (assuming
that R2 has not been corrupted) using:
ANDS r2, r2, #7
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-80
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.17 Block copy with LDM and STM
Note
The purpose of this example is to show the use of the LDM and STM instructions. There are other ways to
perform bulk copy operations, the most efficient of which depends on many factors and is outside the
scope of this document.
Related information
What is the fastest way to copy memory on a Cortex-A8?.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-81
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.18 Memory accesses
Pre-indexed addressing
The offset value is applied to an address obtained from the base register. The result is used as the
address for the memory access, and written back into the base register. The assembly language
syntax for this mode is:
[Rn, offset]!
Post-indexed addressing
The address obtained from the base register is used, unchanged, as the address for the memory
access. The offset value is applied to the address, and written back into the base register. The
assembly language syntax for this mode is:
[Rn], offset
Related concepts
6.16 Address alignment on page 6-128.
Related references
2.7 ARM registers on page 2-36.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-82
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.19 The Read-Modify-Write operation
Related concepts
2.9 Register accesses on page 2-39.
2.15 The Q flag on page 2-45.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
11.21 VMRS on page 11-560.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-83
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.20 Optional hash with immediate constants
Related references
Chapter 10 ARM and Thumb Instructions on page 10-270.
Chapter 11 VFP Instructions on page 11-537.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-84
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.21 Use of macros
Related concepts
4.22 Test-and-branch macro example on page 4-86.
4.23 Unsigned integer division macro example on page 4-87.
Related references
12.52 MACRO and MEND on page 12-633.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-85
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.22 Test-and-branch macro example
The line after the MACRO directive is the macro prototype statement. This defines the name
(TestAndBranch) you use to invoke the macro. It also defines parameters ($label, $dest, $reg, and
$cc). Unspecified parameters are substituted with an empty string. For this macro you must give values
for $dest, $reg and $cc to avoid syntax errors. The assembler substitutes the values you give into the
code.
This macro can be invoked as follows:
test TestAndBranch NonZero, r0, NE
...
...
NonZero
Related concepts
4.21 Use of macros on page 4-85.
4.23 Unsigned integer division macro example on page 4-87.
7.10 Numeric local labels on page 7-141.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-86
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.23 Unsigned integer division macro example
The macro checks that no two parameters use the same register. It also optimizes the code produced if
only the remainder is required.
To avoid multiple definitions of labels if DivMod is used more than once in the assembler source, the
macro uses numeric local labels (90, 91).
The following example shows the code that this macro produces if it is invoked as follows:
ratio DivMod R0,R5,R4,R2
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-87
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.23 Unsigned integer division macro example
Related concepts
4.21 Use of macros on page 4-85.
4.22 Test-and-branch macro example on page 4-86.
7.10 Numeric local labels on page 7-141.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-88
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.24 Instruction and directive relocations
Note
You can use the RELOC directive to control the relocation at a finer level, but this requires knowledge of
the ABI.
Example
IMPORT sym ; sym is an external symbol
DCW sym ; Because DCW only outputs 16 bits, only the lower
; 16 bits of the address of sym are inserted at
; link-time.
Related references
12.6 AREA on page 12-582.
12.28 EXPORT or GLOBAL on page 12-606.
12.46 IMPORT and EXTERN on page 12-626.
12.58 REQUIRE on page 12-642.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-89
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.24 Instruction and directive relocations
Related information
ELF for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-90
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.25 Frame directives
Related concepts
4.26 Exception tables and Unwind tables on page 4-92.
Related references
12.3 About frame directives on page 12-578.
Related information
Procedure Call Standard for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-91
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.26 Exception tables and Unwind tables
Related concepts
4.25 Frame directives on page 4-91.
Related references
12.3 About frame directives on page 12-578.
9.29 --exceptions, --no_exceptions on page 9-225.
9.30 --exceptions_unwind, --no_exceptions_unwind on page 9-226.
12.40 FRAME UNWIND ON on page 12-619.
12.41 FRAME UNWIND OFF on page 12-620.
12.42 FUNCTION or PROC on page 12-621.
12.25 ENDFUNC or ENDP on page 12-603.
Related information
Exception Handling ABI for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-92
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.27 Assembly language changes after RVCT v2.1
The default addressing mode for LDM and STM is IA LDMIA, STMIA LDM, STM
You can use the PUSH and POP mnemonics for full, descending STMFD sp!, {reglist} PUSH {reglist}
stack operations in ARM in addition to Thumb. LDMFD sp!, {reglist} POP {reglist}
You can use the LSL, LSR, ASR, ROR, and RRX instruction MOV Rd, Rn, LSL shift LSL Rd, Rn, shift
mnemonics for instructions with rotations and no other operation, MOV Rd, Rn, LSR shift LSR Rd, Rn, shift
in ARM in addition to Thumb. MOV Rd, Rn, ASR shift ASR Rd, Rn, shift
MOV Rd, Rn, ROR shift ROR Rd, Rn, shift
MOV Rd, Rn, RRX RRX Rd, Rn
Use the label form for PC-relative addressing. Do not use the LDR Rd, [pc, #offset] LDR Rd, label
offset form in new code.
Specify both registers for doubleword memory accesses. You must LDRD Rd, addr_mode LDRD Rd, Rd2, addr_mode
still obey rules about the register combinations you can use.
{cond}, if used, is always the last element of all instructions. ADD{cond}S ADDS{cond}
LDR{cond}SB LDRSB{cond}
In addition, some flexibility is permitted that was not permitted in previous assemblers as the following
table shows:
If the destination register is the same as the first operand, you can use a two register form ADD r1, r3 ADD r1, r1, r3
of the instruction.
You can write source code for Thumb processors earlier than ARMv6T2 using UAL.
If you are writing Thumb code for a processor earlier than ARMv6T2, you must restrict yourself to
instructions that are available on the processor. The assembler generates error messages if you attempt to
use an instruction that is not available.
If you are writing Thumb code for an ARMv6T2 or later processor, you can minimize your code size by
using 16-bit instructions wherever possible.
The following table shows the main differences between the UAL and the pre-UAL Thumb assembly
language:
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-93
reserved.
Non-Confidential
4 Writing ARM Assembly Language
4.27 Assembly language changes after RVCT v2.1
Table 4-9 Differences between pre-UAL Thumb syntax and UAL syntax
The default addressing mode for LDM and LDMIA, STMIA LDM, STM
STM is IA
You must use the S postfix on instructions ADD r1, r2, r3 ADDS r1, r2, r3
that update the flags. This change is essential SUB r4, r5, #6 SUBS r4, r5, #6
MOV r0, #1 MOVS r0, #1
to avoid conflict with 32-bit Thumb LSR r1, r2, #1 LSRS r1, r2, #1
instructions.
The preferred form for ALU instructions ADD r7, r8 ADD r7, r7, r8
specifies three registers, even if the SUB r1, #80 SUBS r1, r1, #80
destination register is the same as the first
operand. However, the UAL syntax allows
the two register syntax.
If Rd and Rn are both Lo registers, MOV Rd, MOV r2, r3 ADDS r2, r3, #0
Rn is disassembled as ADDS Rd, Rn, #0. MOV r8, r9 MOV r8, r9
CPY r0, r1 MOV r0, r1
LSL r2, r3, #0 MOVS r2, r3
NEG Rd, Rm is disassembled as RSBS Rd, NEG Rd, Rm RSBS Rd, Rm, #0
Rm, #0.
When using the LDR Rd,=const literal LDR r0,=0 LDR r0,=0
load pseudo-instruction, in pre-UAL syntax, ; generates the instruction: ; generates the sequence:
MOVS r0,#0 LDR r0,{pc}+n
the generated instruction might affect the ...
condition code flags. In UAL syntax, the DCD 0
generated instruction sequence is guaranteed
to not affect the condition code flags.
Related references
12.7 ARM or CODE32 on page 12-585.
12.11 CODE16 on page 12-589.
9.1 --16 on page 9-195.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 4-94
reserved.
Non-Confidential
Chapter 5
Condition Codes
Describes condition codes and the conditional execution of ARM and Thumb code.
It contains the following sections:
• 5.1 Conditional instructions on page 5-96.
• 5.2 Conditional execution in ARM state on page 5-97.
• 5.3 Conditional execution in Thumb state on page 5-98.
• 5.4 Updates to the condition flags on page 5-99.
• 5.5 Condition code suffixes and related flags on page 5-100.
• 5.6 Comparison of condition code meanings in integer and floating-point code on page 5-101.
• 5.7 Benefits of using conditional execution on page 5-103.
• 5.8 Example showing the benefits of using conditional instructions on page 5-104.
• 5.9 Optimization for execution speed on page 5-107.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-95
reserved.
Non-Confidential
5 Condition Codes
5.1 Conditional instructions
Related concepts
5.4 Updates to the condition flags on page 5-99.
5.2 Conditional execution in ARM state on page 5-97.
5.3 Conditional execution in Thumb state on page 5-98.
Related references
5.5 Condition code suffixes and related flags on page 5-100.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-96
reserved.
Non-Confidential
5 Condition Codes
5.2 Conditional execution in ARM state
Related concepts
5.3 Conditional execution in Thumb state on page 5-98.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-97
reserved.
Non-Confidential
5 Condition Codes
5.3 Conditional execution in Thumb state
Related concepts
5.2 Conditional execution in ARM state on page 5-97.
Related references
10.39 IT on page 10-338.
10.25 CBZ and CBNZ on page 10-319.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-98
reserved.
Non-Confidential
5 Condition Codes
5.4 Updates to the condition flags
The condition flags are held in the APSR. They are set or cleared as follows:
N
Set to 1 when the result of the operation is negative, cleared to 0 otherwise.
Z
Set to 1 when the result of the operation is zero, cleared to 0 otherwise.
C
Set to 1 when the operation results in a carry, or when a subtraction results in no borrow, cleared
to 0 otherwise.
V
Set to 1 when the operation causes overflow, cleared to 0 otherwise.
C is set in one of the following ways:
• For an addition, including the comparison instruction CMN, C is set to 1 if the addition produced a
carry (that is, an unsigned overflow), and to 0 otherwise.
• For a subtraction, including the comparison instruction CMP, C is set to 0 if the subtraction produced a
borrow (that is, an unsigned underflow), and to 1 otherwise.
• For non-addition/subtractions that incorporate a shift operation, C is set to the last bit shifted out of
the value by the shifter.
• For other non-addition/subtractions, C is normally left unchanged, but see the individual instruction
descriptions for any special cases.
Overflow occurs if the result of a signed add, subtract, or compare is greater than or equal to 231, or less
than –231.
Related concepts
5.1 Conditional instructions on page 5-96.
Related references
5.5 Condition code suffixes and related flags on page 5-100.
Chapter 10 ARM and Thumb Instructions on page 10-270.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-99
reserved.
Non-Confidential
5 Condition Codes
5.5 Condition code suffixes and related flags
EQ Z set Equal
MI N set Negative
VS V set Overflow
VC V clear No overflow
The optional condition code is shown in syntax descriptions as {cond}. This condition is encoded in
ARM instructions, and encoded in a preceding IT instruction for Thumb instructions. An instruction with
a condition code is only executed if the condition flags in the APSR meet the specified condition.
In Thumb state on processors before ARMv6T2, the {cond} field is only permitted on certain branch
instructions because there is no IT instruction on these processors.
The following is an example of conditional execution:
ADD r0, r1, r2 ; r0 = r1 + r2, don't update flags
ADDS r0, r1, r2 ; r0 = r1 + r2, and update flags
ADDSCS r0, r1, r2 ; If C flag set then r0 = r1 + r2,
; and update flags
CMP r0, r1 ; update flags based on r0-r1.
Related concepts
5.1 Conditional instructions on page 5-96.
5.4 Updates to the condition flags on page 5-99.
Related references
5.6 Comparison of condition code meanings in integer and floating-point code on page 5-101.
Chapter 10 ARM and Thumb Instructions on page 10-270.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-100
reserved.
Non-Confidential
5 Condition Codes
5.6 Comparison of condition code meanings in integer and floating-point code
Suffix Meaning after integer data processing instruction Meaning after floating-point instruction
EQ Equal Equal
NE Not equal Not equal, or unordered
CS Carry set Greater than or equal, or unordered
HS Unsigned higher or same Greater than or equal, or unordered
CC Carry clear Less than
LO Unsigned lower Less than
MI Negative Less than
PL Positive or zero Greater than or equal, or unordered
VS Overflow Unordered (at least one NaN operand)
VC No overflow Not unordered
HI Unsigned higher Greater than, or unordered
LS Unsigned lower or same Less than or equal
GE Signed greater than or equal Greater than or equal
LT Signed less than Less than, or unordered
GT Signed greater than Greater than
LE Signed less than or equal Less than or equal, or unordered
AL Always (normally omitted) Always (normally omitted)
Note
The type of the instruction that last updated the condition flags determines the meaning of the condition
codes.
Related concepts
5.1 Conditional instructions on page 5-96.
5.4 Updates to the condition flags on page 5-99.
Related references
5.5 Condition code suffixes and related flags on page 5-100.
11.4 VCMP, VCMPE on page 11-543.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-101
reserved.
Non-Confidential
5 Condition Codes
5.6 Comparison of condition code meanings in integer and floating-point code
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-102
reserved.
Non-Confidential
5 Condition Codes
5.7 Benefits of using conditional execution
Related concepts
5.8 Example showing the benefits of using conditional instructions on page 5-104.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-103
reserved.
Non-Confidential
5 Condition Codes
5.8 Example showing the benefits of using conditional instructions
The following examples show implementations of the gcd algorithm with and without conditional
instructions:
Note
The detailed analysis of execution speed only applies to an ARM7™ processor. The code density
calculations apply to all ARM processors.
The code is seven instructions long because of the number of branches. Every time a branch is taken, the
processor must refill the pipeline and continue from the new location. The other instructions and non-
executed branches use a single cycle each.
The following table shows the number of cycles this implementation uses on an ARM7 processor when
R0 equals 1 and R1 equals 2:
1 2 CMP r0, r1 1
1 2 BLT less 3
1 2 B gcd 3
1 1 CMP r0, r1 1
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-104
reserved.
Non-Confidential
5 Condition Codes
5.8 Example showing the benefits of using conditional instructions
1 1 BEQ end 3
Total = 13
In addition to improving code size, in most cases this code executes faster than the version that uses only
branches.
The following table shows the number of cycles this implementation uses on an ARM7 processor when
R0 equals 1 and R1 equals 2:
1 2 CMP r0, r1 1
1 1 SUBLT r1,r1,r0 1
1 1 BNE gcd 3
1 1 CMP r0,r1 1
Total = 10
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-105
reserved.
Non-Confidential
5 Condition Codes
5.8 Example showing the benefits of using conditional instructions
This assembles equally well to ARM or Thumb code. The assembler checks the IT instructions, but
omits them on assembly to ARM code.
It requires one more instruction in Thumb code (the IT instruction) than in ARM code, but the overall
code size is 10 bytes in Thumb code compared with 16 bytes in ARM code.
Related concepts
5.7 Benefits of using conditional execution on page 5-103.
5.9 Optimization for execution speed on page 5-107.
Related references
10.39 IT on page 10-338.
5.5 Condition code suffixes and related flags on page 5-100.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-106
reserved.
Non-Confidential
5 Condition Codes
5.9 Optimization for execution speed
Related information
ARM Architecture Reference Manual.
Further reading.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 5-107
reserved.
Non-Confidential
Chapter 6
Using the Assembler
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-108
reserved.
Non-Confidential
6 Using the Assembler
6.1 armasm command-line syntax
where:
options
are commands that instruct the assembler how to assemble the inputfile. You can invoke
armasm with any combination of options separated by spaces. You can specify values for some
options. To specify a value for an option, use either ‘=’ (option=value) or a space character
(option value).
inputfile
is an assembly source file. It must contain UAL or pre-UAL ARM or Thumb assembly
language.
Note
The inline and embedded assemblers are part of the C and C++ compilers and do not use any command-
line syntax for invocation. However, to pass additional assembler options when the compiler invokes
armasm for embedded assembly, you can use the armcc –A option.
The assembler command line is case-insensitive, except in filenames and where specified. The assembler
uses the same command-line ordering rules as the compiler. This means that if the command line
contains options that conflict with each other, then the last option found always takes precedence.
Related information
Order of compiler command-line options.
Compiler command-line options listed by group.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-109
reserved.
Non-Confidential
6 Using the Assembler
6.2 Specify command-line options with an environment variable
Related concepts
6.1 armasm command-line syntax on page 6-109.
Related information
Toolchain environment variables.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-110
reserved.
Non-Confidential
6 Using the Assembler
6.3 Using stdin to input source code to the assembler
Note
The source code from stdin is stored in an internal cache that can hold up to 8 MB. You can increase
this cache size using the --maxcache command-line option.
Procedure
1. Invoke the assembler with the command-line options you want to use. Use the minus character (-) as
the source filename to instruct the assembler to take input from stdin. You must specify the output
filename using the -o option. For example:
armasm --bigend -o output.o -
2. Enter your input. For example:
AREA ARMex, CODE, READONLY
; Name this block of code ARMex
ENTRY ; Mark first instruction to execute
start
MOV r0, #10 ; Set up parameters
MOV r1, #3
ADD r0, r0, r1 ; r0 = r0 + r1
stop
MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC #0x123456 ; ARM semihosting (formerly SWI)
END ; Mark end of file
Related concepts
6.1 armasm command-line syntax on page 6-109.
13.1 Overview of via files on page 13-654.
Related references
9.47 --maxcache=n on page 9-244.
Related information
Rules for specifying command-line options.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-111
reserved.
Non-Confidential
6 Using the Assembler
6.4 Built-in variables and constants
{ARMASM_VERSION} Holds an integer that increases with each version of armasm. The format of the
version number is PVVbbbb where:
P
is the major version.
VV
is the minor version.
bbbb
is the build number.
{ENDIAN} Has the value "big" if the assembler is in big-endian mode, or "little" if it is in
little-endian mode.
{FPIC} Has the Boolean value {True} if --apcs=/fpic is set. The default is {False}.
{FPU} Holds the name of the selected FPU. The default is "SoftVFP".
{LINENUM} Holds an integer indicating the line number in the current source file.
{LINENUMUP} When used in a macro, holds an integer indicating the line number of the current
macro. The value is the same as {LINENUM} when used in a non-macro context.
{LINENUMUPPER} When used in a macro, holds an integer indicating the line number of the top macro.
The value is the same as {LINENUM} when used in a non-macro context.
{OPT} Value of the currently-set listing option. You can use the OPT directive to save the
current listing option, force a change in it, or restore its original value.
{PCSTOREOFFSET} Is the offset between the address of the STR PC,[…] or STM Rb,{…, PC}
instruction and the value of PC stored out. This varies depending on the processor or
architecture specified.
{ROPI} Has the Boolean value {True} if --apcs=/ropi is set. The default is {False}.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-112
reserved.
Non-Confidential
6 Using the Assembler
6.4 Built-in variables and constants
{RWPI} Has the Boolean value {True} if --apcs=/rwpi is set. The default is {False}.
You can use built-in variables in expressions or conditions in assembly source code. For example:
IF {ARCHITECTURE} = "4T"
Note
All built-in string variables contain case-sensitive values. Relational operations on these built-in
variables do not match with strings that contain an incorrect case. Use the command-line options --cpu
and --fpu to determine valid values for {CPU}, {ARCHITECTURE}, and {FPU}.
The assembler defines the built-in Boolean constants TRUE and FALSE.
The following table lists the target processor-related built-in variables that are predefined by the
assembler. Where the value field is empty, the symbol is a Boolean value and the meaning column
describes when its value is {TRUE}.
{TARGET_ARCH_ARM} num The number of the ARM base architecture of the target processor
irrespective of whether the assembler is assembling for ARM or Thumb.
{TARGET_ARCH_THUMB} num The number of the Thumb base architecture of the target processor
irrespective of whether the assembler is assembling for ARM or Thumb.
The value is defined as zero if the target does not support Thumb.
{TARGET_ARCH_XX} – XX represents the target architecture and its value depends on the target
processor. For example, if you specify the assembler option --cpu=4T or
--cpu=ARM7TDMI then {TARGET_ARCH_4T} is defined.
{TARGET_FEATURE_CLZ} – If the target processor supports the CLZ instruction (that is, ARMv5T and
later except ARMv6-M).
{TARGET_FEATURE_DIVIDE} – If the target processor supports the hardware divide instructions SDIV and
UDIV.
{TARGET_FEATURE_DOUBLEWORD} – If the target processor supports the LDRD and STRD instructions (that is,
ARMv5TE and later except ARMv6-M).
{TARGET_FEATURE_DSPMUL} – If the DSP-enhanced multiplier (for example the SMLAxy instruction) is
available, for example in ARMv5TE.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-113
reserved.
Non-Confidential
6 Using the Assembler
6.4 Built-in variables and constants
{TARGET_FEATURE_MULTIPLY} – If the target processor supports the long multiply instructions SMULL,
SMLAL, UMULL, and UMLAL (that is, all architectures except ARMv6-M).
{TARGET_FEATURE_UNALIGNED} – If the target processor has support for unaligned access (that is, ARMv6
and later except ARMv6-M).
{TARGET_FPU_SOFTVFP} – If assembling with the option --fpu=softvfp.
{TARGET_FPU_SOFTVFP_VFP} – If assembling for a target processor with softvfp and VFP hardware, for
example --fpu=softvfp+vfpv3.
{TARGET_FPU_VFP} – If assembling for a target processor with VFP hardware, without using
softvfp, for example --fpu=vfpv3.
{TARGET_PROFILE_R} – If assembling for a Cortex-R profile processor, for example, if you specify
the assembler option --cpu=7-R.
The following table shows the possible values for {TARGET_ARCH_ARM} and {TARGET_ARCH_THUMB}, and
for XX in the TARGET_ARCH_XX built-in variables. It also shows how these values relate to versions of the
ARM architecture.
v4 4 0 4
v4T 4 1 4T
v5T 5 2 5T
v5TE 5 2 5TE
v5TEJ 5 2 5TEJ
v6 6 3 6
v6K 6 3 6K
v6Z 6 3 6Z
v6T2 6 4 6T2
v6-M 0 3 6_M
v6S-M 0 3 6S_M
v7-R 7 4 7_R
v7-M 0 4 7_M
v7E-M 0 4 7E_M
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-114
reserved.
Non-Confidential
6 Using the Assembler
6.4 Built-in variables and constants
Related concepts
6.5 Identifying versions of armasm in source code on page 6-116.
Related references
9.14 --cpu=name on page 9-209.
9.33 --fpu=name on page 9-229.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-115
reserved.
Non-Confidential
6 Using the Assembler
6.5 Identifying versions of armasm in source code
The assembler also defines the built-in variable |ads$version| for legacy code. This variable did not
exist before ADS and RVCT. If you have to build versions of your code using legacy development tools,
you can test for the built-in variable |ads$version|. If this variable is not defined, then the assembler is
part of a legacy development toolchain. Use code similar to the following:
IF :DEF: |ads$version|
; code for RealView or ADS
ELSE
; code for SDT (a legacy development toolchain)
ENDIF
Related references
6.4 Built-in variables and constants on page 6-112.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-116
reserved.
Non-Confidential
6 Using the Assembler
6.6 Diagnostic messages
Related concepts
6.7 Interlocks diagnostics on page 6-118.
6.8 Automatic IT block generation on page 6-119.
6.9 Thumb branch target alignment on page 6-120.
6.10 Thumb code size diagnostics on page 6-121.
6.11 ARM and Thumb instruction portability diagnostics on page 6-122.
6.12 Instruction width diagnostics on page 6-123.
6.13 Two pass assembler diagnostics on page 6-124.
Related references
9.18 --diag_error=tag[,tag,…] on page 9-214.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-117
reserved.
Non-Confidential
6 Using the Assembler
6.7 Interlocks diagnostics
Related concepts
6.8 Automatic IT block generation on page 6-119.
6.9 Thumb branch target alignment on page 6-120.
6.12 Instruction width diagnostics on page 6-123.
6.6 Diagnostic messages on page 6-117.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-118
reserved.
Non-Confidential
6 Using the Assembler
6.8 Automatic IT block generation
You can receive warning messages about this automatic generation of IT blocks when assembling
Thumb code. To do this, use the following command-line option when invoking the assembler:
armasm --diag_warning 1763
Related concepts
6.6 Diagnostic messages on page 6-117.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-119
reserved.
Non-Confidential
6 Using the Assembler
6.9 Thumb branch target alignment
Related concepts
6.6 Diagnostic messages on page 6-117.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-120
reserved.
Non-Confidential
6 Using the Assembler
6.10 Thumb code size diagnostics
Related concepts
6.17 Instruction width selection in Thumb on page 6-129.
2.2 ARM, Thumb, and ThumbEE instruction sets on page 2-31.
6.6 Diagnostic messages on page 6-117.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-121
reserved.
Non-Confidential
6 Using the Assembler
6.11 ARM and Thumb instruction portability diagnostics
It warns for any instruction that cannot be assembled in the other instruction set. This is only a hint, and
other factors, like relocation availability or target distance might affect the accuracy of the message.
Related concepts
2.2 ARM, Thumb, and ThumbEE instruction sets on page 2-31.
6.6 Diagnostic messages on page 6-117.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-122
reserved.
Non-Confidential
6 Using the Assembler
6.12 Instruction width diagnostics
Related concepts
6.6 Diagnostic messages on page 6-117.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-123
reserved.
Non-Confidential
6 Using the Assembler
6.13 Two pass assembler diagnostics
armasm is a two pass assembler and the input code that the assembler reads must be identical in both
passes. If a symbol is defined after the :DEF: test for that symbol, then the code read in pass one might
be different from the code read in pass two. armasm can warn in this situation.
To do this, use the --diag_warning 1907 command-line option when invoking armasm.
Example
The following example shows that the symbol foo is defined after the :DEF: foo test.
AREA x,CODE
[ :DEF: foo
]
foo MOV r3, r4
END
Related concepts
6.8 Automatic IT block generation on page 6-119.
6.9 Thumb branch target alignment on page 6-120.
6.12 Instruction width diagnostics on page 6-123.
6.6 Diagnostic messages on page 6-117.
1.3 How the assembler works on page 1-25.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
1.4 Directives that can be omitted in pass 2 of the assembler on page 1-27.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-124
reserved.
Non-Confidential
6 Using the Assembler
6.14 Conditional assembly
For example, in the following code, the C preprocessor replaces y with x+1 at the point at which y is
used, and therefore example() returns 0:
#define x 1
#define y x+1
#define x 2
int example()
{
#if y == 2
return 1;
#else
return 0;
#endif
}
Conditional assembly is based on variables, and works on each line in turn. Unlike the C preprocessor,
the assembler evaluates expressions. Conditional assembly is controlled by the following:
• Assembler directives that declare and set the value of variables, for example GBLx, LCLx and SETx.
• Assembler directives that control the flow of the assembly, for example WHILE, IF and ELSE.
• Assembler directives that define macros, for example MACRO.
• The assembler command-line option --predefine, which pre-executes a GBLx and SETx directive.
For example, in the following code, the assembler evaluates x+1 at the point at which the SETA directive
occurs, and therefore MOV sets r0 to 1:
GBLA x
GBLA y
x SETA 1
y SETA x+1
x SETA 2
AREA example, CODE
IF y == 2
MOV r0, #1
ELSE
MOV r0, #0
ENDIF
END
Related references
12.2 About assembly control directives on page 12-577.
9.57 --predefine "directive" on page 9-254.
Related information
-Dname[(parm-list)][=def] compiler option.
-Uname compiler option.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-125
reserved.
Non-Confidential
6 Using the Assembler
6.15 Using the C preprocessor
--arm_only --diag_style -i
Some of the options that armasm passes to armcc are converted to the armcc equivalent beforehand.
These are shown in the following table:
armasm armcc
--16 --thumb
--32 --arm
-i -I
To pass other simple compiler options, such as the preprocessor option -D, you must use the
--cpreproc_opts command-line option. armasm correctly interprets the preprocessed #line commands.
It can generate error messages and debug_line tables using the information in the #line commands.
In this example, the preprocessor outputs a file called preprocessed.s, and armasm assembles it.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-126
reserved.
Non-Confidential
6 Using the Assembler
6.15 Using the C preprocessor
Related references
9.11 --cpreproc on page 9-206.
9.12 --cpreproc_opts=option[,option,…] on page 9-207.
Related information
Compiler command-line options listed by group.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-127
reserved.
Non-Confidential
6 Using the Assembler
6.16 Address alignment
ARMv7
In ARMv7-R, the A bit in the System Control Register, SCTLR, controls whether alignment checking is
enabled or disabled. In ARMv7-M, the UNALIGN_TRP bit, bit 3, in the Configuration and Control Register
(CCR) controls this.
If alignment checking is enabled, all unaligned word and halfword transfers cause an alignment
exception. If disabled, unaligned accesses are permitted for the LDR, LDRH, STR, STRH, LDRSH, LDRT, STRT,
LDRSHT, LDRHT, STRHT, and TBH instructions. Other data-accessing instructions always cause an alignment
exception for unaligned data.
For STRD and LDRD, the specified address must be word-aligned.
ARMv6
ARMv6 can be configured to support either the ARMv5 or ARMv7 alignment models, depending on the
value of the U bit in the SCTLR. ARMv6-M faults all unaligned data accesses.
--no_unaligned_access
If all your data accesses are aligned, you can use the --no_unaligned_access command-line option to
avoid linking in any library functions that support unaligned accesses.
Related references
9.65 --unaligned_access, --no_unaligned_access on page 9-262.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-128
reserved.
Non-Confidential
6 Using the Assembler
6.17 Instruction width selection in Thumb
Related concepts
10.2 Instruction width specifiers on page 10-281.
6.10 Thumb code size diagnostics on page 6-121.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 6-129
reserved.
Non-Confidential
Chapter 7
Symbols, Literals, Expressions, and Operators
Describes how you can use symbols to represent variables, addresses, and constants in code, and how
you can combine these with operators to create numeric or string expressions.
It contains the following sections:
• 7.1 Symbol naming rules on page 7-132.
• 7.2 Variables on page 7-133.
• 7.3 Numeric constants on page 7-134.
• 7.4 Assembly time substitution of variables on page 7-135.
• 7.5 Register-relative and PC-relative expressions on page 7-136.
• 7.6 Labels on page 7-137.
• 7.7 Labels for PC-relative addresses on page 7-138.
• 7.8 Labels for register-relative addresses on page 7-139.
• 7.9 Labels for absolute addresses on page 7-140.
• 7.10 Numeric local labels on page 7-141.
• 7.11 Syntax of numeric local labels on page 7-142.
• 7.12 String expressions on page 7-143.
• 7.13 String literals on page 7-144.
• 7.14 Numeric expressions on page 7-145.
• 7.15 Syntax of numeric literals on page 7-146.
• 7.16 Syntax of floating-point literals on page 7-147.
• 7.17 Logical expressions on page 7-148.
• 7.18 Logical literals on page 7-149.
• 7.19 Unary operators on page 7-150.
• 7.20 Binary operators on page 7-151.
• 7.21 Multiplicative operators on page 7-152.
• 7.22 String manipulation operators on page 7-153.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-130
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-131
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.1 Symbol naming rules
The bars are not part of the symbol. You cannot use bars, semicolons, or newlines within the bars.
Related concepts
7.10 Numeric local labels on page 7-141.
Related references
2.10 Predeclared core register names on page 2-40.
2.11 Predeclared extension register names on page 2-41.
2.12 Predeclared coprocessor names on page 2-42.
6.4 Built-in variables and constants on page 6-112.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-132
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.2 Variables
7.2 Variables
You can declare numeric, logical, or string variables using assembler directives.
The value of a variable can be changed as assembly proceeds. Variables are local to the assembler. This
means that in the generated code or data, every instance of the variable has a fixed value.
The type of a variable cannot be changed. Variables are one of the following types:
• Numeric.
• Logical.
• String.
The range of possible values of a numeric variable is the same as the range of possible values of a
numeric constant or numeric expression.
The possible values of a logical variable are {TRUE} or {FALSE}.
The range of possible values of a string variable is the same as the range of values of a string expression.
Use the GBLA, GBLL, GBLS, LCLA, LCLL, and LCLS directives to declare symbols representing variables, and
assign values to them using the SETA, SETL, and SETS directives.
Example
a SETA 100
L1 MOV R1, #(a*5) ; In the object file, this is MOV R1, #500
a SETA 200 ; Value of 'a' is 200 only after this point.
; The previous instruction is always MOV R1, #500
…
BNE L1 ; When the processor branches to L1, it executes
; MOV R1, #500
Related concepts
7.14 Numeric expressions on page 7-145.
7.12 String expressions on page 7-143.
7.3 Numeric constants on page 7-134.
7.17 Logical expressions on page 7-148.
Related references
12.43 GBLA, GBLL, and GBLS on page 12-622.
12.50 LCLA, LCLL, and LCLS on page 12-631.
12.63 SETA, SETL, and SETS on page 12-647.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-133
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.3 Numeric constants
Related concepts
7.14 Numeric expressions on page 7-145.
Related references
7.15 Syntax of numeric literals on page 7-146.
12.27 EQU on page 12-605.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-134
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.4 Assembly time substitution of variables
Example
; straightforward substitution
GBLS add4ff
;
add4ff SETS "ADD r4,r4,#0xFF" ; set up add4ff
$add4ff.00 ; invoke add4ff
; this produces
ADD r4,r4,#0xFF00
; elaborate substitution
GBLS s1
GBLS s2
GBLS fixup
GBLA count
;
count SETA 14
s1 SETS "a$$b$count" ; s1 now has value a$b0000000E
s2 SETS "abc"
fixup SETS "|xy$s2.z|" ; fixup now has value |xyabcz|
|C$$code| MOV r4,#16 ; but the label here is C$$code
Related references
3.1 Syntax of source lines in assembly language on page 3-51.
7.1 Symbol naming rules on page 7-132.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-135
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.5 Register-relative and PC-relative expressions
If you specify a label, the assembler calculates the offset from the PC value of the current instruction to
the address of the label. The assembler encodes the offset in the instruction. If the offset is too large, the
assembler produces an error. The offset is either added to or subtracted from the PC value to form the
required address.
ARM recommends you write PC-relative expressions using labels rather than the PC because the value
of the PC depends on the instruction set.
Note
• In ARM code, the value of the PC is the address of the current instruction plus 8 bytes.
• In Thumb code:
— For B, BL, CBNZ, and CBZ instructions, the value of the PC is the address of the current instruction
plus 4 bytes.
— For all other instructions that use labels, the value of the PC is the address of the current
instruction plus 4 bytes, with bit[1] of the result cleared to 0 to make it word-aligned.
Example
LDR r4,=data+4*n ; n is an assembly-time variable
; code
MOV pc,lr
data DCD value_0
; n-1 DCD directives
DCD value_n ; data+4*n points here
; more DCD directives
Related concepts
7.6 Labels on page 7-137.
Related references
12.53 MAP on page 12-636.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-136
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.6 Labels
7.6 Labels
A label is a symbol that represents the memory address of an instruction or data.
The address can be PC-relative, register-relative, or absolute. Labels are local to the source file unless
you make them global using the EXPORT directive.
The address given by a label is calculated during assembly. armasm calculates the address of a label
relative to the origin of the section where the label is defined. A reference to a label within the same
section can use the PC plus or minus an offset. This is called PC-relative addressing.
Addresses of labels in other sections are calculated at link time, when the linker has allocated specific
locations in memory for each section.
Related concepts
7.7 Labels for PC-relative addresses on page 7-138.
7.8 Labels for register-relative addresses on page 7-139.
7.9 Labels for absolute addresses on page 7-140.
Related references
3.1 Syntax of source lines in assembly language on page 3-51.
12.28 EXPORT or GLOBAL on page 12-606.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-137
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.7 Labels for PC-relative addresses
Related references
12.6 AREA on page 12-582.
12.15 DCB on page 12-593.
12.16 DCD and DCDU on page 12-594.
12.18 DCFD and DCFDU on page 12-596.
12.19 DCFS and DCFSU on page 12-597.
12.20 DCI on page 12-598.
12.21 DCQ and DCQU on page 12-599.
12.22 DCW and DCWU on page 12-600.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-138
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.8 Labels for register-relative addresses
Related references
12.17 DCDO on page 12-595.
12.27 EQU on page 12-605.
12.53 MAP on page 12-636.
12.64 SPACE or FILL on page 12-648.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-139
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.9 Labels for absolute addresses
Related concepts
7.6 Labels on page 7-137.
7.7 Labels for PC-relative addresses on page 7-138.
7.8 Labels for register-relative addresses on page 7-139.
Related references
12.27 EQU on page 12-605.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-140
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.10 Numeric local labels
Related concepts
7.6 Labels on page 7-137.
Related references
3.1 Syntax of source lines in assembly language on page 3-51.
7.11 Syntax of numeric local labels on page 7-142.
12.52 MACRO and MEND on page 12-633.
12.49 KEEP on page 12-630.
12.62 ROUT on page 12-646.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-141
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.11 Syntax of numeric local labels
Syntax
n[routname] ; a numeric local label
where:
n
is the number of the numeric local label in the range 0-99.
routname
is the name of the current scope.
%
introduces the reference.
F
instructs armasm to search forwards only.
B
instructs armasm to search backwards only.
A
instructs armasm to search all macro levels.
T
instructs armasm to look at this macro level only.
Usage
If neither F nor B is specified, armasm searches backwards first, then forwards.
If neither A nor T is specified, armasm searches all macros from the current level to the top level, but does
not search lower level macros.
If routname is specified in either a label or a reference to a label, armasm checks it against the name of
the nearest preceding ROUT directive. If it does not match, armasm generates an error message and the
assembly fails.
Related concepts
7.10 Numeric local labels on page 7-141.
Related references
12.62 ROUT on page 12-646.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-142
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.12 String expressions
Example
improb SETS "literal":CC:(strvar2:LEFT:4)
; sets the variable improb to the value "literal"
; with the left-most four characters of the
; contents of string variable strvar2 appended
Related concepts
7.13 String literals on page 7-144.
7.19 Unary operators on page 7-150.
7.2 Variables on page 7-133.
Related references
7.22 String manipulation operators on page 7-153.
12.63 SETA, SETL, and SETS on page 12-647.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-143
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.13 String literals
Examples
abc SETS "this string contains only one "" double quote"
def SETS "this string contains only one $$ dollar symbol"
Related references
3.1 Syntax of source lines in assembly language on page 3-51.
9.50 --no_esc on page 9-247.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-144
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.14 Numeric expressions
Example
a SETA 256*256 ; 256*256 is a numeric expression
MOV r1,#(a*22) ; (a*22) is a numeric expression
Related concepts
7.20 Binary operators on page 7-151.
7.2 Variables on page 7-133.
7.3 Numeric constants on page 7-134.
Related references
7.15 Syntax of numeric literals on page 7-146.
12.63 SETA, SETL, and SETS on page 12-647.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-145
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.15 Syntax of numeric literals
Examples
a SETA 34906
addr DCD 0xA10E
LDR r4,=&1000000F
DCD 2_11001010
c3 SETA 8_74007
DCQ 0x0123456789abcdef
LDR r1,='A' ; pseudo-instruction loading 65 into r1
ADD r3,r2,#'\'' ; add 39 to contents of r2, result to r3
Related concepts
7.3 Numeric constants on page 7-134.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-146
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.16 Syntax of floating-point literals
where:
digits
Are sequences of characters using only the digits 0 to 9. You can write E in uppercase or
lowercase. These forms correspond to normal floating-point notation.
hexdigits
Are sequences of characters using only the digits 0 to 9 and the letters A to F or a to f. These
forms correspond to the internal representation of the numbers in the computer. Use these forms
to enter infinities and NaNs, or if you want to be sure of the exact bit patterns you are using.
The 0x and & forms allow the floating-point bit pattern to be specified by any number of hex digits.
The 0f_ form requires the floating-point bit pattern to be specified by exactly 8 hex digits.
The 0d_ form requires the floating-point bit pattern to be specified by exactly 16 hex digits.
The range for single-precision floating-point values is:
• Maximum 3.40282347e+38.
• Minimum 1.17549435e–38.
The range for double-precision floating-point values is:
• Maximum 1.79769313486231571e+308.
• Minimum 2.22507385850720138e–308.
Floating-point numbers are only available if your system has VFP.
Examples
DCFD 1E308,-4E-100
DCFS 1.0
DCFS 0.02
DCFD 3.725e15
DCFS 0x7FC00000 ; Quiet NaN
DCFD &FFF0000000000000 ; Minus infinity
Related concepts
7.3 Numeric constants on page 7-134.
Related references
7.15 Syntax of numeric literals on page 7-146.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-147
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.17 Logical expressions
Related references
7.26 Boolean operators on page 7-157.
7.25 Relational operators on page 7-156.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-148
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.18 Logical literals
Related concepts
7.13 String literals on page 7-144.
Related references
7.15 Syntax of numeric literals on page 7-146.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-149
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.19 Unary operators
:UPPERCASE: :UPPERCASE:string Returns the given string, with all lowercase characters converted to uppercase.
The following table lists the unary operators that return numeric values:
+ and - +A Unary plus. Unary minus. + and – can act on numeric and PC-relative expressions.
-A
:CC_ENCODING: :CC_ENCODING:cond_code Returns the numeric value of the condition code in cond_code, or an error if
cond_code does not contain a valid condition code.
:INDEX: :INDEX:A If A is a register-relative expression, :INDEX: returns the offset from that base
register. :INDEX: is most useful in macros.
Related concepts
7.20 Binary operators on page 7-151.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-150
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.20 Binary operators
Note
The order of precedence is not the same as in C.
Related concepts
7.28 Difference between operator precedence in assembly language and C on page 7-159.
Related references
7.21 Multiplicative operators on page 7-152.
7.22 String manipulation operators on page 7-153.
7.23 Shift operators on page 7-154.
7.24 Addition, subtraction, and logical operators on page 7-155.
7.25 Relational operators on page 7-156.
7.26 Boolean operators on page 7-157.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-151
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.21 Multiplicative operators
* A*B Multiply
/ A/B Divide
:MOD: % A:MOD:B A modulo B
You can use the :MOD: operator on PC-relative expressions to ensure code is aligned correctly. These
alignment checks have the form PC-relative:MOD:Constant. For example:
AREA x,CODE
ASSERT ({PC}:MOD:4) == 0
DCB 1
y DCB 2
ASSERT (y:MOD:4) == 1
ASSERT ({PC}:MOD:4) == 2
END
Related concepts
7.20 Binary operators on page 7-151.
7.5 Register-relative and PC-relative expressions on page 7-136.
7.14 Numeric expressions on page 7-145.
Related references
7.15 Syntax of numeric literals on page 7-146.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-152
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.22 String manipulation operators
Related concepts
7.12 String expressions on page 7-143.
7.14 Numeric expressions on page 7-145.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-153
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.23 Shift operators
Note
SHR is a logical shift and does not propagate the sign bit.
Related concepts
7.20 Binary operators on page 7-151.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-154
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.24 Addition, subtraction, and logical operators
+ A+B Add A to B
- A-B Subtract B from A
:AND: & A:AND:B Bitwise AND of A and B
Related concepts
7.20 Binary operators on page 7-151.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-155
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.25 Relational operators
= == A=B A equal to B
> A>B A greater than B
>= A>=B A greater than or equal to B
< A<B A less than B
<= A<=B A less than or equal to B
/= <> != A/=B A not equal to B
Related concepts
7.20 Binary operators on page 7-151.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-156
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.26 Boolean operators
Related concepts
7.20 Binary operators on page 7-151.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-157
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.27 Operator precedence
Related concepts
7.19 Unary operators on page 7-150.
7.20 Binary operators on page 7-151.
7.28 Difference between operator precedence in assembly language and C on page 7-159.
Related references
7.21 Multiplicative operators on page 7-152.
7.22 String manipulation operators on page 7-153.
7.23 Shift operators on page 7-154.
7.24 Addition, subtraction, and logical operators on page 7-155.
7.25 Relational operators on page 7-156.
7.26 Boolean operators on page 7-157.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-158
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.28 Difference between operator precedence in assembly language and C
* / :MOD: * / %
C precedence
unary operators
* / %
<< >>
== !=
&
&&
||
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-159
reserved.
Non-Confidential
7 Symbols, Literals, Expressions, and Operators
7.28 Difference between operator precedence in assembly language and C
Related concepts
7.20 Binary operators on page 7-151.
Related references
7.27 Operator precedence on page 7-158.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 7-160
reserved.
Non-Confidential
Chapter 8
VFP Programming
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-161
reserved.
Non-Confidential
8 VFP Programming
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-162
reserved.
Non-Confidential
8 VFP Programming
8.1 Architecture support for VFP
Related concepts
8.2 Half-precision extension for VFP on page 8-164.
8.3 Fused Multiply-Add extension for VFP on page 8-165.
8.16 VFP vector mode on page 8-179.
Related information
Floating-point support.
Further reading.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-163
reserved.
Non-Confidential
8 VFP Programming
8.2 Half-precision extension for VFP
Related concepts
8.1 Architecture support for VFP on page 8-163.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-164
reserved.
Non-Confidential
8 VFP Programming
8.3 Fused Multiply-Add extension for VFP
Related concepts
8.1 Architecture support for VFP on page 8-163.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-165
reserved.
Non-Confidential
8 VFP Programming
8.4 Extension register bank mapping in VFP
S0
D0
S1
S2
D1
S3
S4
D2
S5
S6
D3
S7
... ...
S28
D14
S29
S30
D15
S31
D16
D17
...
D30
D31
Note
The figure applies to a VFP implementation with 32 double precision registers. The following versions
of VFP use 16 double precision registers, D0-D15.
• VFPv2.
• VFPv3-D16.
• VFPv4-D16.
The aliased views enable half-precision, single-precision, and double-precision values to coexist in
different non-overlapped registers at the same time.
You can also use the same overlapped registers to store half-precision, single-precision, and double-
precision values at different times.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-166
reserved.
Non-Confidential
8 VFP Programming
8.4 Extension register bank mapping in VFP
Do not attempt to use overlapped 32-bit and 64-bit registers at the same time because it creates
meaningless results.
The mapping between the registers is as follows:
• S<2n> maps to the least significant half of D<n>.
• S<2n+1> maps to the most significant half of D<n>.
For example, you can access the least significant half of the elements of a vector in D6 by referring to
S12, and the most significant half of the elements by referring to S13.
Related concepts
8.5 VFP views of the extension register bank on page 8-168.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-167
reserved.
Non-Confidential
8 VFP Programming
8.5 VFP views of the extension register bank
Related concepts
8.4 Extension register bank mapping in VFP on page 8-166.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-168
reserved.
Non-Confidential
8 VFP Programming
8.6 Load values to VFP registers
Related references
11.14 VLDR pseudo-instruction on page 11-553.
11.17 VMOV (floating-point) on page 11-556.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-169
reserved.
Non-Confidential
8 VFP Programming
8.7 Conditional execution of VFP instructions
Related concepts
5.2 Conditional execution in ARM state on page 5-97.
5.3 Conditional execution in Thumb state on page 5-98.
Related references
5.6 Comparison of condition code meanings in integer and floating-point code on page 5-101.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-170
reserved.
Non-Confidential
8 VFP Programming
8.8 Floating-point exceptions in VFP
Related concepts
8.12 Flush-to-zero mode on page 8-175.
Related references
Chapter 11 VFP Instructions on page 11-537.
Related information
ARM Architecture Reference Manual.
Further reading.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-171
reserved.
Non-Confidential
8 VFP Programming
8.9 VFP data types
The data type of the second (or only) operand is specified in the instruction.
Note
• Most instructions have a restricted range of permitted data types. See the instruction pages for details.
However, the data type description is flexible:
— If only the data size is specified, you can specify a type (S, U, P or F).
— If no data type is specified, you can specify a data type.
• The F16 data type is only available on systems that implement the half-precision architecture
extension.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-172
reserved.
Non-Confidential
8 VFP Programming
8.10 Extended notation extension for VFP
Related concepts
8.9 VFP data types on page 8-172.
Related references
12.23 DN and SN on page 12-601.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-173
reserved.
Non-Confidential
8 VFP Programming
8.11 VFP system registers
Related concepts
4.19 The Read-Modify-Write operation on page 4-83.
Related information
ARM Architecture Reference Manual.
Further reading.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-174
reserved.
Non-Confidential
8 VFP Programming
8.12 Flush-to-zero mode
Related concepts
8.14 The effects of using flush-to-zero mode in VFP on page 8-177.
Related references
8.13 When to use flush-to-zero mode in VFP on page 8-176.
8.15 VFP operations not affected by flush-to-zero mode on page 8-178.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-175
reserved.
Non-Confidential
8 VFP Programming
8.13 When to use flush-to-zero mode in VFP
Related concepts
8.12 Flush-to-zero mode on page 8-175.
8.14 The effects of using flush-to-zero mode in VFP on page 8-177.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-176
reserved.
Non-Confidential
8 VFP Programming
8.14 The effects of using flush-to-zero mode in VFP
Related concepts
8.12 Flush-to-zero mode on page 8-175.
Related references
8.15 VFP operations not affected by flush-to-zero mode on page 8-178.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-177
reserved.
Non-Confidential
8 VFP Programming
8.15 VFP operations not affected by flush-to-zero mode
Related concepts
8.12 Flush-to-zero mode on page 8-175.
Related references
11.2 VABS (floating-point) on page 11-541.
11.24 VNEG (floating-point) on page 11-563.
11.12 VLDR (floating-point) on page 11-551.
11.32 VSTR (floating-point) on page 11-571.
11.11 VLDM (floating-point) on page 11-550.
11.31 VSTM (floating-point) on page 11-570.
11.18 VMOV (between one ARM register and single precision VFP) on page 11-557.
11.19 VMOV (between two ARM registers and one or two extension registers) on page 11-558.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-178
reserved.
Non-Confidential
8 VFP Programming
8.16 VFP vector mode
Related concepts
8.1 Architecture support for VFP on page 8-163.
8.17 Vectors in the VFP extension register bank on page 8-180.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-179
reserved.
Non-Confidential
8 VFP Programming
8.17 Vectors in the VFP extension register bank
... ...
A vector, in a VFP instruction, can use up to eight single-precision registers, or four double-precision
registers, from the same bank. The number of registers used by a vector is controlled by the LEN bits in
the FPSCR.
Note
The value of the LEN bits is not a sufficient condition to perform vector operations using VFP. Whether a
VFP operation is scalar, vector or mixed depends on which bank the specified operand and destination
registers are in.
A vector can start from any register and wraps around to the beginning of the bank. The first register
used by an operand vector is the register that is specified as the operand in the individual VFP
instructions. The first register used by the destination vector is the register that is specified as the
destination in the individual VFP instructions.
Related concepts
8.18 VFP vector wrap-around on page 8-182.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-180
reserved.
Non-Confidential
8 VFP Programming
8.17 Vectors in the VFP extension register bank
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-181
reserved.
Non-Confidential
8 VFP Programming
8.18 VFP vector wrap-around
Related concepts
8.17 Vectors in the VFP extension register bank on page 8-180.
8.20 Restriction on vector length on page 8-184.
8.19 VFP vector stride on page 8-183.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-182
reserved.
Non-Confidential
8 VFP Programming
8.19 VFP vector stride
Related concepts
8.17 Vectors in the VFP extension register bank on page 8-180.
8.18 VFP vector wrap-around on page 8-182.
8.20 Restriction on vector length on page 8-184.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-183
reserved.
Non-Confidential
8 VFP Programming
8.20 Restriction on vector length
Related concepts
8.17 Vectors in the VFP extension register bank on page 8-180.
8.18 VFP vector wrap-around on page 8-182.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-184
reserved.
Non-Confidential
8 VFP Programming
8.21 Control of scalar, vector, and mixed operations
where:
Op
is the VFP instruction.
Fd
is the destination register.
Fn
is an operand register.
Fm
is the only or second operand register.
the behavior of the operation is as follows:
• If Fd is in the first or fifth bank of registers then the operation is scalar.
• If Fm is in the first or fifth bank of registers, but Fd is not, then the operation is mixed.
• If neither Fd nor Fm are in the first or fifth bank of registers, the operation is vector.
In scalar operations, Op acts on the value in Fm, and the value in Fn if present. The result is placed in Fd.
In vector operations, Op acts on the values in the vector starting at Fm, together with the values in the
vector starting at Fn if present. The results are placed in the vector starting at Fd.
In mixed operations, with a single operand, Op acts on the single value in Fm and LEN copies of the result
are placed in the vector starting at Fd.
In mixed operations, with two operands, Op acts on the single value in Fm, together with the values in the
vector starting at Fn. The results are placed in the vector starting at Fd.
Related concepts
8.17 Vectors in the VFP extension register bank on page 8-180.
8.18 VFP vector wrap-around on page 8-182.
8.19 VFP vector stride on page 8-183.
8.20 Restriction on vector length on page 8-184.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-185
reserved.
Non-Confidential
8 VFP Programming
8.22 Overview of VFP directives and vector notation
Related concepts
8.23 Pre-UAL VFP syntax and mnemonics on page 8-187.
Related references
8.25 VFPASSERT SCALAR on page 8-190.
8.26 VFPASSERT VECTOR on page 8-191.
8.24 Vector notation on page 8-189.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-186
reserved.
Non-Confidential
8 VFP Programming
8.23 Pre-UAL VFP syntax and mnemonics
VABS FABS
VADD FADD
VDIV FDIV
VMLA FMAC
VMLS FNMAC
VMUL FMUL
VNEG FNEG
VNMLA FNMSC
VNMLS FMSC
VNMUL FNMUL
VSQRT FSQRT
VSUB FSUB
a The immediate in VMOV (immediate) is the floating-point number you want to load. The immediate in FCONST is the number encoded in the instruction to produce
the floating-point number you want to load.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-187
reserved.
Non-Confidential
8 VFP Programming
8.23 Pre-UAL VFP syntax and mnemonics
efgh
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-188
reserved.
Non-Confidential
8 VFP Programming
8.24 Vector notation
Related references
8.25 VFPASSERT SCALAR on page 8-190.
8.26 VFPASSERT VECTOR on page 8-191.
12.23 DN and SN on page 12-601.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-189
reserved.
Non-Confidential
8 VFP Programming
8.25 VFPASSERT SCALAR
Syntax
VFPASSERT SCALAR
Usage
Use the VFPASSERT SCALAR directive to mark the end of any block of code where the VFP mode is
VECTOR.
Place the VFPASSERT SCALAR directive immediately after the instruction where the change occurs. This is
usually an FMXR instruction, but might be a BL instruction.
If a function expects VFP to be in vector mode on exit, place a VFPASSERT SCALAR directive immediately
after the last instruction. Such a function would not be AAPCS compliant.
Note
This directive does not generate any code. It is only an assertion by the programmer. The assembler
produces error messages if any such assertions are inconsistent with each other, or with any vector
notation in VFP data processing instructions.
The assembler faults vector notation in VFP data processing instructions following a VFPASSERT SCALAR
directive, even if the vector length is 1.
Example
VFPASSERT SCALAR ; scalar mode
faddd d4, d4, d0 ; okay
fadds s4<3>, s8<3>, s0 ; ERROR, vectors in scalar mode
fabss s24<1>, s28<1> ; ERROR, vectors in scalar mode
; (even though length==1)
Related references
8.24 Vector notation on page 8-189.
8.26 VFPASSERT VECTOR on page 8-191.
Related information
Procedure Call Standard for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-190
reserved.
Non-Confidential
8 VFP Programming
8.26 VFPASSERT VECTOR
Syntax
VFPASSERT VECTOR{<{n{:s}}>}
where:
n
is the vector length, 1-8.
s
is the vector stride, 1-2.
Usage
Use the VFPASSERT VECTOR directive to mark the start of a block of instructions where the VFP mode is
VECTOR, and to mark changes in the length or stride of vectors.
Place the VFPASSERT VECTOR directive immediately after the instruction where the change occurs. This is
usually an FMXR instruction, but might be a BL instruction.
If a function expects VFP to be in vector mode on entry, place a VFPASSERT VECTOR directive
immediately before the first instruction. Such a function would not be AAPCS compliant.
Note
This directive does not generate any code. It is only an assertion by the programmer. The assembler
produces error messages if any such assertions are inconsistent with each other, or with any vector
notation in VFP data processing instructions.
Example
VMRS r10,FPSCR ; UAL mnemonic - could be FMRX instead.
BIC r10,r10,#0x00370000
ORR r10,r10,#0x00020000 ; set length = 3, stride = 1
VMSR FPSCR,r10
VFPASSERT VECTOR ; assert vector mode, unspecified length
; and stride
faddd d4, d4, d0 ; ERROR, scalars in vector mode
fadds s16<3>, s8<3>, s0 ; okay
fabss s24<1>, s28<1> ; wrong length, but not faulted
; (unspecified)
VMRS r10,FPSCR
BIC r10,r10,#0x00370000
ORR r10,r10,#0x00030000 ; set length = 4, stride = 1
VMSR FPSCR,r10
VFPASSERT VECTOR<4> ; assert vector mode, length 4, stride 1
fadds s24<4>, s8<4>, s0 ; okay
fabss s24<2>, s24<2> ; ERROR, wrong length
VMRS r10,FPSCR
BIC r10,r10,#0x00370000
ORR r10,r10,#0x00130000 ; set length = 4, stride = 2
VMSR FPSCR,r10
VFPASSERT VECTOR<4:2> ; assert vector mode, length 4, stride 2
fadds s8<4>, s16<4>, s0 ; ERROR, wrong stride because omitting
; stride causes a default stride of 1.
fabss s16<4:2>, s28<4:2> ; okay
fadds s8<>, s16<>, s2 ; okay (s8 and s16 both have
; length 4 and stride 2. s2 is scalar.)
Related references
8.24 Vector notation on page 8-189.
8.25 VFPASSERT SCALAR on page 8-190.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-191
reserved.
Non-Confidential
8 VFP Programming
8.26 VFPASSERT VECTOR
Related information
Procedure Call Standard for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 8-192
reserved.
Non-Confidential
Chapter 9
Assembler Command-line Options
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-193
reserved.
Non-Confidential
9 Assembler Command-line Options
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-194
reserved.
Non-Confidential
9 Assembler Command-line Options
9.1 --16
9.1 --16
Instructs the assembler to interpret instructions as Thumb instructions using the pre-UAL Thumb syntax.
This option is equivalent to a CODE16 directive at the head of the source file. Use the --thumb option to
specify Thumb instructions using the UAL syntax.
Related references
9.63 --thumb on page 9-260.
12.11 CODE16 on page 12-589.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-195
reserved.
Non-Confidential
9 Assembler Command-line Options
9.2 --32
9.2 --32
A synonym for the --arm command-line option.
Related references
9.4 --arm on page 9-199.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-196
reserved.
Non-Confidential
9 Assembler Command-line Options
9.3 --apcs=qualifier…qualifier
9.3 --apcs=qualifier…qualifier
Controls interworking and position independence when generating code.
Syntax
--apcs=qualifier...qualifier
Where qualifier...qualifier denotes a list of qualifiers. There must be:
• At least one qualifier present.
• No spaces or commas separating individual qualifiers in the list.
Each instance of qualifier must be one of:
none
Specifies that the input file does not use AAPCS. AAPCS registers are not set up. Other
qualifiers are not permitted if you use none.
/interwork, /nointerwork
/interwork specifies that the code in the input file can interwork between ARM and Thumb
safely. The default is /nointerwork.
/inter, /nointer
Are synonyms for /interwork and /nointerwork.
/ropi, /noropi
/ropi specifies that the code in the input file is Read-Only Position-Independent (ROPI). The
default is /noropi.
/pic, /nopic
Are synonyms for /ropi and /noropi.
/rwpi, /norwpi
/rwpi specifies that the code in the input file is Read-Write Position-Independent (RWPI). The
default is /norwpi.
/pid, /nopid
Are synonyms for /rwpi and /norwpi.
/fpic, /nofpic
/fpic specifies that the code in the input file is read-only independent and references to
addresses are suitable for use in a Linux shared object. The default is /nofpic.
/hardfp, /softfp
Requests hardware or software floating-point linkage. This enables the procedure call standard
to be specified separately from the version of the floating-point hardware available through the
--fpu option. It is still possible to specify the procedure call standard by using the --fpu option,
but ARM recommends you use --apcs. If floating-point support is not permitted (for example,
because --fpu=none is specified, or because of other means), then /hardfp and /softfp are
ignored. If floating-point support is permitted and the softfp calling convention is used
(--fpu=softvfp or --fpu=softvfp+vfp...), then /hardfp gives an error.
Usage
This option specifies whether you are using the Procedure Call Standard for the ARM Architecture
(AAPCS). It can also specify some attributes of code sections.
The AAPCS forms part of the Base Standard Application Binary Interface for the ARM Architecture
(BSABI) specification. By writing code that adheres to the AAPCS, you can ensure that separately
compiled and assembled modules can work together.
Note
AAPCS qualifiers do not affect the code produced by armasm. They are an assertion by the programmer
that the code in the input file complies with a particular variant of AAPCS. They cause attributes to be
set in the object file produced by armasm. The linker uses these attributes to check compatibility of files,
and to select appropriate library variants.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-197
reserved.
Non-Confidential
9 Assembler Command-line Options
9.3 --apcs=qualifier…qualifier
Example
armasm --apcs=/inter/ropi inputfile.s
Related information
--apcs=qualifier...qualifier compiler option.
Procedure Call Standard for the ARM Architecture.
Application Binary Interface (ABI) for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-198
reserved.
Non-Confidential
9 Assembler Command-line Options
9.4 --arm
9.4 --arm
Targets the ARM instruction set. The assembler is permitted to generate both ARM and Thumb code, but
recognizes that ARM code is preferred.
This option instructs the assembler to interpret instructions as ARM instructions. It does not, however,
guarantee ARM-only code in the object file. This is the default. Using this option is equivalent to
specifying the ARM or CODE32 directive at the start of the source file.
Related references
9.5 --arm_only on page 9-200.
12.7 ARM or CODE32 on page 12-585.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-199
reserved.
Non-Confidential
9 Assembler Command-line Options
9.5 --arm_only
9.5 --arm_only
Enforces ARM-only code. The assembler behaves as if Thumb is absent from the target architecture.
This option instructs the assembler to only generate ARM code. This is similar to --arm but also has the
property that the assembler does not permit the generation of any Thumb code.
Related references
9.4 --arm on page 9-199.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-200
reserved.
Non-Confidential
9 Assembler Command-line Options
9.6 --bi
9.6 --bi
A synonym for the --bigend command-line option.
Related references
9.7 --bigend on page 9-202.
9.45 --littleend on page 9-242.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-201
reserved.
Non-Confidential
9 Assembler Command-line Options
9.7 --bigend
9.7 --bigend
Generates code suitable for an ARM processor using big-endian memory access.
The default is --littleend.
Related references
9.45 --littleend on page 9-242.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-202
reserved.
Non-Confidential
9 Assembler Command-line Options
9.8 --brief_diagnostics, --no_brief_diagnostics
Related references
9.18 --diag_error=tag[,tag,…] on page 9-214.
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-203
reserved.
Non-Confidential
9 Assembler Command-line Options
9.9 --checkreglist
9.9 --checkreglist
Instructs the armasm to check RLIST, LDM, and STM register lists to ensure that all registers are provided in
increasing register number order.
When this option is used, armasm gives a warning if the registers are not listed in order.
Note
This option is deprecated. Use --diag_warning 1206 instead.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-204
reserved.
Non-Confidential
9 Assembler Command-line Options
9.10 --compatible=name
9.10 --compatible=name
Generates code that is compatible with multiple target processors.
Syntax
--compatible=name
Where:
name
is the name of a target processor or None.
Processor names are not case-sensitive.
Specifying None generates code only for the processor specified by --cpu.
If multiple instances of this option are present on the command line, the last one specified
overrides the previous instances. Specify --compatible=None at the end of the command line to
turn off all other instances of the option.
Default
The default is None.
Usage
Using this option avoids having to reassemble the same source code for different targets.
See the following table. The valid combinations are:
• --cpu=CPU_from_group1 --compatible=CPU_from_group2.
• --cpu=CPU_from_group2 --compatible=CPU_from_group1.
Group 1 ARM7TDMI
Group 2 Cortex-M0, Cortex-M1, Cortex-M3, Cortex-M4, 7-M, 6-M, 6S-M, SC300, SC000
Example
To generate code that is compatible with both the ARM7TDMI processor and the Cortex-M4 processor,
specify:
armasm --cpu=arm7tdmi --compatible=cortex-m4 inputfile.s
Related references
9.14 --cpu=name on page 9-209.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-205
reserved.
Non-Confidential
9 Assembler Command-line Options
9.11 --cpreproc
9.11 --cpreproc
Instructs the assembler to call armcc to preprocess the input file before assembling it.
Related concepts
6.15 Using the C preprocessor on page 6-126.
Related references
9.12 --cpreproc_opts=option[,option,…] on page 9-207.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-206
reserved.
Non-Confidential
9 Assembler Command-line Options
9.12 --cpreproc_opts=option[,option,…]
9.12 --cpreproc_opts=option[,option,…]
Enables the assembler to pass options to the compiler when using the C preprocessor.
Syntax
--cpreproc_opts=option[,option,…]
Example
armasm --cpreproc --cpreproc_opts=-DDEBUG=1,-UALPHA inputfile.s
Related concepts
6.15 Using the C preprocessor on page 6-126.
Related references
9.11 --cpreproc on page 9-206.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-207
reserved.
Non-Confidential
9 Assembler Command-line Options
9.13 --cpu=list
9.13 --cpu=list
Lists the architecture and processor names that are supported by the --cpu=name option.
Syntax
--cpu=list
Related references
9.14 --cpu=name on page 9-209.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-208
reserved.
Non-Confidential
9 Assembler Command-line Options
9.14 --cpu=name
9.14 --cpu=name
Enables code generation for the selected ARM processor
Syntax
--cpu=name
Where name is the name of a processor. Enter name as shown on ARM data sheets, for example, Cortex-
M3.
Default
armasm assumes --cpu=ARM7TDMI if you do not specify a --cpu option.
Usage
The following general points apply to processor options:
Processors
• Selecting the processor selects the appropriate architecture, Floating-Point Unit (FPU), and
memory organization.
• If you specify a processor for the --cpu option, the generated code is optimized for that
processor. This enables the assembler to use specific coprocessors or instruction scheduling
for optimum performance.
FPU
• Some specifications of --cpu imply an --fpu selection.
For example, when building with the --arm option, --cpu=Cortex-R4F implies
--fpu=vfpv3_d16.
Note
Any explicit FPU, set with --fpu on the command line, overrides an implicit FPU.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-209
reserved.
Non-Confidential
9 Assembler Command-line Options
9.14 --cpu=name
ARM/Thumb
• Specifying a processor or architecture that supports Thumb instructions, such as
--cpu=ARM7TDMI, does not make the assembler generate Thumb code. It only enables
features of the processor to be used, such as long multiply. Use the --thumb option to
generate Thumb code, unless the processor is a Thumb-only processor, for example Cortex-
M4. In this case, --thumb is not required.
Note
Specifying the target processor or architecture might make the generated object code
incompatible with other ARM processors. For example, code generated for architecture
ARMv6 might not run on an ARM920T processor, if the generated object code includes
instructions specific to ARMv6. Therefore, you must choose the lowest common
denominator processor suited to your purpose.
• If you are building for mixed ARM/Thumb systems for processors that support ARMv4T or
ARMv5T, then you must specify the interworking option --apcs=/interwork. By default,
this is enabled for processors that support ARMv5T or above.
• If you build for Thumb, that is with the --thumb option on the command line, the assembler
generates as much of the code as possible using the Thumb instruction set. However, the
assembler might generate ARM code for some parts of the compilation. For example, if you
are generating code for a 16-bit Thumb processor and using VFP, any function containing
floating-point operations is compiled for ARM.
Restrictions
You cannot specify both a processor and an architecture on the same command-line.
Example
armasm --cpu=Cortex-A17 inputfile.s
Related references
9.3 --apcs=qualifier…qualifier on page 9-197.
9.10 --compatible=name on page 9-205.
9.13 --cpu=list on page 9-208.
9.33 --fpu=name on page 9-229.
9.63 --thumb on page 9-260.
9.66 --unsafe on page 9-263.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-210
reserved.
Non-Confidential
9 Assembler Command-line Options
9.15 --debug
9.15 --debug
Instructs the assembler to generate DWARF debug tables.
--debug is a synonym for -g. The default is DWARF 3.
Note
Local symbols are not preserved with --debug. You must specify --keep if you want to preserve the
local symbols to aid debugging.
Related references
9.24 --dwarf2 on page 9-220.
9.25 --dwarf3 on page 9-221.
9.37 --keep on page 9-234.
9.34 -g on page 9-231.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-211
reserved.
Non-Confidential
9 Assembler Command-line Options
9.16 --depend=dependfile
9.16 --depend=dependfile
Writes makefile dependency lines to a file.
Source file dependency lists are suitable for use with make utilities.
Related references
9.48 --md on page 9-245.
9.17 --depend_format=string on page 9-213.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-212
reserved.
Non-Confidential
9 Assembler Command-line Options
9.17 --depend_format=string
9.17 --depend_format=string
Specifies the format of output dependency files, for compatibility with some UNIX make programs.
Syntax
--depend_format=string
Related references
9.16 --depend=dependfile on page 9-212.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-213
reserved.
Non-Confidential
9 Assembler Command-line Options
9.18 --diag_error=tag[,tag,…]
9.18 --diag_error=tag[,tag,…]
Sets diagnostic messages that have a specific tag to Error severity.
Syntax
--diag_error=tag[,tag,…]
Where tag can be:
• A diagnostic message number to set to error severity. This is the four-digit number, nnnn, with the
tool letter prefix, but without the letter suffix indicating the severity.
• warning, to treat all warnings as errors.
Usage
Diagnostic messages output by the assembler can be identified by a tag in the form of {prefix}number,
where the prefix is A.
You can specify more than one tag with this option by separating each tag using a comma. You can
specify the optional assembler prefix A before the tag number. If any prefix other than A is included, the
message number is ignored.
The following table shows the meaning of the term severity used in the option descriptions:
Severity Description
Error Errors indicate violations in the syntactic or semantic rules of assembly language. Assembly continues, but object code is
not generated.
Warning Warnings indicate unusual conditions in your code that might indicate a problem. Assembly continues, and object code is
generated unless any problems with an Error severity are detected.
Remark Remarks indicate common, but not recommended, use of assembly language. These diagnostics are not issued by default.
Assembly continues, and object code is generated unless any problems with an Error severity are detected.
Related references
9.8 --brief_diagnostics, --no_brief_diagnostics on page 9-203.
9.19 --diag_remark=tag[,tag,…] on page 9-215.
9.21 --diag_suppress=tag[,tag,…] on page 9-217.
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-214
reserved.
Non-Confidential
9 Assembler Command-line Options
9.19 --diag_remark=tag[,tag,…]
9.19 --diag_remark=tag[,tag,…]
Sets diagnostic messages that have a specific tag to Remark severity.
Syntax
--diag_remark=tag[,tag,…]
Where tag is a comma-separated list of diagnostic message numbers. This is the four-digit number,
nnnn, with the tool letter prefix, but without the letter suffix indicating the severity.
Usage
Diagnostic messages output by the assembler can be identified by a tag in the form of {prefix}number,
where the prefix is A.
You can specify more than one tag with this option by separating each tag using a comma. You can
specify the optional assembler prefix A before the tag number. If any prefix other than A is included, the
message number is ignored.
Related references
9.8 --brief_diagnostics, --no_brief_diagnostics on page 9-203.
9.18 --diag_error=tag[,tag,…] on page 9-214.
9.21 --diag_suppress=tag[,tag,…] on page 9-217.
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-215
reserved.
Non-Confidential
9 Assembler Command-line Options
9.20 --diag_style={arm|ide|gnu}
9.20 --diag_style={arm|ide|gnu}
Specifies the display style for diagnostic messages.
Syntax
--diag_style=string
Usage
--diag_style=ide matches the format reported by Microsoft Visual Studio.
Choosing the option --diag_style=ide implicitly selects the option --brief_diagnostics. Explicitly
selecting --no_brief_diagnostics on the command line overrides the selection of
--brief_diagnostics implied by --diag_style=ide.
Default
The default is --diag_style=arm.
Related references
9.8 --brief_diagnostics, --no_brief_diagnostics on page 9-203.
9.18 --diag_error=tag[,tag,…] on page 9-214.
9.19 --diag_remark=tag[,tag,…] on page 9-215.
9.21 --diag_suppress=tag[,tag,…] on page 9-217.
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-216
reserved.
Non-Confidential
9 Assembler Command-line Options
9.21 --diag_suppress=tag[,tag,…]
9.21 --diag_suppress=tag[,tag,…]
Suppresses diagnostic messages that have a specific tag.
Syntax
--diag_suppress=tag[,tag,…]
Where tag can be:
• A diagnostic message number to be suppressed. This is the four-digit number, nnnn, with the tool
letter prefix, but without the letter suffix indicating the severity.
• error, to suppress all errors that can be downgraded.
• warning, to suppress all warnings.
Diagnostic messages output by armasm can be identified by a tag in the form of {prefix}number, where
the prefix is A.
You can specify more than one tag with this option by separating each tag using a comma.
Example
For example, to suppress the warning messages that have numbers 1293 and 187, use the following
command:
armasm --diag_suppress=1293,187
You can specify the optional assembler prefix A before the tag number. For example:
armasm --diag_suppress=A1293,A187
If any prefix other than A is included, the message number is ignored. Diagnostic message tags can be
cut and pasted directly into a command line.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-217
reserved.
Non-Confidential
9 Assembler Command-line Options
9.22 --diag_warning=tag[,tag,…]
9.22 --diag_warning=tag[,tag,…]
Sets diagnostic messages that have a specific tag to Warning severity.
Syntax
--diag_warning=tag[,tag,…]
Where tag can be:
• A diagnostic message number to set to warning severity. This is the four-digit number, nnnn, with the
tool letter prefix, but without the letter suffix indicating the severity.
• error, to set all errors that can be downgraded to warnings.
Diagnostic messages output by the assembler can be identified by a tag in the form of {prefix}number,
where the prefix is A.
You can specify more than one tag with this option by separating each tag using a comma.
You can specify the optional assembler prefix A before the tag number. If any prefix other than A is
included, the message number is ignored.
Related references
9.8 --brief_diagnostics, --no_brief_diagnostics on page 9-203.
9.18 --diag_error=tag[,tag,…] on page 9-214.
9.19 --diag_remark=tag[,tag,…] on page 9-215.
9.21 --diag_suppress=tag[,tag,…] on page 9-217.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-218
reserved.
Non-Confidential
9 Assembler Command-line Options
9.23 --dllexport_all
9.23 --dllexport_all
Controls symbol visibility when building DLLs.
This option gives all exported global symbols STV_PROTECTED visibility in ELF rather than STV_HIDDEN,
unless overridden by source directives.
Related references
12.28 EXPORT or GLOBAL on page 12-606.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-219
reserved.
Non-Confidential
9 Assembler Command-line Options
9.24 --dwarf2
9.24 --dwarf2
Uses DWARF 2 debug table format.
This option can be used with --debug, to instruct armasm to generate DWARF 2 debug tables.
Related references
9.15 --debug on page 9-211.
9.25 --dwarf3 on page 9-221.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-220
reserved.
Non-Confidential
9 Assembler Command-line Options
9.25 --dwarf3
9.25 --dwarf3
Uses DWARF 3 debug table format.
This option can be used with --debug, to instruct the assembler to generate DWARF 3 debug tables. This
is the default if --debug is specified.
Related references
9.15 --debug on page 9-211.
9.24 --dwarf2 on page 9-220.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-221
reserved.
Non-Confidential
9 Assembler Command-line Options
9.26 --errors=errorfile
9.26 --errors=errorfile
Redirects the output of diagnostic messages from stderr to the specified errors file.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-222
reserved.
Non-Confidential
9 Assembler Command-line Options
9.27 --execstack, --no_execstack
In the absence of --execstack and --no_execstack, the .note.GNU-stack section is not generated
unless it is specified by the AREA directive.
If both the command-line option and source directive are used and are different, then the stack is marked
as executable.
Table 9-3 Specifying a command-line option and an AREA directive for GNU-stack sections
Related references
12.6 AREA on page 12-582.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-223
reserved.
Non-Confidential
9 Assembler Command-line Options
9.28 --execute_only
9.28 --execute_only
Adds the EXECONLY AREA attribute to all code sections.
Usage
The EXECONLY AREA attribute causes the linker to treat the section as execute-only.
It is the user's responsibility to ensure that the code in the section is safe to run in execute-only memory.
For example:
• The code must not contain literal pools.
• The code must not attempt to load data from the same, or another, execute-only section.
Restrictions
This option is only supported for:
• Processors that support the ARMv7-M architecture, such as Cortex-M3, Cortex-M4, and Cortex-M7.
• Processors that support the ARMv6-M architecture.
Note
ARM has only performed limited testing of execute-only code on ARMv6-M targets.
Related references
12.6 AREA on page 12-582.
Related information
Execute-only memory.
Building applications for execute-only memory.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-224
reserved.
Non-Confidential
9 Assembler Command-line Options
9.29 --exceptions, --no_exceptions
Related references
9.30 --exceptions_unwind, --no_exceptions_unwind on page 9-226.
12.40 FRAME UNWIND ON on page 12-619.
12.41 FRAME UNWIND OFF on page 12-620.
12.42 FUNCTION or PROC on page 12-621.
12.25 ENDFUNC or ENDP on page 12-603.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-225
reserved.
Non-Confidential
9 Assembler Command-line Options
9.30 --exceptions_unwind, --no_exceptions_unwind
Related references
9.29 --exceptions, --no_exceptions on page 9-225.
12.40 FRAME UNWIND ON on page 12-619.
12.41 FRAME UNWIND OFF on page 12-620.
12.42 FUNCTION or PROC on page 12-621.
12.25 ENDFUNC or ENDP on page 12-603.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-226
reserved.
Non-Confidential
9 Assembler Command-line Options
9.31 --fpmode=model
9.31 --fpmode=model
Specifies floating-point standard conformance and sets library attributes and floating-point
optimizations.
Syntax
--fpmode=model
Note
This does not cause any changes to the code that you write.
Example
armasm --fpmode ieee_full inputfile.s
Related references
9.33 --fpu=name on page 9-229.
Related information
IEEE Standards Association.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-227
reserved.
Non-Confidential
9 Assembler Command-line Options
9.32 --fpu=list
9.32 --fpu=list
Lists the FPU architecture names that are supported by the --fpu=name option.
Example
armasm --fpu=list
Related references
9.31 --fpmode=model on page 9-227.
9.33 --fpu=name on page 9-229.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-228
reserved.
Non-Confidential
9 Assembler Command-line Options
9.33 --fpu=name
9.33 --fpu=name
Specifies the target FPU architecture.
Syntax
--fpu=name
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-229
reserved.
Non-Confidential
9 Assembler Command-line Options
9.33 --fpu=name
softvfp+vfpv3_d16_fp16
Selects a hardware vector floating-point unit conforming to VFPv3-D16-fp16, with software
floating-point linkage.
softvfp+vfpv4
Selects a hardware floating-point unit conforming to FPv4, with software floating-point linkage.
softvfp+vfpv4_d16
Selects a hardware floating-point unit conforming to VFPv4-D16, with software floating-point
linkage.
softvfp+fpv4-sp
Selects a hardware floating-point unit conforming to FPv4-SP, with software floating-point
linkage.
softvfp+fpv5_d16
Selects a hardware floating-point unit conforming to FPv5-D16, with software floating-point
linkage.
softvfp+fpv5-sp
Selects a hardware floating-point unit conforming to FPv5-SP, with software floating-point
linkage.
To obtain a full list of FPU architectures use the --fpu=list option.
Usage
If you specify this option, it overrides any implicit FPU option that appears on the command line, for
example, where you use the --cpu option.
Any FPU explicitly selected using the --fpu option always overrides any FPU implicitly selected using
the --cpu option. For example, the option --cpu=ARM1136JF-S --fpu=softvfp generates code that
uses the software floating-point library fplib, even though the choice of CPU implies the use of
architecture VFPv2.
armasm sets a build attribute corresponding to name in the object file. The linker determines
compatibility between object files, and selection of libraries, accordingly.
To control floating-point linkage without affecting the choice of FPU, you can use --apcs=/softfp or
--apcs=/hardfp.
Restrictions
armasm only permits hardware VFP architectures, such as --fpu=vfpv3 or --fpu=softvfp+vfpv2, to be
specified when MRRC and MCRR instructions are supported in the processor instruction set. MRRC and MCRR
instructions are not supported in 4, 4T, 5T and 6-M. Therefore, armasm does not allow the use of these
CPU architectures with hardware VFP architectures.
Other than this, armasm does not check that --cpu and --fpu combinations are valid. Beyond the scope
of the assembler, additional architectural constraints apply. For example, VFPv3 is not supported with
architectures prior to ARMv7. Therefore, the combination of --fpu and --cpu options permitted by
armasm does not necessarily translate to the actual device in use.
Default
The default target FPU architecture is derived from use of the --cpu option.
If the CPU specified with --cpu has a VFP coprocessor, the default target FPU architecture is the VFP
architecture for that CPU. For example, the option --cpu ARM1136JF-S implies the option --fpu vfpv2.
If a VFP coprocessor is present, VFP instructions are generated.
Related references
9.31 --fpmode=model on page 9-227.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-230
reserved.
Non-Confidential
9 Assembler Command-line Options
9.34 -g
9.34 -g
Enables the generation of debug tables.
This option is a synonym for --debug.
Related references
9.15 --debug on page 9-211.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-231
reserved.
Non-Confidential
9 Assembler Command-line Options
9.35 --help
9.35 --help
Displays a summary of the main command-line options.
Default
This is the default if you specify armasm without any options or source files.
Related references
9.68 --version_number on page 9-265.
9.70 --vsn on page 9-267.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-232
reserved.
Non-Confidential
9 Assembler Command-line Options
9.36 -idir[,dir, …]
9.36 -idir[,dir, …]
Adds directories to the source file include path.
Any directories added using this option have to be fully qualified.
Related references
12.44 GET or INCLUDE on page 12-623.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-233
reserved.
Non-Confidential
9 Assembler Command-line Options
9.37 --keep
9.37 --keep
Instructs the assembler to keep named local labels in the symbol table of the object file, for use by the
debugger.
Related references
12.49 KEEP on page 12-630.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-234
reserved.
Non-Confidential
9 Assembler Command-line Options
9.38 --length=n
9.38 --length=n
Sets the listing page length.
Length zero means an unpaged listing. The default is 66 lines.
Related references
9.43 --list=file on page 9-240.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-235
reserved.
Non-Confidential
9 Assembler Command-line Options
9.39 --li
9.39 --li
A synonym for the --littleend command-line option.
Related references
9.45 --littleend on page 9-242.
9.7 --bigend on page 9-202.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-236
reserved.
Non-Confidential
9 Assembler Command-line Options
9.40 --library_type=lib
9.40 --library_type=lib
Enables the selected library to be used at link time.
Syntax
--library_type=lib
Note
• This option can be used with the compiler, assembler, or linker when use of the libraries require more
specialized optimizations.
• This option can be overridden at link time by providing it to the linker.
Related information
Building an application with microlib.
--library_type=lib compiler option.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-237
reserved.
Non-Confidential
9 Assembler Command-line Options
9.41 --liclinger=seconds
9.41 --liclinger=seconds
The time in seconds that a license is to remain checked out.
Syntax
--liclinger=seconds
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-238
reserved.
Non-Confidential
9 Assembler Command-line Options
9.42 --licretry
9.42 --licretry
If you are using floating licenses, armasm makes up to 10 attempts to obtain a license when invoked.
Note
This option is always enabled. armasm ignores this option if you specify it.
Related information
Toolchain environment variables.
ARM DS-5 License Management Guide.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-239
reserved.
Non-Confidential
9 Assembler Command-line Options
9.43 --list=file
9.43 --list=file
Instructs the assembler to output a detailed listing of the assembly language produced by the assembler to
a file.
If - is given as file, the listing is sent to stdout.
Use the following command-line options to control the behavior of --list:
• --no_terse.
• --width.
• --length.
• --xref.
Related references
9.53 --no_terse on page 9-250.
9.71 --width=n on page 9-268.
9.38 --length=n on page 9-235.
9.72 --xref on page 9-269.
12.56 OPT on page 12-639.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-240
reserved.
Non-Confidential
9 Assembler Command-line Options
9.44 --list=
9.44 --list=
Instructs the assembler to send the detailed assembly language listing to inputfile.lst.
Note
You can use --list without the equals sign and filename to send the output to inputfile.lst.
However, this syntax is deprecated and the assembler issues a warning. This syntax is to be removed in a
later release. Use --list= instead.
Related references
9.43 --list=file on page 9-240.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-241
reserved.
Non-Confidential
9 Assembler Command-line Options
9.45 --littleend
9.45 --littleend
Generates code suitable for an ARM processor using little-endian memory access.
Related references
9.7 --bigend on page 9-202.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-242
reserved.
Non-Confidential
9 Assembler Command-line Options
9.46 -m
9.46 -m
Instructs the assembler to write source file dependency lists to stdout.
Related references
9.48 --md on page 9-245.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-243
reserved.
Non-Confidential
9 Assembler Command-line Options
9.47 --maxcache=n
9.47 --maxcache=n
Sets the maximum source cache size in bytes.
The default is 8MB. armasm gives a warning if the size is less than 8MB.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-244
reserved.
Non-Confidential
9 Assembler Command-line Options
9.48 --md
9.48 --md
Creates makefile dependency lists.
This option instructs the assembler to write source file dependency lists to inputfile.d.
Related references
9.46 -m on page 9-243.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-245
reserved.
Non-Confidential
9 Assembler Command-line Options
9.49 --no_code_gen
9.49 --no_code_gen
Instructs the assembler to exit after pass 1, generating no object file. This option is useful if you only
want to check the syntax of the source code or directives.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-246
reserved.
Non-Confidential
9 Assembler Command-line Options
9.50 --no_esc
9.50 --no_esc
Instructs the assembler to ignore C-style escaped special characters, such as \n and \t.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-247
reserved.
Non-Confidential
9 Assembler Command-line Options
9.51 --no_hide_all
9.51 --no_hide_all
Gives all exported and imported global symbols STV_DEFAULT visibility in ELF rather than STV_HIDDEN,
unless overridden using source directives.
You can use the following directives to specify an attribute that overrides the implicit symbol visibility:
• EXPORT.
• EXTERN.
• GLOBAL.
• IMPORT.
Related references
12.28 EXPORT or GLOBAL on page 12-606.
12.46 IMPORT and EXTERN on page 12-626.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-248
reserved.
Non-Confidential
9 Assembler Command-line Options
9.52 --no_regs
9.52 --no_regs
Instructs armasm not to predefine register names.
Note
This option is deprecated. Use --regnames=none instead.
Related references
9.59 --regnames on page 9-256.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-249
reserved.
Non-Confidential
9 Assembler Command-line Options
9.53 --no_terse
9.53 --no_terse
Instructs the assembler to show in the list file the lines of assembly code that it has skipped because of
conditional assembly.
If you do not specify this option, the assembler does not output the skipped assembly code to the list file.
This option turns off the terse flag. By default the terse flag is on.
Related references
9.43 --list=file on page 9-240.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-250
reserved.
Non-Confidential
9 Assembler Command-line Options
9.54 --no_warn
9.54 --no_warn
Turns off warning messages.
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-251
reserved.
Non-Confidential
9 Assembler Command-line Options
9.55 -o filename
9.55 -o filename
Specifies the name of the output file.
If this option is not used, the assembler creates an object filename in the form inputfilename.o. This
option is case-sensitive.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-252
reserved.
Non-Confidential
9 Assembler Command-line Options
9.56 --pd
9.56 --pd
A synonym for the --predefine command-line option.
Related references
9.57 --predefine "directive" on page 9-254.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-253
reserved.
Non-Confidential
9 Assembler Command-line Options
9.57 --predefine "directive"
armasm also executes a corresponding GBLL, GBLS, or GBLA directive to define the variable before setting
its value.
The variable name is case-sensitive. The variables defined using the command line are global to armasm
source files specified on the command line.
Related concepts
6.14 Conditional assembly on page 6-125.
Related references
9.56 --pd on page 9-253.
12.43 GBLA, GBLL, and GBLS on page 12-622.
12.45 IF, ELSE, ENDIF, and ELIF on page 12-624.
12.63 SETA, SETL, and SETS on page 12-647.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-254
reserved.
Non-Confidential
9 Assembler Command-line Options
9.58 --reduce_paths, --no_reduce_paths
Note
This option is valid for 32-bit Windows systems only.
Related information
--reduce_paths, --no_reduce_paths compiler option.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-255
reserved.
Non-Confidential
9 Assembler Command-line Options
9.59 --regnames
9.59 --regnames
Controls the predefinition of register names.
Syntax
--regnames=option
Related references
9.52 --no_regs on page 9-249.
9.3 --apcs=qualifier…qualifier on page 9-197.
2.10 Predeclared core register names on page 2-40.
2.11 Predeclared extension register names on page 2-41.
2.12 Predeclared coprocessor names on page 2-42.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-256
reserved.
Non-Confidential
9 Assembler Command-line Options
9.60 --report-if-not-wysiwyg
9.60 --report-if-not-wysiwyg
Instructs armasm to report when it outputs an encoding that was not directly requested in the source code.
This can happen when armasm:
• Uses a pseudo-instruction that is not available in other assemblers, for example MOV32.
• Outputs an encoding that does not directly match the instruction mnemonic, for example if the
assembler outputs the MVN encoding when assembling the MOV instruction.
• Inserts additional instructions where necessary for instruction syntax semantics, for example armasm
can insert a missing IT instruction before a conditional Thumb instruction.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-257
reserved.
Non-Confidential
9 Assembler Command-line Options
9.61 --show_cmdline
9.61 --show_cmdline
Outputs the command line used by the assembler.
Usage
Shows the command line after processing by the assembler, and can be useful to check:
• The command line a build system is using.
• How the assembler is interpreting the supplied command line, for example, the ordering of
command-line options.
The commands are shown normalized, and the contents of any via files are expanded.
The output is sent to the standard error stream (stderr).
Related references
9.69 --via=filename on page 9-266.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-258
reserved.
Non-Confidential
9 Assembler Command-line Options
9.62 --split_ldm
9.62 --split_ldm
Instructs the assembler to fault LDM and STM instructions with a large number of registers.
Note
This option is deprecated.
This option faults LDM instructions if the maximum number of registers transferred exceeds:
• Five, for LDMs that do not load the PC.
• Four, for LDMs that load the PC.
This option faults STM instructions if the maximum number of registers transferred exceeds 5.
Avoiding large multiple register transfers can reduce interrupt latency on ARM systems that:
• Do not have a cache or a write buffer (for example, a cacheless ARM7TDMI).
• Use zero wait-state, 32-bit memory.
Also, avoiding large multiple register transfers:
• Always increases code size.
• Has no significant benefit for cached systems or processors with a write buffer.
• Has no benefit for systems without zero wait-state memory, or for systems with slow peripheral
devices. Interrupt latency in such systems is determined by the number of cycles required for the
slowest memory or peripheral access. This is typically much greater than the latency introduced by
multiple register transfers.
Related references
10.41 LDM on page 10-342.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-259
reserved.
Non-Confidential
9 Assembler Command-line Options
9.63 --thumb
9.63 --thumb
Targets the Thumb instruction set.
This option instructs the assembler to interpret instructions as Thumb instructions, using the UAL syntax.
This is equivalent to a THUMB directive at the start of the source file.
Related references
9.4 --arm on page 9-199.
12.65 THUMB on page 12-649.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-260
reserved.
Non-Confidential
9 Assembler Command-line Options
9.64 --thumbx
9.64 --thumbx
Targets the ThumbEE instruction set.
This option instructs the assembler to interpret instructions as ThumbEE instructions, using the UAL
syntax. This is equivalent to a THUMBX directive at the start of the source file.
Note
• ARM deprecates the use of ThumbEE instructions.
• For descriptions of ThumbEE instructions, see the ARM Architecture Reference Manual.
Related references
12.66 THUMBX on page 12-650.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-261
reserved.
Non-Confidential
9 Assembler Command-line Options
9.65 --unaligned_access, --no_unaligned_access
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-262
reserved.
Non-Confidential
9 Assembler Command-line Options
9.66 --unsafe
9.66 --unsafe
Enables instructions for other architectures to be assembled without error.
It downgrades error messages to corresponding warning messages. It also suppresses warnings about
operator precedence.
Related concepts
7.20 Binary operators on page 7-151.
Related references
9.18 --diag_error=tag[,tag,…] on page 9-214.
9.22 --diag_warning=tag[,tag,…] on page 9-218.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-263
reserved.
Non-Confidential
9 Assembler Command-line Options
9.67 --untyped_local_labels
9.67 --untyped_local_labels
Causes the assembler not to set the Thumb bit for the address of a numeric local label referenced in an
LDR pseudo instruction.
When this option is not used, if you reference a numeric local label in an LDR pseudo-instruction, and the
label is in Thumb code, then the assembler sets the Thumb bit (bit 0) of the address. You can then use the
address as the target for a BX or BLX instruction.
If you require the actual address of the numeric local label, without the Thumb bit set, then use this
option.
Note
When using this option, if you use the address in a branch (register) instruction, the assembler treats it as
an ARM code address, causing the branch to arrive in ARM state, meaning it would interpret this code as
ARM instructions.
Example
THUMB
...
1
...
LDR r0,=%B1 ; r0 contains the address of numeric local label "1".
; Thumb bit is not set if --untyped_local_labels was
; used.
...
Related concepts
7.10 Numeric local labels on page 7-141.
Related references
10.46 LDR pseudo-instruction on page 10-356.
10.16 B on page 10-305.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-264
reserved.
Non-Confidential
9 Assembler Command-line Options
9.68 --version_number
9.68 --version_number
Displays the version of armasm you are using.
Usage
The assembler displays the version number in the format nnnbbbb, where:
• nnn is the version number.
• bbbb is the build number.
Example
Version 5.06 build 0019 is displayed as 5060019.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-265
reserved.
Non-Confidential
9 Assembler Command-line Options
9.69 --via=filename
9.69 --via=filename
Reads an additional list of input filenames and assembler options from filename.
Syntax
--via=filename
Where filename is the name of a via file containing options to be included on the command line.
Usage
You can enter multiple --via options on the assembler command line. The --via options can also be
included within a via file.
Related concepts
13.1 Overview of via files on page 13-654.
Related references
13.2 Via file syntax rules on page 13-655.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-266
reserved.
Non-Confidential
9 Assembler Command-line Options
9.70 --vsn
9.70 --vsn
Displays the version information and the license details.
Example
> armasm --vsn
Product: ARM Compiler N.nn
Component: ARM Compiler N.nn (toolchain_build_number)
Tool: armasm [build_number]
license_type
Software supplied by: ARM Limited
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-267
reserved.
Non-Confidential
9 Assembler Command-line Options
9.71 --width=n
9.71 --width=n
Sets the listing page width.
The default is 79 characters.
Related references
9.43 --list=file on page 9-240.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-268
reserved.
Non-Confidential
9 Assembler Command-line Options
9.72 --xref
9.72 --xref
Instructs the assembler to list cross-referencing information on symbols, including where they were
defined and where they were used, both inside and outside macros.
The default is off.
Related references
9.43 --list=file on page 9-240.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 9-269
reserved.
Non-Confidential
Chapter 10
ARM and Thumb Instructions
Describes the ARM and Thumb instructions supported by the ARM assembler, armasm.
Some instruction descriptions have an Architectures section. Instructions that do not have this section are
available in all versions of the ARM instruction set, and all versions of the Thumb instruction set.
It contains the following sections:
• 10.1 ARM and Thumb instruction summary on page 10-274.
• 10.2 Instruction width specifiers on page 10-281.
• 10.3 Flexible second operand (Operand2) on page 10-282.
• 10.4 Syntax of Operand2 as a constant on page 10-283.
• 10.5 Syntax of Operand2 as a register with optional shift on page 10-284.
• 10.6 Shift operations on page 10-285.
• 10.7 Saturating instructions on page 10-288.
• 10.8 Condition code suffixes on page 10-289.
• 10.9 ADC on page 10-290.
• 10.10 ADD on page 10-292.
• 10.11 ADR (PC-relative) on page 10-295.
• 10.12 ADR (register-relative) on page 10-297.
• 10.13 ADRL pseudo-instruction on page 10-299.
• 10.14 AND on page 10-301.
• 10.15 ASR on page 10-303.
• 10.16 B on page 10-305.
• 10.17 BFC on page 10-307.
• 10.18 BFI on page 10-308.
• 10.19 BIC on page 10-309.
• 10.20 BKPT on page 10-311.
• 10.21 BL on page 10-312.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-270
reserved.
Non-Confidential
10 ARM and Thumb Instructions
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-271
reserved.
Non-Confidential
10 ARM and Thumb Instructions
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-272
reserved.
Non-Confidential
10 ARM and Thumb Instructions
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-273
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.1 ARM and Thumb instruction summary
DBG Debug 7
DMB Data Memory Barrier 7, 6M
DSB Data Synchronization Barrier 7, 6M
EOR Exclusive OR All
ERET Exception Return 7VE
HVC Hypervisor Call 7VE
ISB Instruction Synchronization Barrier 7, 6M
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-274
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.1 ARM and Thumb instruction summary
IT If-Then T2
LDC Load Coprocessor x6M
LDC2 Load Coprocessor 5, x6M
LDM Load Multiple registers All
LDR Load Register with word All
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-275
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.1 ARM and Thumb instruction summary
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-276
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.1 ARM and Thumb instruction summary
SMUAD, SMUSD Dual Signed Multiply, and Add or Subtract products 6, 7EM
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-277
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.1 ARM and Thumb instruction summary
SWP, SWPB Swap registers and memory (ARM only) All, x7M
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-278
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.1 ARM and Thumb instruction summary
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-279
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.1 ARM and Thumb instruction summary
Entries in the Architecture column indicate that the instructions are available as follows:
All
All versions of the ARM architecture.
5
The ARMv5T*, ARMv6*, and ARMv7 architectures.
5E
The ARMv5TE, ARMv6*, and ARMv7 architectures.
6
The ARMv6* and ARMv7 architectures.
6M
The ARMv6-M and ARMv7 architectures.
x6M
Not available in the ARMv6-M architecture.
7
The ARMv7 architectures.
7M
The ARMv7-M architecture, including ARMv7E-M implementations.
x7M
Not available in the ARMv6-M or ARMv7-M architecture, or any ARMv7E-M implementation.
7EM
ARMv7E-M implementations but not in the ARMv7-M or ARMv6-M architecture.
7R
The ARMv7-R architecture.
7VE
The ARMv7 architectures that implement the Virtualization Extensions.
J
The ARMv5TEJ, ARMv6*, and ARMv7 architectures.
K
The ARMv6K, and ARMv7 architectures.
T
The ARMv4T, ARMv5T*, ARMv6*, and ARMv7 architectures.
T2
The ARMv6T2 and above architectures.
Z
If Security Extensions are implemented.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-280
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.2 Instruction width specifiers
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-281
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.3 Flexible second operand (Operand2)
Related concepts
10.6 Shift operations on page 10-285.
Related references
10.4 Syntax of Operand2 as a constant on page 10-283.
10.5 Syntax of Operand2 as a register with optional shift on page 10-284.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-282
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.4 Syntax of Operand2 as a constant
Syntax
#constant
Usage
In ARM instructions, constant can have any value that can be produced by rotating an 8-bit value right
by any even number of bits within a 32-bit word.
In Thumb instructions, constant can be:
• Any constant that can be produced by shifting an 8-bit value left by any number of bits within a 32-
bit word.
• Any constant of the form 0x00XY00XY.
• Any constant of the form 0xXY00XY00.
• Any constant of the form 0xXYXYXYXY.
Note
In these constants, X and Y are hexadecimal digits.
In addition, in a small number of instructions, constant can take a wider range of values. These are
listed in the individual instruction descriptions.
When an Operand2 constant is used with the instructions MOVS, MVNS, ANDS, ORRS, ORNS, EORS, BICS, TEQ
or TST, the carry flag is updated to bit[31] of the constant, if the constant is greater than 255 and can be
produced by shifting an 8-bit value. These instructions do not affect the carry flag if Operand2 is any
other constant.
Instruction substitution
If the value of an Operand2 constant is not available, but its logical inverse or negation is available, then
the assembler produces an equivalent instruction and inverts or negates the constant.
For example, an assembler might assemble the instruction CMP Rd, #0xFFFFFFFE as the equivalent
instruction CMN Rd, #0x2.
Be aware of this when comparing disassembly listings with source code.
You can use the --diag_warning 1645 assembler command line option to check when an instruction
substitution occurs.
Related concepts
10.6 Shift operations on page 10-285.
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.5 Syntax of Operand2 as a register with optional shift on page 10-284.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-283
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.5 Syntax of Operand2 as a register with optional shift
Syntax
Rm {, shift}
where:
Rm
is the register holding the data for the second operand.
shift
is an optional constant or register-controlled shift to be applied to Rm. It can be one of:
ASR #n
arithmetic shift right n bits, 1 ≤ n ≤ 32.
LSL #n
logical shift left n bits, 1 ≤ n ≤ 31.
LSR #n
logical shift right n bits, 1 ≤ n ≤ 32.
ROR #n
rotate right n bits, 1 ≤ n ≤ 31.
RRX
rotate right one bit, with extend.
type Rs
register-controlled shift is available in ARM code only, where:
type
is one of ASR, LSL, LSR, ROR.
Rs
is a register supplying the shift amount, and only the least significant byte is
used.
-
if omitted, no shift occurs, equivalent to LSL #0.
Usage
If you omit the shift, or specify LSL #0, the instruction uses the value in Rm.
If you specify a shift, the shift is applied to the value in Rm, and the resulting 32-bit value is used by the
instruction. However, the contents of the register Rm remain unchanged. Specifying a register with shift
also updates the carry flag when used with certain instructions.
Related concepts
10.6 Shift operations on page 10-285.
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.4 Syntax of Operand2 as a constant on page 10-283.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-284
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.6 Shift operations
Carry
Flag
31 54 3 2 1 0
...
Figure 10-1 ASR #3
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-285
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.6 Shift operations
0 0 0 Carry
Flag
31 5 4 3 2 10
...
Figure 10-2 LSR #3
0 0 0
31 5 4 3 2 10
Carry
Flag ...
Figure 10-3 LSL #3
Carry
Flag
31 5 4 3 2 10
...
Figure 10-4 ROR #3
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-286
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.6 Shift operations
Carry
Flag
31 1 0
... ...
Figure 10-5 RRX
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.4 Syntax of Operand2 as a constant on page 10-283.
10.5 Syntax of Operand2 as a register with optional shift on page 10-284.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-287
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.7 Saturating instructions
Saturating arithmetic
Saturation means that, for some value of 2n that depends on the instruction:
• For a signed saturating operation, if the full result would be less than -2n, the result returned is -2n.
• For an unsigned saturating operation, if the full result would be negative, the result returned is zero.
• If the full result would be greater than 2n-1, the result returned is 2n-1.
When any of these occurs, it is called saturation. Some instructions set the Q flag when saturation occurs.
Note
Saturating instructions do not clear the Q flag when saturation does not occur. To clear the Q flag, use an
MSR instruction.
The Q flag can also be set by two other instructions, but these instructions do not saturate.
Related references
10.74 QADD on page 10-398.
10.81 QSUB on page 10-405.
10.78 QDADD on page 10-402.
10.79 QDSUB on page 10-403.
10.109 SMLAxy on page 10-441.
10.114 SMLAWy on page 10-447.
10.121 SMULxy on page 10-454.
10.123 SMULWy on page 10-456.
10.126 SSAT on page 10-460.
10.174 USAT on page 10-521.
10.63 MSR (general-purpose register to PSR) on page 10-380.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-288
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.8 Condition code suffixes
Suffix Meaning
EQ Equal
NE Not equal
CS Carry set (identical to HS)
HS Unsigned higher or same (identical to CS)
CC Carry clear (identical to LO)
LO Unsigned lower (identical to CC)
MI Minus or negative result
PL Positive or zero result
VS Overflow
VC No overflow
HI Unsigned higher
LS Unsigned lower or same
GE Signed greater than or equal
LT Signed less than
GT Signed greater than
LE Signed less than or equal
AL Always (this is the default)
Note
The meaning of some of these condition codes depends on whether the instruction that last updated the
condition flags is a floating-point or integer instruction.
Related concepts
8.7 Conditional execution of VFP instructions on page 8-170.
Related references
5.6 Comparison of condition code meanings in integer and floating-point code on page 5-101.
10.39 IT on page 10-338.
11.21 VMRS on page 11-560.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-289
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.9 ADC
10.9 ADC
Add with Carry.
Syntax
ADC{S}{cond} {Rd}, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Usage
The ADC (Add with Carry) instruction adds the values in Rn and Operand2, together with the carry flag.
You can use ADC to synthesize multiword arithmetic.
In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when
reading disassembly listings.
Condition flags
If S is specified, the ADC instruction updates the N, Z, C and V flags according to the result.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-290
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.9 ADC
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-291
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.10 ADD
10.10 ADD
Add without Carry.
Syntax
ADD{S}{cond} {Rd}, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
imm12
is any value in the range 0-4095.
Operation
The ADD instruction adds the values in Rn and Operand2 or imm12.
In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when
reading disassembly listings.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-292
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.10 ADD
Condition flags
If S is specified, these instructions update the N, Z, C and V flags according to the result.
16-bit instructions
The following forms of these instructions are available in Thumb code, and are 16-bit instructions:
ADDS Rd, Rn, #imm
imm range 0-7. Rd and Rn must both be Lo registers. This form can only be used outside an IT
block.
ADD{cond} Rd, Rn, #imm
imm range 0-7. Rd and Rn must both be Lo registers. This form can only be used inside an IT
block.
ADDS Rd, Rn, Rm
Rd, Rn and Rm must all be Lo registers. This form can only be used outside an IT block.
ADD{cond} Rd, Rn, Rm
Rd, Rn and Rm must all be Lo registers. This form can only be used inside an IT block.
ADD Rd, Rd, Rm
ARMv6 and earlier: either Rd or Rm, or both, must be a Hi register. ARMv6T2 and above: this
restriction does not apply.
ADDS Rd, Rd, #imm
imm range 0-255. Rd must be a Lo register. This form can only be used outside an IT block.
ADD{cond} Rd, Rd, #imm
imm range 0-255. Rd must be a Lo register. This form can only be used inside an IT block.
ADD SP, SP, #imm
imm range 0-508, word aligned.
ADD Rd, SP, #imm
imm range 0-1020, word aligned. Rd must be a Lo register.
ADD Rd, pc, #imm
imm range 0-1020, word aligned. Rd must be a Lo register. Bits[1:0] of the PC are read as 0 in
this instruction.
Example
ADD r2, r1, r3
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-293
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.10 ADD
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
10.138 SUBS pc, lr on page 10-481.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-294
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.11 ADR (PC-relative)
Syntax
ADR{cond}{.W} Rd,label
where:
cond
is an optional condition code.
.W
is an optional instruction width specifier.
Rd
is the destination register to load.
label
is a PC-relative expression.
label must be within a limited distance of the current instruction.
Usage
ADR produces position-independent code, because the assembler generates an instruction that adds or
subtracts a value to the PC.
Use the ADRL pseudo-instruction to assemble a wider range of effective addresses.
label must evaluate to an address in the same assembler area as the ADR instruction.
If you use ADR to generate a target for a BX or BLX instruction, it is your responsibility to set the Thumb
bit (bit 0) of the address if the target contains Thumb instructions.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-295
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.11 ADR (PC-relative)
T
The ARMv4T, ARMv5T*, ARMv6*, and ARMv7 architectures.
ADR in Thumb
You can use the .W width specifier to force ADR to generate a 32-bit instruction in Thumb code. ADR
with .W always generates a 32-bit instruction, even if the address can be generated in a 16-bit instruction.
For forward references, ADR without .W always generates a 16-bit instruction in Thumb code, even if that
results in failure for an address that could be generated in a 32-bit Thumb ADD instruction.
Restrictions
In Thumb code, Rd cannot be PC or SP.
In ARM code, Rd can be PC or SP but use of SP is deprecated in ARMv6T2 and above.
Related concepts
4.9 Load addresses to a register using ADR on page 4-69.
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.4 Syntax of Operand2 as a constant on page 10-283.
10.13 ADRL pseudo-instruction on page 10-299.
12.6 AREA on page 12-582.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-296
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.12 ADR (register-relative)
Syntax
ADR{cond}{.W} Rd,label
where:
cond
is an optional condition code.
.W
is an optional instruction width specifier.
Rd
is the destination register to load.
label
is a symbol defined by the FIELD directive. label specifies an offset from the base register
which is defined using the MAP directive.
label must be within a limited distance from the base register.
Usage
ADR generates code to easily access named fields inside a storage map.
Restrictions
In Thumb code:
• Rd cannot be PC.
• Rd can be SP only if the base register is SP.
The following table shows the possible offsets between the label and the current instruction:
ARM ADR Any value that can be produced by rotating an 8-bit value right by All
any even number of bits within a 32-bit word.
d Rd must be in the range R0-R7 or SP. If Rd is SP, the offset range is –508 to 508 and must be a multiple of 4
e Must be a multiple of 4.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-297
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.12 ADR (register-relative)
T
The ARMv4T, ARMv5T*, ARMv6*, and ARMv7 architectures.
ADR in Thumb
You can use the .W width specifier to force ADR to generate a 32-bit instruction in Thumb code. ADR
with .W always generates a 32-bit instruction, even if the address can be generated in a 16-bit instruction.
For forward references, ADR without .W, with base register SP, always generates a 16-bit instruction in
Thumb code, even if that results in failure for an address that could be generated in a 32-bit Thumb ADD
instruction.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.4 Syntax of Operand2 as a constant on page 10-283.
10.13 ADRL pseudo-instruction on page 10-299.
12.53 MAP on page 12-636.
12.30 FIELD on page 12-609.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-298
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.13 ADRL pseudo-instruction
Syntax
ADRL{cond} Rd,label
where:
cond
is an optional condition code.
Rd
is the register to load.
label
is a PC-relative or register-relative expression.
Usage
ADRL always assembles to two 32-bit instructions. Even if the address can be reached in a single
instruction, a second, redundant instruction is produced.
If the assembler cannot construct the address in two instructions, it generates an error message and the
assembly fails. You can use the LDR pseudo-instruction for loading a wider range of addresses.
ADRL is similar to the ADR instruction, except ADRL can load a wider range of addresses because it
generates two data processing instructions.
ADRL produces position-independent code, because the address is PC-relative or register-relative.
If label is PC-relative, it must evaluate to an address in the same assembler area as the ADRL pseudo-
instruction.
If you use ADRL to generate a target for a BX or BLX instruction, it is your responsibility to set the Thumb
bit (bit 0) of the address if the target contains Thumb instructions.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
4.3 Load immediate values on page 4-60.
Related references
10.4 Syntax of Operand2 as a constant on page 10-283.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-299
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.13 ADRL pseudo-instruction
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-300
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.14 AND
10.14 AND
Logical AND.
Syntax
AND{S}{cond} Rd, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Operation
The AND instruction performs bitwise AND operations on the values in Rn and Operand2.
In certain circumstances, the assembler can substitute BIC for AND, or AND for BIC. Be aware of this when
reading disassembly listings.
Condition flags
If S is specified, the AND instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
ANDS Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
AND{cond} Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
It does not matter if you specify AND{S} Rd, Rm, Rd. The instruction is the same.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-301
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.14 AND
Examples
AND r9,r2,#0xFF00
ANDS r9, r8, #0x19
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-302
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.15 ASR
10.15 ASR
Arithmetic Shift Right. This instruction is a preferred synonym for MOV instructions with shifted register
operands.
Syntax
ASR{S}{cond} Rd, Rm, Rs
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rm
is the register holding the first operand. This operand is shifted right.
Rs
is a register holding a shift value to apply to the value in Rm. Only the least significant byte is
used.
sh
is a constant shift. The range of values permitted is 1-32.
Operation
ASR provides the signed value of the contents of a register divided by a power of two. It copies the sign
bit into vacated bit positions on the left.
Caution
Do not use the S suffix when using PC as Rd in User mode or System mode. The assembler cannot warn
you about this because it has no information about what the processor mode is likely to be at execution
time.
You cannot use PC for Rd or any operand in the ASR instruction if it has a register-controlled shift.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-303
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.15 ASR
Condition flags
If S is specified, the ASR instruction updates the N and Z flags according to the result.
The C flag is unaffected if the shift value is 0. Otherwise, the C flag is updated to the last bit shifted out.
16-bit instructions
The following forms of these instructions are available in Thumb code, and are 16-bit instructions:
ASRS Rd, Rm, #sh
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
ASR{cond} Rd, Rm, #sh
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
ASRS Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used outside an IT block.
ASR{cond} Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used inside an IT block.
Architectures
The ASR ARM instruction is available in all architectures.
The ASR 32-bit Thumb instruction is available in ARMv6T2 and above.
The ASR 16-bit Thumb instruction is available in ARMv4T and above.
Example
ASR r7, r8, r9
Related references
10.55 MOV on page 10-370.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-304
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.16 B
10.16 B
Branch.
Syntax
B{cond}{.W} label
where:
cond
is an optional condition code.
.W
is an optional instruction width specifier to force the use of a 32-bit B instruction in Thumb.
label
is a PC-relative expression.
Operation
The B instruction causes a branch to label.
B{cond} label ±32MB (All) –252 to +258 (All T) ±1MB f (All T2)
B in Thumb
You can use the .W width specifier to force B to generate a 32-bit instruction in Thumb code.
B.W always generates a 32-bit instruction, even if the target could be reached using a 16-bit instruction.
For forward references, B without .W always generates a 16-bit instruction in Thumb code, even if that
results in failure for a target that could be reached using a 32-bit Thumb instruction.
Condition flags
The B instruction does not change the flags.
Architectures
See the preceding table for details of availability of the B instruction in each architecture.
Example
B loopA
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-305
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.16 B
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.8 Condition code suffixes on page 10-289.
Related information
Information about image structure and generation.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-306
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.17 BFC
10.17 BFC
Bit Field Clear.
Syntax
BFC{cond} Rd, #lsb, #width
where:
cond
is an optional condition code.
Rd
is the destination register.
lsb
is the least significant bit that is to be cleared.
width
is the number of bits to be cleared. width must not be 0, and (width+lsb) must be less than or
equal to 32.
Operation
Clears adjacent bits in a register. width bits in Rd are cleared, starting at lsb. Other bits in Rd are
unchanged.
Register restrictions
You cannot use PC for any register.
You can use SP in the BFC ARM instruction but this is deprecated in ARMv6T2 and above. You cannot
use SP in the BFC Thumb instruction.
Condition flags
The BFC instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6T2 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-307
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.18 BFI
10.18 BFI
Bit Field Insert.
Syntax
BFI{cond} Rd, Rn, #lsb, #width
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the source register.
lsb
is the least significant bit that is to be copied.
width
is the number of bits to be copied. width must not be 0, and (width+lsb) must be less than or
equal to 32.
Operation
Inserts adjacent bits from one register into another. width bits in Rd, starting at lsb, are replaced by
width bits from Rn, starting at bit[0]. Other bits in Rd are unchanged.
Register restrictions
You cannot use PC for any register.
You can use SP in the BFI ARM instruction but this is deprecated in ARMv6T2 and above. You cannot
use SP in the BFI Thumb instruction.
Condition flags
The BFI instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6T2 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-308
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.19 BIC
10.19 BIC
Bit Clear.
Syntax
BIC{S}{cond} Rd, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Operation
The BIC (Bit Clear) instruction performs an AND operation on the bits in Rn with the complements of the
corresponding bits in the value of Operand2.
In certain circumstances, the assembler can substitute BIC for AND, or AND for BIC. Be aware of this when
reading disassembly listings.
Condition flags
If S is specified, the BIC instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
16-bit instructions
The following forms of the BIC instruction are available in Thumb code, and are 16-bit instructions:
BICS Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
BIC{cond} Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-309
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.19 BIC
Example
BIC r0, r1, #0xab
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-310
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.20 BKPT
10.20 BKPT
Breakpoint.
Syntax
BKPT #imm
where:
imm
is an expression evaluating to an integer in the range:
• 0-65535 (a 16-bit value) in an ARM instruction.
• 0-255 (an 8-bit value) in a 16-bit Thumb instruction.
Usage
The BKPT instruction causes the processor to enter Debug state. Debug tools can use this to investigate
system state when the instruction at a particular address is reached.
In both ARM state and Thumb state, imm is ignored by the ARM hardware. However, a debugger can use
it to store additional information about the breakpoint.
BKPT is an unconditional instruction. It must not have a condition code in ARM code. In Thumb code, the
BKPT instruction does not require a condition code suffix because BKPT always executes irrespective of its
condition code suffix.
Architectures
This ARM instruction is available in ARMv5T and above.
This 16-bit Thumb instruction is available in ARMv5T and above.
There is no 32-bit version of this instruction in Thumb.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-311
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.21 BL
10.21 BL
Branch with Link.
Syntax
BL{cond}{.W} label
where:
cond
is an optional condition code. cond is not available on all forms of this instruction.
.W
is an optional instruction width specifier to force the use of a 32-bit BL instruction in Thumb.
label
is a PC-relative expression.
Operation
The BL instruction causes a branch to label, and copies the address of the next instruction into LR (R14,
the link register).
Condition flags
The BL instruction does not change the flags.
Architectures
See the preceding table for details of availability of the BL instruction in each architecture.
Examples
BLE ng+8
BL subC
BLLT rtX
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-312
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.21 BL
Related references
10.8 Condition code suffixes on page 10-289.
Related information
Information about image structure and generation.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-313
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.22 BLX
10.22 BLX
Branch with Link and exchange instruction set.
Syntax
BLX{cond}{.W} label
BLX{cond} Rm
where:
cond
is an optional condition code. cond is not available on all forms of this instruction.
.W
is an optional instruction width specifier to force the use of a 32-bit BLX instruction in Thumb.
label
is a PC-relative expression.
Rm
is a register containing an address to branch to.
Operation
The BLX instruction causes a branch to label, or to the address contained in Rm. In addition:
• The BLX instruction copies the address of the next instruction into LR (R14, the link register).
• The BLX instruction can change the instruction set.
BLX label always changes the instruction set. It changes a processor in ARM state to Thumb state,
or a processor in Thumb state to ARM state.
BLX Rm derives the target instruction set from bit[0] of Rm:
— if bit[0] of Rm is 0, the processor changes to, or remains in, ARM state
— if bit[0] of Rm is 1, the processor changes to, or remains in, Thumb state.
Register restrictions
You can use PC for Rm in the ARM BLX instruction, but this is deprecated in ARMv6T2 and above. You
cannot use PC in other ARM instructions.
You can use PC for Rm in the Thumb BLX instruction. You cannot use PC in other Thumb instructions.
You can use SP for Rm in this ARM instruction but this is deprecated in ARMv6T2 and above.
You can use SP for Rm in the Thumb BLX instruction, but this is deprecated. You cannot use SP in the
other Thumb instructions.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-314
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.22 BLX
Condition flags
This instruction does not change the flags.
Architectures
See the preceding table for details of availability of the BLX instruction in each architecture.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.8 Condition code suffixes on page 10-289.
Related information
Information about image structure and generation.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-315
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.23 BX
10.23 BX
Branch and exchange instruction set.
Syntax
BX{cond} Rm
where:
cond
is an optional condition code. cond is not available on all forms of this instruction.
Rm
is a register containing an address to branch to.
Operation
The BX instruction causes a branch to the address contained in Rm and exchanges the instruction set, if
required:
• BX Rm derives the target instruction set from bit[0] of Rm:
— If bit[0] of Rm is 0, the processor changes to, or remains in, ARM state.
— If bit[0] of Rm is 1, the processor changes to, or remains in, Thumb state.
Register restrictions
You can use PC for Rm in the ARM BX instruction, but this is deprecated in ARMv6T2 and above. You
cannot use PC in other ARM instructions.
You can use PC for Rm in the Thumb BX instruction. You cannot use PC in other Thumb instructions.
You can use SP for Rm in the ARM BX instruction but this is deprecated in ARMv6T2 and above.
You can use SP for Rm in the Thumb BX instruction, but this is deprecated.
Condition flags
The BX instruction does not change the flags.
Architectures
See the preceding table for details of availability of the BX instruction in each architecture.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
i The assembler accepts BX{cond} Rm for code assembled for ARMv4 and converts it to MOV{cond} PC, Rm at link time, unless objects targeted for ARMv4T
are present.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-316
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.23 BX
Related references
10.8 Condition code suffixes on page 10-289.
Related information
Information about image structure and generation.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-317
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.24 BXJ
10.24 BXJ
Branch and change to Jazelle state.
Syntax
BXJ{cond} Rm
where:
cond
is an optional condition code. cond is not available on all forms of this instruction.
Rm
is a register containing an address to branch to.
Operation
The BXJ instruction causes a branch to the address contained in Rm and changes the instruction set state to
Jazelle.
Register restrictions
You can use SP for Rm in the BXJ ARM instruction but this is deprecated in ARMv6T2 and above.
You cannot use SP in the BXJ Thumb instruction.
Condition flags
The BXJ instruction does not change the flags.
Architectures
See the preceding table for details of availability of the BXJ instruction in each architecture.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.8 Condition code suffixes on page 10-289.
Related information
Information about image structure and generation.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-318
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.25 CBZ and CBNZ
Syntax
CBZ Rn, label
where:
Rn
is the register holding the operand.
label
is the branch destination.
Usage
You can use the CBZ or CBNZ instructions to avoid changing the condition flags and to reduce the number
of instructions.
Except that it does not change the condition flags, CBZ Rn, label is equivalent to:
CMP Rn, #0
BEQ label
Except that it does not change the condition flags, CBNZ Rn, label is equivalent to:
CMP Rn, #0
BNE label
Restrictions
The branch destination must be within 4 to 130 bytes after the instruction and in the same execution
state.
These instructions must not be used inside an IT block.
Condition flags
These instructions do not change the flags.
Architectures
These 16-bit Thumb instructions are available in ARMv6T2 and above.
There are no ARM or 32-bit Thumb encodings of these instructions.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-319
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.26 CDP and CDP2
Syntax
CDP{cond} coproc, #opcode1, CRd, CRn, CRm{, #opcode2}
where:
cond
is an optional condition code. In ARM code, cond is not permitted for CDP2.
coproc
is the name of the coprocessor the instruction is for. The standard name is pn, where n is an
integer in the range 0 to 15.
opcode1
is a 4-bit coprocessor-specific opcode.
opcode2
is an optional 3-bit coprocessor-specific opcode.
CRd, CRn, CRm
are coprocessor registers.
Usage
The use of these instructions depends on the coprocessor. See the coprocessor documentation for details.
Architectures
The CDP ARM instruction is available in all versions of the ARM architecture.
The CDP2 ARM instruction is available in ARMv5T and above.
These 32-bit Thumb instructions are available in ARMv6T2 and above.
There are no 16-bit versions of these instructions in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-320
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.27 CLREX
10.27 CLREX
Clear Exclusive.
Syntax
CLREX{cond}
where:
cond
is an optional condition code.
Note
cond is permitted only in Thumb code, using a preceding IT instruction. This is an
unconditional instruction in ARM.
Usage
Use the CLREX instruction to clear the local record of the executing processor that an address has had a
request for an exclusive access.
CLREX returns a closely-coupled exclusive access monitor to its open-access state. This removes the
requirement for a dummy store to memory.
It is implementation defined whether CLREX also clears the global record of the executing processor that
an address has had a request for an exclusive access.
Architectures
This ARM instruction is available in ARMv6K and above.
This 32-bit Thumb instruction is available in ARMv7 and above.
There is no 16-bit CLREX instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-321
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.28 CLZ
10.28 CLZ
Count Leading Zeros.
Syntax
CLZ{cond} Rd, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the operand register.
Operation
The CLZ instruction counts the number of leading zeros in the value in Rm and returns the result in Rd.
The result value is 32 if no bits are set in the source register, and zero if bit 31 is set.
Register restrictions
You cannot use PC for any operand.
You can use SP in these ARM instructions but this is deprecated in ARMv6T2 and above.
You cannot use SP in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv5T and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Examples
CLZ r4,r9
CLZNE r2,r3
Use the CLZ Thumb instruction followed by a left shift of Rm by the resulting Rd value to normalize the
value of register Rm. Use MOVS, rather than MOV, to flag the case where Rm is zero:
CLZ r5, r9
MOVS r9, r9, LSL r5
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-322
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.29 CMP and CMN
Syntax
CMP{cond} Rn, Operand2
where:
cond
is an optional condition code.
Rn
is the ARM register holding the first operand.
Operand2
is a flexible second operand.
Operation
These instructions compare the value in a register with Operand2. They update the condition flags on the
result, but do not place the result in any register.
The CMP instruction subtracts the value of Operand2 from the value in Rn. This is the same as a SUBS
instruction, except that the result is discarded.
The CMN instruction adds the value of Operand2 to the value in Rn. This is the same as an ADDS
instruction, except that the result is discarded.
In certain circumstances, the assembler can substitute CMN for CMP, or CMP for CMN. Be aware of this when
reading disassembly listings.
Condition flags
These instructions update the N, Z, C and V flags according to the result.
16-bit instructions
The following forms of these instructions are available in Thumb code, and are 16-bit instructions:
CMP Rn, Rm
Lo register restriction does not apply.
CMN Rn, Rm
Rn and Rm must both be Lo registers.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-323
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.29 CMP and CMN
Correct examples
CMP r2, r9
CMN r0, #6400
CMPGT sp, r7, LSL #2
Incorrect example
CMP r2, pc, ASR r0 ; PC not permitted with register-controlled shift.
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-324
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.30 CPS
10.30 CPS
Change Processor State.
Syntax
CPSeffect iflags{, #mode}
CPS #mode
where:
effect
is one of:
IE
Interrupt or abort enable.
ID
Interrupt or abort disable.
iflags
is a sequence of one or more of:
a
Enables or disables imprecise aborts.
i
Enables or disables IRQ interrupts.
f
Enables or disables FIQ interrupts.
mode
specifies the number of the mode to change to.
Usage
Changes one or more of the mode, A, I, and F bits in the CPSR, without changing the other CPSR bits.
CPS is only permitted in privileged software execution, and has no effect in User mode.
Condition flags
This instruction does not change the condition flags.
16-bit instructions
The following forms of these instructions are available in Thumb code, and are 16-bit instructions:
• CPSIE iflags.
• CPSID iflags.
You cannot specify a mode change in a 16-bit Thumb instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction are available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in T variants of ARMv6 and above.
Examples
CPSIE if ; Enable IRQ and FIQ interrupts.
CPSID A ; Disable imprecise aborts.
CPSID ai, #17 ; Disable imprecise aborts and interrupts, and enter FIQ mode.
CPS #16 ; Enter User mode.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-325
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.30 CPS
Related concepts
2.4 Processor modes, and privileged and unprivileged software execution on page 2-33.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-326
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.31 CPY pseudo-instruction
Syntax
CPY{cond} Rd, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register holding the value to be copied.
Operation
The CPY pseudo-instruction copies a value from one register to another, without changing the condition
flags.
CPY Rd, Rm assembles to MOV Rd, Rm.
Architectures
This pseudo-instruction is available in ARMv6 and above in ARM code and in T variants of ARMv6 and
above in Thumb code.
Register restrictions
Using SP or PC for both Rd and Rm is deprecated.
Condition flags
This instruction does not change the condition flags.
Related references
10.55 MOV on page 10-370.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-327
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.32 DBG
10.32 DBG
Debug.
Syntax
DBG{cond} {option}
where:
cond
is an optional condition code.
option
is an optional limitation on the operation of the hint. The range is 0-15.
Usage
DBG is a hint instruction. It is optional whether it is implemented or not. If it is not implemented, it
behaves as a NOP. The assembler produces a diagnostic message if the instruction executes as NOP on the
target.
DBG executes as a NOP instruction in ARMv6K and ARMv6T2.
Debug hint provides a hint to a debugger and related tools. See your debugger and related tools
documentation to determine the use, if any, of this instruction.
Architectures
This ARM instruction is available in ARMv6K and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.67 NOP on page 10-387.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-328
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.33 DMB
10.33 DMB
Data Memory Barrier.
Syntax
DMB{cond} {option}
where:
cond
is an optional condition code.
Note
cond is permitted only in Thumb code. This is an unconditional instruction in ARM code.
option
is an optional limitation on the operation of the hint. Permitted values are:
SY
Full system DMB operation. This is the default and can be omitted.
ST
DMB operation that waits only for stores to complete.
ISH
DMB operation only to the inner shareable domain.
ISHST
DMB operation that waits only for stores to complete, and only to the inner shareable
domain.
NSH
DMB operation only out to the point of unification.
NSHST
DMB operation that waits only for stores to complete and only out to the point of
unification.
OSH
DMB operation only to the outer shareable domain.
OSHST
DMB operation that waits only for stores to complete, and only to the outer shareable
domain.
Operation
Data Memory Barrier acts as a memory barrier. It ensures that all explicit memory accesses that appear in
program order before the DMB instruction are observed before any explicit memory accesses that appear
in program order after the DMB instruction. It does not affect the ordering of any other instructions
executing on the processor.
Alias
The following alternative values of option are supported, but ARM recommends that you do not use
them:
• SH is an alias for ISH.
• SHST is an alias for ISHST.
• UN is an alias for NSH.
• UNST is an alias for NSHST.
Architectures
This ARM and 32-bit Thumb instruction is available in ARMv7.
There is no 16-bit version of this instruction in Thumb.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-329
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.33 DMB
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-330
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.34 DSB
10.34 DSB
Data Synchronization Barrier.
Syntax
DSB{cond} {option}
where:
cond
is an optional condition code.
Note
cond is permitted only in Thumb code. This is an unconditional instruction in ARM.
option
is an optional limitation on the operation of the hint. Permitted values are:
SY
Full system DSB operation. This is the default and can be omitted.
ST
DSB operation that waits only for stores to complete.
ISH
DSB operation only to the inner shareable domain.
ISHST
DSB operation that waits only for stores to complete, and only to the inner shareable
domain.
NSH
DSB operation only out to the point of unification.
NSHST
DSB operation that waits only for stores to complete and only out to the point of
unification.
OSH
DSB operation only to the outer shareable domain.
OSHST
DSB operation that waits only for stores to complete, and only to the outer shareable
domain.
Operation
Data Synchronization Barrier acts as a special kind of memory barrier. No instruction in program order
after this instruction executes until this instruction completes. This instruction completes when:
• All explicit memory accesses before this instruction complete.
• All Cache, Branch predictor and TLB maintenance operations before this instruction complete.
Alias
The following alternative values of option are supported for DSB, but ARM recommends that you do not
use them:
• SH is an alias for ISH.
• SHST is an alias for ISHST.
• UN is an alias for NSH.
• UNST is an alias for NSHST.
Architectures
This ARM and 32-bit Thumb instruction is available in ARMv7.
There is no 16-bit version of this instruction in Thumb.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-331
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.34 DSB
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-332
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.35 EOR
10.35 EOR
Logical Exclusive OR.
Syntax
EOR{S}{cond} Rd, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Operation
The EOR instruction performs bitwise Exclusive OR operations on the values in Rn and Operand2.
Condition flags
If S is specified, the EOR instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
16-bit instructions
The following forms of the EOR instruction are available in Thumb code, and are 16-bit instructions:
EORS Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
EOR{cond} Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
It does not matter if you specify EOR{S} Rd, Rm, Rd. The instruction is the same.
Correct examples
EORS r0,r0,r3,ROR r6
EORS r7, r11, #0x18181818
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-333
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.35 EOR
Incorrect example
EORS r0,pc,r3,ROR r6 ; PC not permitted with register
; controlled shift
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-334
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.36 ERET
10.36 ERET
Exception Return.
Syntax
ERET{cond}
where:
cond
is an optional condition code.
Usage
In a processor that implements the Virtualization Extensions, you can use ERET to perform a return from
an exception taken to Hyp mode.
Operation
When executed in Hyp mode, ERET loads the PC from ELR_hyp and loads the CPSR from SPSR_hyp.
When executed in any other mode, apart from User or System, it behaves as:
• MOVS PC, LR in the ARM instruction set.
• SUBS PC, LR, #0 in the Thumb instruction set.
Notes
You must not use ERET in User or System mode. The assembler cannot warn you about this because it
has no information about what the processor mode is likely to be at execution time.
ERET is the preferred synonym for SUBS PC, LR, #0 in the Thumb instruction set.
Architectures
This ARM instruction is available in ARMv7 architectures that include the Virtualization Extensions.
This 32-bit Thumb instruction is available in ARMv7 architectures that include the Virtualization
Extensions.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.4 Processor modes, and privileged and unprivileged software execution on page 2-33.
Related references
10.55 MOV on page 10-370.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
10.37 HVC on page 10-336.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-335
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.37 HVC
10.37 HVC
Hypervisor Call.
Syntax
HVC #imm
where:
imm
is an expression evaluating to an integer in the range 0-65535.
Operation
In a processor that implements the Virtualization Extensions, the HVC instruction causes a Hypervisor
Call exception. This means that the processor enters Hyp mode, the CPSR value is saved to the Hyp
mode SPSR, and execution branches to the HVC vector.
HVC must not be used if the processor is in Secure state, or in User mode in Non-secure state.
imm is ignored by the processor. However, it can be retrieved by the exception handler to determine what
service is being requested.
HVC cannot be conditional, and is not permitted in an IT block.
Notes
The ERET instruction performs an exception return from Hyp mode.
Architectures
This ARM and 32-bit Thumb instruction is available in ARMv7 architectures that include the
Virtualization Extensions.
There is no 16-bit version of this instruction in Thumb
Related concepts
2.4 Processor modes, and privileged and unprivileged software execution on page 2-33.
Related references
10.36 ERET on page 10-335.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-336
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.38 ISB
10.38 ISB
Instruction Synchronization Barrier.
Syntax
ISB{cond} {option}
where:
cond
is an optional condition code.
Note
cond is permitted only in Thumb code. This is an unconditional instruction in ARM code.
option
is an optional limitation on the operation of the hint. The permitted value is:
SY
Full system DMB operation. This is the default and can be omitted.
Operation
Instruction Synchronization Barrier flushes the pipeline in the processor, so that all instructions following
the ISB are fetched from cache or memory, after the instruction has been completed. It ensures that the
effects of context altering operations, such as changing the ASID, or completed TLB maintenance
operations, or branch predictor maintenance operations, in addition to all changes to the CP15 registers,
executed before the ISB instruction are visible to the instructions fetched after the ISB.
In addition, the ISB instruction ensures that any branches that appear in program order after it are always
written into the branch prediction logic with the context that is visible after the ISB instruction. This is
required to ensure correct execution of the instruction stream.
Note
When the target architecture is ARMv7-M, you cannot use an ISB instruction in an IT block, unless it is
the last instruction in the block.
Architectures
This ARM and 32-bit Thumb instruction is available in ARMv7.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-337
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.39 IT
10.39 IT
If-Then.
Syntax
IT{x{y{z}}} {cond}
where:
x
specifies the condition switch for the second instruction in the IT block.
y
specifies the condition switch for the third instruction in the IT block.
z
specifies the condition switch for the fourth instruction in the IT block.
cond
specifies the condition for the first instruction in the IT block.
The condition switch for the second, third and fourth instruction in the IT block can be either:
T
Then. Applies the condition cond to the instruction.
E
Else. Applies the inverse condition of cond to the instruction.
Usage
The IT instruction makes up to four following instructions (the IT block) conditional. The conditions can
be all the same, or some of them can be the logical inverse of the others.
The instructions (including branches) in the IT block, except the BKPT instruction, must specify the
condition in the {cond} part of their syntax.
You are not required to write IT instructions in your code, because the assembler generates them for you
automatically according to the conditions specified on the following instructions. However, if you do
write IT instructions, the assembler validates the conditions specified in the IT instructions against the
conditions specified in the following instructions.
Writing the IT instructions ensures that you consider the placing of conditional instructions, and the
choice of conditions, in the design of your code.
When assembling to ARM code, the assembler performs the same checks, but does not generate any IT
instructions.
With the exception of CMP, CMN, and TST, the 16-bit instructions that normally affect the condition flags,
do not affect them when used inside an IT block.
A BKPT instruction in an IT block is always executed, so it does not require a condition in the {cond} part
of its syntax. The IT block continues from the next instruction.
Note
You can use an IT block for unconditional instructions by using the AL condition.
Conditional branches inside an IT block have a longer branch range than those outside the IT block.
Restrictions
The following instructions are not permitted in an IT block:
• IT.
• CBZ and CBNZ.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-338
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.39 IT
Note
The assembler shows a diagnostic message when any of these instructions are used in an IT block.
Condition flags
This instruction does not change the flags.
Exceptions
Exceptions can occur between an IT instruction and the corresponding IT block, or within an IT block.
This exception results in entry to the appropriate exception handler, with suitable return information in
LR and SPSR.
Instructions designed for use as exception returns can be used as normal to return from the exception,
and execution of the IT block resumes correctly. This is the only way that a PC-modifying instruction
can branch to an instruction in an IT block.
Architectures
This 16-bit Thumb instruction is available in ARMv6T2 and above.
In ARM code, IT is a pseudo-instruction that does not generate any code.
There is no 32-bit version of this instruction.
Correct examples
ITTE NE ; IT can be omitted
ANDNE r0,r0,r1 ; 16-bit AND, not ANDS
ADDSNE r2,r2,#1 ; 32-bit ADDS (16-bit ADDS does not set flags in
; IT block)
MOVEQ r2,r3 ; 16-bit MOV
ITT AL ; emit 2 non-flag setting 16-bit instructions
ADDAL r0,r0,r1 ; 16-bit ADD, not ADDS
SUBAL r2,r2,#1 ; 16-bit SUB, not SUB
ADD r0,r0,r1 ; expands into 32-bit ADD, and is not in IT block
ITT EQ
MOVEQ r0,r1
BEQ dloop ; branch at end of IT block is permitted
ITT EQ
MOVEQ r0,r1
BKPT #1 ; BKPT always executes
ADDEQ r0,r0,#1
Incorrect example
IT NE
ADD r0,r0,r1 ; syntax error: no condition code used in IT block
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-339
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.40 LDC and LDC2
Syntax
op{L}{cond} coproc, CRd, [Rn]
where:
op
is LDC or LDC2.
cond
is an optional condition code.
In ARM code, cond is not permitted for LDC2.
L
is an optional suffix specifying a long transfer.
coproc
is the name of the coprocessor the instruction is for. The standard name is pn, where n is an
integer in the range 0 to 15.
CRd
is the coprocessor register to load.
Rn
is the register on which the memory address is based. If PC is specified, the value used is the
address of the current instruction plus eight.
-
is an optional minus sign. If - is present, the offset is subtracted from Rn. Otherwise, the offset is
added to Rn.
offset
is an expression evaluating to a multiple of 4, in the range 0 to 1020.
!
is an optional suffix. If ! is present, the address including the offset is written back into Rn.
label
is a word-aligned PC-relative expression.
label must be within 1020 bytes of the current instruction.
option
is a coprocessor option in the range 0-255, enclosed in braces.
Usage
The use of these instructions depends on the coprocessor. See the coprocessor documentation for details.
Architectures
LDC is available in all versions of the ARM architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-340
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.40 LDC and LDC2
Register restrictions
You cannot use PC for Rn in the pre-index and post-index instructions. These are the forms that write
back to Rn.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-341
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.41 LDM
10.41 LDM
Load Multiple registers.
Syntax
LDM{addr_mode}{cond} Rn{!}, reglist{^}
where:
addr_mode
is any one of the following:
IA
Increment address After each transfer. This is the default, and can be omitted.
IB
Increment address Before each transfer (ARM only).
DA
Decrement address After each transfer (ARM only).
DB
Decrement address Before each transfer.
You can also use the stack oriented addressing mode suffixes, for example, when implementing
stacks.
cond
is an optional condition code.
Rn
is the base register, the ARM register holding the initial address for the transfer. Rn must not be
PC.
!
is an optional suffix. If ! is present, the final address is written back into Rn.
reglist
is a list of one or more registers to be loaded, enclosed in braces. It can contain register ranges.
It must be comma separated if it contains more than one register or register range. Any
combination of registers R0 to R15 (PC) can be transferred in ARM state, but there are some
restrictions in Thumb state.
^
is an optional suffix, available in ARM state only. You must not use it in User mode or System
mode. It has the following purposes:
• If reglist contains the PC (R15), in addition to the normal multiple register transfer, the
SPSR is copied into the CPSR. This is for returning from exception handlers. Use this only
from exception modes.
• Otherwise, data is transferred into or out of the User mode registers instead of the current
mode registers.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-342
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.41 LDM
16-bit instructions
16-bit versions of a subset of these instructions are available in Thumb code.
The following restrictions apply to the 16-bit instructions:
• All registers in reglist must be Lo registers.
• Rn must be a Lo register.
• addr_mode must be omitted (or IA), meaning increment address after each transfer.
• Writeback must be specified for LDM instructions where Rn is not in the reglist.
In addition, the PUSH and POP instructions are subsets of the STM and LDM instructions and can therefore
be expressed using the STM and LDM instructions. Some forms of PUSH and POP are also 16-bit
instructions.
Loading to the PC
A load to the PC causes a branch to the instruction at the address loaded.
In ARMv4, bits[1:0] of the address loaded must be 0b00.
In ARMv5T and above:
• Bits[1:0] must not be 0b10.
• If bit[0] is 1, execution continues in Thumb state.
• If bit[0] is 0, execution continues in ARM state.
Correct example
LDM r8,{r0,r2,r9} ; LDMIA is a synonym for LDM
Incorrect example
LDMDA r2, {} ; must be at least one register in list
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
6.16 Address alignment on page 6-128.
Related references
10.72 POP on page 10-395.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-343
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.42 LDR (immediate offset)
Syntax
LDR{type}{cond} Rt, [Rn {, #offset}] ; immediate offset
where:
type
can be any one of:
B
unsigned Byte (Zero extend to 32 bits on loads.)
SB
signed Byte (LDR only. Sign extend to 32 bits.)
H
unsigned Halfword (Zero extend to 32 bits on loads.)
SH
signed Halfword (LDR only. Sign extend to 32 bits.)
-
omitted, for Word.
cond
is an optional condition code.
Rt
is the register to load.
Rn
is the register on which the memory address is based.
offset
is an offset. If offset is omitted, the address is the contents of Rn.
Rt2
is the additional register to load for doubleword operations.
Not all options are available in every instruction set and architecture.
Table 10-10 Offsets and architectures, LDR, word, halfword, and byte
ARM, word or byte j –4095 to 4095 –4095 to 4095 –4095 to 4095 All
ARM, signed byte, halfword, or signed halfword –255 to 255 –255 to 255 –255 to 255 All
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-344
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.42 LDR (immediate offset)
Table 10-10 Offsets and architectures, LDR, word, halfword, and byte (continued)
Thumb 32-bit encoding, word, halfword, signed halfword, byte, or –255 to 4095 –255 to 255 –255 to 255 T2
signed byte j
Thumb 32-bit encoding, doubleword –1020 to 1020 k –1020 to 1020 k –1020 to 1020 k T2
Register restrictions
Rn must be different from Rt in the pre-index and post-index forms.
For Thumb instructions, you must not specify SP or PC for either Rt or Rt2.
For ARM instructions:
• Rt must be an even-numbered register.
• Rt must not be LR.
• ARM strongly recommends that you do not use R12 for Rt.
• Rt2 must be R(t + 1).
Use of PC
In ARM code you can use PC for Rt in LDR word instructions and PC for Rn in LDR instructions.
Other uses of PC are not permitted in these ARM instructions.
In Thumb code you can use PC for Rt in LDR word instructions and PC for Rn in LDR instructions. Other
uses of PC in these Thumb instructions are not permitted.
Use of SP
You can use SP for Rn.
j For word loads, Rt can be the PC. A load to the PC causes a branch to the address loaded. In ARMv4, bits[1:0] of the address loaded must be 0b00. In ARMv5T and
above, bits[1:0] must not be 0b10, and if bit[0] is 1, execution continues in Thumb state, otherwise execution continues in ARM state.
k Must be divisible by 4.
l Rt and Rn must be in the range R0-R7.
m Must be divisible by 2.
n Rt must be in the range R0-R7.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-345
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.42 LDR (immediate offset)
In ARM code, you can use SP for Rt in word instructions. You can use SP for Rt in non-word
instructions in ARM code but this is deprecated in ARMv6T2 and above.
In Thumb code, you can use SP for Rt in word instructions only. All other use of SP for Rt in these
instructions are not permitted in Thumb code.
Examples
LDR r8,[r10] ; loads R8 from the address in R10.
LDRNE r2,[r5,#960]! ; (conditionally) loads R2 from a word
; 960 bytes above the address in R5, and
; increments R5 by 960.
Related concepts
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-346
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.43 LDR (PC-relative)
Syntax
LDR{type}{cond}{.W} Rt, label
where:
type
can be any one of:
B
unsigned Byte (Zero extend to 32 bits on loads.)
SB
signed Byte (LDR only. Sign extend to 32 bits.)
H
unsigned Halfword (Zero extend to 32 bits on loads.)
SH
signed Halfword (LDR only. Sign extend to 32 bits.)
-
omitted, for Word.
cond
is an optional condition code.
.W
is an optional instruction width specifier.
Rt
is the register to load or store.
Rt2
is the second register to load or store.
label
is a PC-relative expression.
label must be within a limited distance of the current instruction.
Note
Equivalent syntaxes are available for the STR instruction in ARM code but they are deprecated in
ARMv6T2 and above.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-347
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.43 LDR (PC-relative)
Use of SP
In ARM code, you can use SP for Rt in LDR word instructions. You can use SP for Rt in LDR non-word
ARM instructions but this is deprecated in ARMv6T2 and above.
In Thumb code, you can use SP for Rt in LDR word instructions only. All other uses of SP in these
instructions are not permitted in Thumb code.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
6.16 Address alignment on page 6-128.
o For word loads, Rt can be the PC. A load to the PC causes a branch to the address loaded. In ARMv4, bits[1:0] of the address loaded must be 0b00. In ARMv5T and
above, bits[1:0] must not be 0b10, and if bit[0] is 1, execution continues in Thumb state, otherwise execution continues in ARM state.
p In ARMv7-M, LDRD (PC-relative) instructions must be on a word-aligned address.
q Must be a multiple of 4.
r Rt must be in the range R0-R7. There are no byte, halfword, or doubleword 16-bit instructions.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-348
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.43 LDR (PC-relative)
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-349
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.44 LDR (register offset)
Syntax
LDR{type}{cond} Rt, [Rn, ±Rm {, shift}] ; register offset
LDRD{cond} Rt, Rt2, [Rn, ±Rm] ; register offset, doubleword ; ARM only
where:
type
can be any one of:
B
unsigned Byte (Zero extend to 32 bits on loads.)
SB
signed Byte (LDR only. Sign extend to 32 bits.)
H
unsigned Halfword (Zero extend to 32 bits on loads.)
SH
signed Halfword (LDR only. Sign extend to 32 bits.)
-
omitted, for Word.
cond
is an optional condition code.
Rt
is the register to load.
Rn
is the register on which the memory address is based.
Rm
is a register containing a value to be used as the offset. –Rm is not permitted in Thumb code.
shift
is an optional shift.
Rt2
is the additional register to load for doubleword operations.
Not all options are available in every instruction set and architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-350
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.44 LDR (register offset)
ARM, signed byte, halfword, or signed halfword +/–Rm Not available All
Thumb 32-bit encoding, word, halfword, signed halfword, byte, or signed byte t +Rm LSL #0-3 T2
Register restrictions
In the pre-index and post-index forms:
• Rn must be different from Rt.
• Rn must be different from Rm in architectures before ARMv6.
Use of PC
In ARM instructions you can use PC for Rt in LDR word instructions, and you can use PC for Rn in LDR
instructions with register offset syntax (that is the forms that do not writeback to the Rn).
Other uses of PC are not permitted in ARM instructions.
In Thumb instructions you can use PC for Rt in LDR word instructions. Other uses of PC in these Thumb
instructions are not permitted.
Use of SP
You can use SP for Rn.
In ARM code, you can use SP for Rt in word instructions. You can use SP for Rt in non-word ARM
instructions but this is deprecated in ARMv6T2 and above.
s Where +/–Rm is shown, you can use –Rm, +Rm, or Rm. Where +Rm is shown, you cannot use –Rm.
t For word loads, Rt can be the PC. A load to the PC causes a branch to the address loaded. In ARMv4, bits[1:0] of the address loaded must be 0b00. In ARMv5T and
above, bits[1:0] must not be 0b10, and if bit[0] is 1, execution continues in Thumb state, otherwise execution continues in ARM state.
u Rt, Rn, and Rm must all be in the range R0-R7.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-351
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.44 LDR (register offset)
You can use SP for Rm in ARM instructions but this is deprecated in ARMv6T2 and above.
In Thumb code, you can use SP for Rt in word instructions only. All other use of SP for Rt in these
instructions are not permitted in Thumb code.
Use of SP for Rm is not permitted in Thumb state.
Related concepts
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-352
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.45 LDR (register-relative)
Syntax
LDR{type}{cond}{.W} Rt, label
where:
type
can be any one of:
B
unsigned Byte (Zero extend to 32 bits on loads.)
SB
signed Byte (LDR only. Sign extend to 32 bits.)
H
unsigned Halfword (Zero extend to 32 bits on loads.)
SH
signed Halfword (LDR only. Sign extend to 32 bits.)
-
omitted, for Word.
cond
is an optional condition code.
.W
is an optional instruction width specifier.
Rt
is the register to load or store.
Rt2
is the second register to load or store.
label
is a symbol defined by the FIELD directive. label specifies an offset from the base register
which is defined using the MAP directive.
label must be within a limited distance of the value in the base register.
The following table shows the possible offsets between the label and the current instruction:
v For word loads, Rt can be the PC. A load to the PC causes a branch to the address loaded. In ARMv4, bits[1:0] of the address loaded must be 0b00. In ARMv5T and
above, bits[1:0] must not be 0b10, and if bit[0] is 1, execution continues in Thumb state, otherwise execution continues in ARM state.
w Must be a multiple of 4.
x Rt and base register must be in the range R0-R7.
y Must be a multiple of 2.
z Rt must be in the range R0-R7.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-353
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.45 LDR (register-relative)
Use of PC
You can use PC for Rt in word instructions. Other uses of PC are not permitted in these instructions.
Use of SP
In ARM code, you can use SP for Rt in word instructions. You can use SP for Rt in non-word ARM
instructions but this is deprecated in ARMv6T2 and above.
In Thumb code, you can use SP for Rt in word instructions only. All other use of SP for Rt in these
instructions are not permitted in Thumb code.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
6.16 Address alignment on page 6-128.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-354
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.45 LDR (register-relative)
Related references
12.30 FIELD on page 12-609.
12.53 MAP on page 12-636.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-355
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.46 LDR pseudo-instruction
Note
This describes the LDR pseudo-instruction only, and not the LDR instruction.
Syntax
LDR{cond}{.W} Rt, =expr
where:
cond
is an optional condition code.
.W
is an optional instruction width specifier.
Rt
is the register to be loaded.
expr
evaluates to a numeric value.
label_expr
is a PC-relative or external expression of an address in the form of a label plus or minus a
numeric value.
Usage
When using the LDR pseudo-instruction:
• If the value of expr can be loaded with a valid MOV or MVN instruction, the assembler uses that
instruction.
• If a valid MOV or MVN instruction cannot be used, or if the label_expr syntax is used, the assembler
places the constant in a literal pool and generates a PC-relative LDR instruction that reads the constant
from the literal pool.
Note
— An address loaded in this way is fixed at link time, so the code is not position-independent.
— The address holding the constant remains valid regardless of where the linker places the ELF
section containing the LDR instruction.
The assembler places the value of label_expr in a literal pool and generates a PC-relative LDR
instruction that loads the value from the literal pool.
If label_expr is an external expression, or is not contained in the current section, the assembler places a
linker relocation directive in the object file. The linker generates the address at link time.
If label_expr is either a named or numeric local label, the assembler places a linker relocation directive
in the object file and generates a symbol for that local label. The address is generated at link time. If the
local label references Thumb code, the Thumb bit (bit 0) of the address is set.
The offset from the PC to the value in the literal pool must be less than ±4KB (in an ARM or 32-bit
Thumb encoding) or in the range 0 to +1KB (16-bit Thumb encoding). You are responsible for ensuring
that there is a literal pool within range.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-356
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.46 LDR pseudo-instruction
If the label referenced is in Thumb code, the LDR pseudo-instruction sets the Thumb bit (bit 0) of
label_expr.
Note
In RealView Compilation Tools (RVCT) v2.2, the Thumb bit of the address was not set. If you have code
that relies on this behavior, use the command line option --untyped_local_labels to force the
assembler not to set the Thumb bit when referencing labels in Thumb code.
Examples
LDR r3,=0xff0 ; loads 0xff0 into R3
; => MOV.W r3,#0xff0
LDR r1,=0xfff ; loads 0xfff into R1
; => LDR r1,[pc,offset_to_litpool]
; ...
; litpool DCD 0xfff
LDR r2,=place ; loads the address of
; place into R2
; => LDR r2,[pc,offset_to_litpool]
; ...
; litpool DCD place
Related concepts
7.3 Numeric constants on page 7-134.
7.5 Register-relative and PC-relative expressions on page 7-136.
7.10 Numeric local labels on page 7-141.
Related references
9.67 --untyped_local_labels on page 9-264.
10.56 MOV32 pseudo-instruction on page 10-372.
10.8 Condition code suffixes on page 10-289.
12.51 LTORG on page 12-632.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-357
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.47 LDR, unprivileged
Syntax
LDR{type}T{cond} Rt, [Rn {, #offset}] ; immediate offset (32-bit Thumb encoding only)
where:
type
can be any one of:
B
unsigned Byte (Zero extend to 32 bits on loads.)
SB
signed Byte (Sign extend to 32 bits.)
H
unsigned Halfword (Zero extend to 32 bits on loads.)
SH
signed Halfword (Sign extend to 32 bits.)
-
omitted, for Word.
cond
is an optional condition code.
Rt
is the register to load.
Rn
is the register on which the memory address is based.
offset
is an offset. If offset is omitted, the address is the value in Rn.
Rm
is a register containing a value to be used as the offset. Rm must not be PC.
shift
is an optional shift.
Operation
When these instructions are executed by privileged software, they access memory with the same
restrictions as they would have if they were executed by unprivileged software.
When executed by unprivileged software these instructions behave in exactly the same way as the
corresponding load instruction, for example LDRSBT behaves in the same way as LDRSB.
ARM, word or byte Not available –4095 to 4095 +/–Rm LSL #0-31 All
LSR #1-32
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-358
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.47 LDR, unprivileged
ASR #1-32
ROR #1-31
RRX
ARM, signed byte, halfword, or signed halfword Not available –255 to 255 +/–Rm Not available T2
Thumb, 32-bit encoding, word, halfword, signed halfword, 0 to 255 Not available Not available T2
byte, or signed byte
Related concepts
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-359
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.48 LDREX
10.48 LDREX
Load Register Exclusive.
Syntax
LDREX{cond} Rt, [Rn {, #offset}]
where:
cond
is an optional condition code.
Rt
is the register to load.
Rt2
is the second register for doubleword loads.
Rn
is the register on which the memory address is based.
offset
is an optional offset applied to the value in Rn. offset is permitted only in 32-bit Thumb
instructions. If offset is omitted, an offset of zero is assumed.
Operation
LDREX loads data from memory.
• If the physical address has the Shared TLB attribute, LDREX tags the physical address as exclusive
access for the current processor, and clears any exclusive access tag for this processor for any other
physical address.
• Otherwise, it tags the fact that the executing processor has an outstanding tagged physical address.
LDREXB and LDREXH zero extend the value loaded.
Restrictions
PC must not be used for any of Rt, Rt2, or Rn.
For ARM instructions:
• SP can be used but use of SP for Rt or Rt2 is deprecated in ARMv6T2 and above.
• For LDREXD, Rt must be an even numbered register, and not LR.
• Rt2 must be R(t+1).
• offset is not permitted.
Usage
Use LDREX and STREX to implement interprocess communication in multiple-processor and shared-
memory systems.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-360
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.48 LDREX
For reasons of performance, keep the number of instructions between corresponding LDREX and STREX
instructions to a minimum.
Note
The address used in a STREX instruction must be the same as the address in the most recently executed
LDREX instruction.
Architectures
ARM LDREX and STREX are available in ARMv6 and above.
ARM LDREXB, LDREXH, LDREXD, STREXB, STREXD, and STREXH are available in ARMv6K and above.
All these 32-bit Thumb instructions are available in ARMv6T2 and above, except that LDREXD and
STREXD are not available in the ARMv7-M architecture.
Examples
MOV r1, #0x1 ; load the ‘lock taken’ value
try
LDREX r0, [LockAddr] ; load the lock value
CMP r0, #0 ; is the lock free?
STREXEQ r0, r1, [LockAddr] ; try and claim the lock
CMPEQ r0, #0 ; did this succeed?
BNE try ; no – try again
.... ; yes – we have the lock
Related concepts
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-361
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.49 LSL
10.49 LSL
Logical Shift Left. This instruction is a preferred synonym for MOV instructions with shifted register
operands.
Syntax
LSL{S}{cond} Rd, Rm, Rs
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rm
is the register holding the first operand. This operand is shifted left.
Rs
is a register holding a shift value to apply to the value in Rm. Only the least significant byte is
used.
sh
is a constant shift. The range of values permitted is 0-31.
Operation
LSL provides the value of a register multiplied by a power of two, inserting zeros into the vacated bit
positions.
Caution
Do not use the S suffix when using PC as Rd in User mode or System mode. The assembler cannot warn
you about this because it has no information about what the processor mode is likely to be at execution
time.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-362
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.49 LSL
You cannot use PC for Rd or any operand in the LSL instruction if it has a register-controlled shift.
Condition flags
If S is specified, the LSL instruction updates the N and Z flags according to the result.
The C flag is unaffected if the shift value is 0. Otherwise, the C flag is updated to the last bit shifted out.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
LSLS Rd, Rm, #sh
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
LSL{cond} Rd, Rm, #sh
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
LSLS Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used outside an IT block.
LSL{cond} Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used inside an IT block.
Architectures
This ARM instruction is available in all architectures.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv4T and above.
Example
LSLS r1, r2, r3
Related references
10.55 MOV on page 10-370.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-363
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.50 LSR
10.50 LSR
Logical Shift Right. This instruction is a preferred synonym for MOV instructions with shifted register
operands.
Syntax
LSR{S}{cond} Rd, Rm, Rs
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rm
is the register holding the first operand. This operand is shifted right.
Rs
is a register holding a shift value to apply to the value in Rm. Only the least significant byte is
used.
sh
is a constant shift. The range of values permitted is 1-32.
Operation
LSR provides the unsigned value of a register divided by a variable power of two, inserting zeros into the
vacated bit positions.
Caution
Do not use the S suffix when using PC as Rd in User mode or System mode. The assembler cannot warn
you about this because it has no information about what the processor mode is likely to be at execution
time.
You cannot use PC for Rd or any operand in the LSR instruction if it has a register-controlled shift.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-364
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.50 LSR
Condition flags
If S is specified, the instruction updates the N and Z flags according to the result.
The C flag is unaffected if the shift value is 0. Otherwise, the C flag is updated to the last bit shifted out.
16-bit instructions
The following forms of these instructions are available in Thumb code, and are 16-bit instructions:
LSRS Rd, Rm, #sh
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
LSR{cond} Rd, Rm, #sh
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
LSRS Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used outside an IT block.
LSR{cond} Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used inside an IT block.
Architectures
This ARM instruction is available in all architectures.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv4T and above.
Example
LSR r4, r5, r6
Related references
10.55 MOV on page 10-370.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-365
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.51 MCR and MCR2
Syntax
MCR{cond} coproc, #opcode1, Rt, CRn, CRm{, #opcode2}
where:
cond
is an optional condition code. In ARM code, cond is not permitted for MCR2.
coproc
is the name of the coprocessor the instruction is for. The standard name is pn, where n is an
integer in the range 0 to 15.
opcode1
is a 3-bit coprocessor-specific opcode.
opcode2
is an optional 3-bit coprocessor-specific opcode.
Rt
is an ARM source register. Rt must not be PC.
CRn, CRm
are coprocessor registers.
Usage
The use of these instructions depends on the coprocessor. See the coprocessor documentation for details.
Architectures
The MCR ARM instruction is available in all versions of the ARM architecture.
The MCR2 ARM instruction is available in ARMv5T and above.
These 32-bit Thumb instructions are available in ARMv6T2 and above.
There are no 16-bit versions of these instructions in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-366
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.52 MCRR and MCRR2
Syntax
MCRR{cond} coproc, #opcode, Rt, Rt2, CRn
where:
cond
is an optional condition code. In ARM code, cond is not permitted for MCRR2.
coproc
is the name of the coprocessor the instruction is for. The standard name is pn, where n is an
integer in the range 0 to 15.
opcode
is a 4-bit coprocessor-specific opcode.
Rt, Rt2
are ARM source registers. Rt and Rt2 must not be PC.
CRn
is a coprocessor register.
Usage
The use of these instructions depends on the coprocessor. See the coprocessor documentation for details.
Architectures
The MCRR ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
The MCRR2 ARM instruction is available in ARMv6 and above.
These 32-bit Thumb instructions are available in ARMv6T2 and above.
There are no 16-bit versions of these instructions in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-367
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.53 MLA
10.53 MLA
Multiply-Accumulate with signed or unsigned 32-bit operands, giving the least significant 32 bits of the
result.
Syntax
MLA{S}{cond} Rd, Rn, Rm, Ra
where:
cond
is an optional condition code.
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rn, Rm
are registers holding the values to be multiplied.
Ra
is a register holding the value to be added.
Operation
The MLA instruction multiplies the values from Rn and Rm, adds the value from Ra, and places the least
significant 32 bits of the result in Rd.
Register restrictions
Rn must be different from Rd in architectures before ARMv6.
Condition flags
If S is specified, the MLA instruction:
• Updates the N and Z flags according to the result.
• Corrupts the C and V flag in ARMv4.
• Does not affect the C or V flag in ARMv5T and above.
Architectures
The MLA ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
Example
MLA r10, r2, r1, r5
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-368
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.54 MLS
10.54 MLS
Multiply-Subtract, with signed or unsigned 32-bit operands, giving the least significant 32 bits of the
result.
Syntax
MLS{cond} Rd, Rn, Rm, Ra
where:
cond
is an optional condition code.
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rn, Rm
are registers holding the values to be multiplied.
Ra
is a register holding the value to be subtracted from.
Operation
The MLS instruction multiplies the values in Rn and Rm, subtracts the result from the value in Ra, and
places the least significant 32 bits of the final result in Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Architectures
The MLS ARM instruction is available in ARMv6T2 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
Example
MLS r4, r5, r6, r7
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-369
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.55 MOV
10.55 MOV
Move.
Syntax
MOV{S}{cond} Rd, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Operand2
is a flexible second operand.
imm16
is any value in the range 0-65535.
Operation
The MOV instruction copies the value of Operand2 into Rd.
In certain circumstances, the assembler can substitute MVN for MOV, or MOV for MVN. Be aware of this when
reading disassembly listings.
You can use SP for Rd or Rm. But this is deprecated except for the following cases:
• MOV SP, Rm when Rm is not PC or SP.
• MOV Rd, SP when Rd is not PC or SP.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-370
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.55 MOV
Note
• You cannot use PC for Rd in MOV Rd, #imm16 if the #imm16 value is not a permitted Operand2 value.
You can use PC in forms with Operand2 without register-controlled shift.
• The deprecation of PC and SP in ARM instructions only applies to ARMv6T2 and above.
If you use PC as Rm, the value used is the address of the instruction plus 8.
If you use PC as Rd:
• Execution branches to the address corresponding to the result.
• If you use the S suffix, see the SUBS pc,lr instruction.
Condition flags
If S is specified, the instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
MOVS Rd, #imm
Rd must be a Lo register. imm range 0-255. This form can only be used outside an IT block.
MOV{cond} Rd, #imm
Rd must be a Lo register. imm range 0-255. This form can only be used inside an IT block.
MOVS Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
MOV{cond} Rd, Rm
In architectures before ARMv6, either Rd or Rm, or both, must be a Hi register. In ARMv6 and
above, this restriction does not apply.
Architectures
The #imm16 form of the ARM instruction is available in ARMv6T2 and above. The other forms of the
ARM instruction are available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in all T variants of the ARM architecture.
Related concepts
4.4 Load immediate values using MOV and MVN on page 4-61.
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-371
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.56 MOV32 pseudo-instruction
Syntax
MOV32{cond} Rd, expr
where:
cond
is an optional condition code.
Rd
is the register to be loaded. Rd must not be SP or PC.
expr
can be any one of the following:
symbol
A label in this or another program area.
#constant
Any 32-bit immediate value.
symbol + constant
A label plus a 32-bit immediate value.
Usage
MOV32 always generates two 32-bit instructions, a MOV, MOVT pair. This enables you to load any 32-bit
immediate, or to access the whole 32-bit address space.
The main purposes of the MOV32 pseudo-instruction are:
• To generate literal constants when an immediate value cannot be generated in a single instruction.
• To load a PC-relative or external address into a register. The address remains valid regardless of
where the linker places the ELF section containing the MOV32.
Note
An address loaded in this way is fixed at link time, so the code is not position-independent.
MOV32 sets the Thumb bit (bit 0) of the address if the label referenced is in Thumb code.
Architectures
This pseudo-instruction is available in ARMv6T2 and above in both ARM and Thumb.
Examples
MOV32 r3, #0xABCDEF12 ; loads 0xABCDEF12 into R3
MOV32 r1, Trigger+12 ; loads the address that is 12 bytes
; higher than the address Trigger into R1
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-372
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.57 MOVT
10.57 MOVT
Move Top.
Syntax
MOVT{cond} Rd, #imm16
where:
cond
is an optional condition code.
Rd
is the destination register.
imm16
is a 16-bit immediate value.
Usage
MOVT writes imm16 to Rd[31:16], without affecting Rd[15:0].
You can generate any 32-bit immediate with a MOV, MOVT instruction pair. The assembler implements the
MOV32 pseudo-instruction for convenient generation of this instruction pair.
Register restrictions
You cannot use PC in ARM or Thumb instructions.
You can use SP for Rd in ARM instructions but this is deprecated.
You cannot use SP in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6T2 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.56 MOV32 pseudo-instruction on page 10-372.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-373
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.58 MRC and MRC2
Syntax
MRC{cond} coproc, #opcode1, Rt, CRn, CRm{, #opcode2}
where:
cond
is an optional condition code. In ARM code, cond is not permitted for MRC2.
coproc
is the name of the coprocessor the instruction is for. The standard name is pn, where n is an
integer in the range 0 to 15.
opcode1
is a 3-bit coprocessor-specific opcode.
opcode2
is an optional 3-bit coprocessor-specific opcode.
Rt
is the ARM destination register. Rt must not be PC.
Rt can be APSR_nzcv. This means that the coprocessor executes an instruction that changes the
value of the condition flags in the APSR.
CRn, CRm
are coprocessor registers.
Usage
The use of these instructions depends on the coprocessor. See the coprocessor documentation for details.
Architectures
The MRC ARM instruction is available in all versions of the ARM architecture.
The MRC2 ARM instruction is available in ARMv5T and above.
These 32-bit Thumb instructions are available in ARMv6T2 and above.
There are no 16-bit versions of these instructions in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-374
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.59 MRRC and MRRC2
Syntax
MRRC{cond} coproc, #opcode, Rt, Rt2, CRm
where:
cond
is an optional condition code. In ARM code, cond is not permitted for MRRC2.
coproc
is the name of the coprocessor the instruction is for. The standard name is pn, where n is an
integer in the range 0 to 15.
opcode
is a 4-bit coprocessor-specific opcode.
Rt, Rt2
are ARM destination registers. Rt and Rt2 must not be PC.
CRm
is a coprocessor register.
Usage
The use of these instructions depends on the coprocessor. See the coprocessor documentation for details.
Architectures
The MRRC ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
The MRRC2 ARM instruction is available in ARMv6 and above.
These 32-bit Thumb instructions are available in ARMv6T2 and above.
There are no 16-bit versions of these instructions in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-375
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.60 MRS (PSR to general-purpose register)
Syntax
MRS{cond} Rd, psr
where:
cond
is an optional condition code.
Rd
is the destination register.
psr
is one of:
APSR
on any processor, in any mode.
CPSR
deprecated synonym for APSR and for use in Debug state, on any processor except
ARMv7-M and ARMv6-M.
SPSR
on any processor except ARMv7-M and ARMv6-M, in privileged software execution
only.
Mpsr
on ARMv7-M and ARMv6-M processors only.
Mpsr
can be any of: IPSR, EPSR, IEPSR, IAPSR, EAPSR, MSP, PSP, XPSR, PRIMASK, BASEPRI,
BASEPRI_MAX, FAULTMASK, or CONTROL.
Usage
Use MRS in combination with MSR as part of a read-modify-write sequence for updating a PSR, for
example to change processor mode, or to clear the Q flag.
In process swap code, the programmers’ model state of the process being swapped out must be saved,
including relevant PSR contents. Similarly, the state of the process being swapped in must also be
restored. These operations make use of MRS/store and load/MSR instruction sequences.
SPSR
You must not attempt to access the SPSR when the processor is in User or System mode. This is your
responsibility. The assembler cannot warn you about this, because it has no information about the
processor mode at execution time.
CPSR
ARM deprecates reading the CPSR endianness bit (E) with an MRS instruction.
The CPSR execution state bits, other than the E bit, can only be read when the processor is in Debug
state, halting debug-mode. Otherwise, the execution state bits in the CPSR read as zero.
The condition flags can be read in any mode on any processor. Use APSR if you are only interested in
accessing the condition flags in User mode.
Register restrictions
You cannot use PC for Rd in ARM instructions. You can use SP for Rd in ARM instructions but this is
deprecated in ARMv6T2 and above.
You cannot use PC or SP for Rd in Thumb instructions.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-376
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.60 MRS (PSR to general-purpose register)
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.16 Current Program Status Register on page 2-46.
Related references
10.61 MRS (system coprocessor register to ARM register) on page 10-378.
10.62 MSR (ARM register to system coprocessor register) on page 10-379.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-377
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.61 MRS (system coprocessor register to ARM register)
Syntax
MRS{cond} Rn, coproc_register
where:
cond
is an optional condition code.
coproc_register
is the name of the coprocessor register.
special_register
is the name of the coprocessor register that can be written to APSR_nzcv. This is only possible
for the coprocessor register DBGDSCRint.
Rn
is the ARM destination register. Rn must not be PC.
Usage
You can use this pseudo-instruction to read CP14 or CP15 coprocessor registers, with the exception of
write-only registers. A complete list of the applicable coprocessor register names is in the ARMv7-AR
Architecture Reference Manual. For example:
MRS R1, SCTLR ; writes the contents of the CP15 coprocessor
; register SCTLR into R1
Architectures
This pseudo-instruction is available in ARMv7-R in ARM and 32-bit Thumb code.
There is no 16-bit version of this pseudo-instruction in Thumb.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.62 MSR (ARM register to system coprocessor register) on page 10-379.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.8 Condition code suffixes on page 10-289.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-378
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.62 MSR (ARM register to system coprocessor register)
Syntax
MSR{cond} coproc_register, Rn
where:
cond
is an optional condition code.
coproc_register
is the name of the coprocessor register.
Rn
is the ARM source register. Rn must not be PC.
Usage
You can use this pseudo-instruction to write to any CP14 or CP15 coprocessor writable register. A
complete list of the applicable coprocessor register names is in the ARMv7-AR Architecture Reference
Manual. For example:
MSR SCTLR, R1 ; writes the contents of R1 into the CP15
; coprocessor register SCTLR
Architectures
This pseudo-instruction is available in ARMv7-R in ARM and 32-bit Thumb code.
There is no 16-bit version of this pseudo-instruction in Thumb.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.61 MRS (system coprocessor register to ARM register) on page 10-378.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.8 Condition code suffixes on page 10-289.
10.147 SYS on page 10-492.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-379
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.63 MSR (general-purpose register to PSR)
Syntax
MSR{cond} APSR_flags, Rm
where:
cond
is an optional condition code.
flags
specifies the APSR flags to be moved. flags can be one or more of:
nzcvq
ALU flags field mask, PSR[31:27] (User mode)
g
SIMD GE flags field mask, PSR[19:16] (User mode).
Rm
is the source register. Rm must not be PC.
Syntax
You can also use the following syntax on architectures other than ARMv7-M and ARMv6-M:
MSR{cond} APSR_flags, #constant
MSR{cond} psr_fields, Rm
where:
cond
is an optional condition code.
flags
specifies the APSR flags to be moved. flags can be one or more of:
nzcvq
ALU flags field mask, PSR[31:27] (User mode)
g
SIMD GE flags field mask, PSR[19:16] (User mode).
constant
is an expression evaluating to a numeric value. The value must correspond to an 8-bit pattern
rotated by an even number of bits within a 32-bit word. Not available in Thumb.
Rm
is the source register. Rm must not be PC.
psr
is one of:
CPSR
for use in Debug state, also deprecated synonym for APSR
SPSR
on any processor, in privileged software execution only.
fields
specifies the SPSR or CPSR fields to be moved. fields can be one or more of:
c
control field mask byte, PSR[7:0] (privileged software execution)
x
extension field mask byte, PSR[15:8] (privileged software execution)
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-380
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.63 MSR (general-purpose register to PSR)
s
status field mask byte, PSR[23:16] (privileged software execution)
f
flags field mask byte, PSR[31:24] (privileged software execution).
Syntax
You can also use the following syntax on ARMv7-M and ARMv6-M only:
MSR{cond} psr, Rm
where:
cond
is an optional condition code.
Rm
is the source register. Rm must not be PC.
psr
can be any of: APSR, IPSR, EPSR, IEPSR, IAPSR, EAPSR, XPSR, MSP, PSP, PRIMASK, BASEPRI,
BASEPRI_MAX, FAULTMASK, or CONTROL.
Usage
In User mode:
• Use APSR to access the condition flags, Q, or GE bits.
• Writes to unallocated, privileged or execution state bits in the CPSR are ignored. This ensures that
User mode programs cannot change to privileged software execution.
ARM deprecates using MSR to change the endianness bit (E) of the CPSR, in any mode.
You must not attempt to access the SPSR when the processor is in User or System mode.
Register restrictions
You cannot use PC in ARM instructions. You can use SP for Rm in ARM instructions but this is
deprecated in ARMv6T2 and above.
You cannot use PC or SP in Thumb instructions.
Condition flags
This instruction updates the flags explicitly if the APSR_nzcvq or CPSR_f field is specified.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.61 MRS (system coprocessor register to ARM register) on page 10-378.
10.62 MSR (ARM register to system coprocessor register) on page 10-379.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-381
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.64 MUL
10.64 MUL
Multiply with signed or unsigned 32-bit operands, giving the least significant 32 bits of the result.
Syntax
MUL{S}{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rn, Rm
are registers holding the values to be multiplied.
Operation
The MUL instruction multiplies the values from Rn and Rm, and places the least significant 32 bits of the
result in Rd.
Register restrictions
Rn must be different from Rd in architectures before ARMv6.
Condition flags
If S is specified, the MUL instruction:
• Updates the N and Z flags according to the result.
• Corrupts the C and V flag in ARMv4.
• Does not affect the C or V flag in ARMv5T and above.
16-bit instructions
The following forms of the MUL instruction are available in Thumb code, and are 16-bit instructions:
MULS Rd, Rn, Rd
Rd and Rn must both be Lo registers. This form can only be used outside an IT block.
MUL{cond} Rd, Rn, Rd
Rd and Rn must both be Lo registers. This form can only be used inside an IT block.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
MUL is available in a 32-bit encoding in Thumb in ARMv6T2 and above. MULS is not available in a 32-bit
encoding in Thumb.
This 16-bit Thumb instruction is available in all T variants of the ARM architecture.
Examples
MUL r10, r2, r5
MULS r0, r2, r2
MULLT r2, r3, r2
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-382
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.64 MUL
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-383
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.65 MVN
10.65 MVN
Move Not.
Syntax
MVN{S}{cond} Rd, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Operand2
is a flexible second operand.
Operation
The MVN instruction takes the value of Operand2, performs a bitwise logical NOT operation on the value,
and places the result into Rd.
In certain circumstances, the assembler can substitute MVN for MOV, or MOV for MVN. Be aware of this when
reading disassembly listings.
Note
The deprecation of PC and SP in ARM instructions only applies to ARMv6T2 and above.
If you use PC as Rm, the value used is the address of the instruction plus 8.
If you use PC as Rd:
• Execution branches to the address corresponding to the result.
• If you use the S suffix, see the SUBS pc,lr instruction.
Condition flags
If S is specified, the instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-384
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.65 MVN
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
MVNS Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
MVN{cond} Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in all T variants of the ARM architecture.
Correct example
MVNNE r11, #0xF000000B ; ARM only. This immediate value is not available in Thumb.
Incorrect example
MVN pc,r3,ASR r0 ; PC not permitted with register-controlled shift
Related concepts
4.4 Load immediate values using MOV and MVN on page 4-61.
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-385
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.66 NEG pseudo-instruction
Syntax
NEG{cond} Rd, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register containing the value that is subtracted from zero.
Operation
The NEG pseudo-instruction negates the value in one register and stores the result in a second register.
NEG{cond} Rd, Rm assembles to RSBS{cond} Rd, Rm, #0.
Architectures
The ARM encoding of this pseudo-instruction is available in all versions of the ARM architecture.
The 32-bit Thumb encoding of this pseudo-instruction is available in ARMv6T2 and later.
Register restrictions
In ARM instructions, using SP or PC for Rd or Rm is deprecated. In Thumb instructions, you cannot use
SP or PC for Rd or Rm.
Condition flags
This pseudo-instruction updates the condition flags, based on the result.
Related references
10.10 ADD on page 10-292.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-386
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.67 NOP
10.67 NOP
No Operation.
Syntax
NOP{cond}
where:
cond
is an optional condition code.
Usage
NOP does nothing. If NOP is not implemented as a specific instruction on your target architecture, the
assembler treats it as a pseudo-instruction and generates an alternative instruction that does nothing, such
as MOV r0, r0 (ARM) or MOV r8, r8 (Thumb).
NOP is not necessarily a time-consuming NOP. The processor might remove it from the pipeline before it
reaches the execution stage.
You can use NOP for padding, for example to place the following instruction on a 64-bit boundary in
ARM, or a 32-bit boundary in Thumb.
Architectures
This ARM instruction is available in ARMv6K and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6T2 and above.
NOP is available on all other ARM and Thumb architectures as a pseudo-instruction.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-387
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.68 ORN (Thumb only)
Syntax
ORN{S}{cond} Rd, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Operation
The ORN Thumb instruction performs an OR operation on the bits in Rn with the complements of the
corresponding bits in the value of Operand2.
In certain circumstances, the assembler can substitute ORN for ORR, or ORR for ORN. Be aware of this when
reading disassembly listings.
Use of PC
You cannot use PC (R15) for Rd or any operand in the ORN instruction.
Condition flags
If S is specified, the ORN instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
Examples
ORN r7, r11, lr, ROR #4
ORNS r7, r11, lr, ASR #32
Architectures
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no ARM or 16-bit Thumb ORN instruction.
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-388
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.69 ORR
10.69 ORR
Logical OR.
Syntax
ORR{S}{cond} Rd, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Operation
The ORR instruction performs bitwise OR operations on the values in Rn and Operand2.
In certain circumstances, the assembler can substitute ORN for ORR, or ORR for ORN. Be aware of this when
reading disassembly listings.
Condition flags
If S is specified, the ORR instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
16-bit instructions
The following forms of the ORR instruction are available in Thumb code, and are 16-bit instructions:
ORRS Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used outside an IT block.
ORR{cond} Rd, Rd, Rm
Rd and Rm must both be Lo registers. This form can only be used inside an IT block.
It does not matter if you specify ORR{S} Rd, Rm, Rd. The instruction is the same.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-389
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.69 ORR
Example
ORREQ r2,r0,r5
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-390
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.70 PKHBT and PKHTB
Syntax
PKHBT{cond} {Rd}, Rn, Rm{, LSL #leftshift}
where:
PKHBT
Combines bits[15:0] of Rn with bits[31:16] of the shifted value from Rm.
PKHTB
Combines bits[31:16] of Rn with bits[15:0] of the shifted value from Rm.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Rm
is the register holding the first operand.
leftshift
is in the range 0 to 31.
rightshift
is in the range 1 to 32.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
These instructions do not change the flags.
Architectures
These ARM instructions are available in ARMv6 and above.
These 32-bit Thumb instructions are available in ARMv6T2 and above. For the ARMv7-M architecture,
they are only available in an ARMv7E-M implementation.
There are no 16-bit versions of these instructions in Thumb.
Correct examples
PKHBT r0, r3, r5 ; combine the bottom halfword of R3
; with the top halfword of R5
PKHBT r0, r3, r5, LSL #16 ; combine the bottom halfword of R3
; with the bottom halfword of R5
PKHTB r0, r3, r5, ASR #16 ; combine the top halfword of R3
; with the top halfword of R5
You can also scale the second operand by using different values of shift.
Incorrect example
PKHBTEQ r4, r5, r1, ASR #8 ; ASR not permitted with PKHBT
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-391
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.70 PKHBT and PKHTB
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-392
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.71 PLD and PLI
Syntax
PLtype{cond} [Rn {, #offset}]
PLtype{cond} label
where:
type
can be one of:
D
Data address.
I
Instruction address.
cond
is an optional condition code.
Note
cond is permitted only in Thumb code, using a preceding IT instruction. This is an
unconditional instruction in ARM code and you must not use cond.
Rn
is the register on which the memory address is based.
offset
is an immediate offset. If offset is omitted, the address is the value in Rn.
Rm
is a register containing a value to be used as the offset.
shift
is an optional shift.
label
is a PC-relative expression.
Range of offsets
The offset is applied to the value in Rn before the preload takes place. The result is used as the memory
address for the preload. The range of offsets permitted is:
• –4095 to +4095 for ARM instructions.
• –255 to +4095 for Thumb instructions, when Rn is not PC.
• –4095 to +4095 for Thumb instructions, when Rn is PC.
The assembler calculates the offset from the PC for you. The assembler generates an error if label is out
of range.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-393
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.71 PLD and PLI
Register restrictions
Rm must not be PC. For Thumb instructions Rm must also not be SP.
Rn must not be PC for Thumb instructions of the syntax PLtype{cond} [Rn, ±Rm{, #shift}].
Architectures
ARM PLD is available in ARMv5TE and above.
The 32-bit Thumb encoding of PLD is available in ARMv6T2 and above.
PLI is available only in ARMv7 and above.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-394
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.72 POP
10.72 POP
Pop registers off a full descending stack.
Syntax
POP{cond} reglist
where:
cond
is an optional condition code.
reglist
is a non-empty list of registers, enclosed in braces. It can contain register ranges. It must be
comma separated if it contains more than one register or register range.
Operation
POP is a synonym for LDMIA sp! reglist. POP is the preferred mnemonic.
Note
LDM and LDMFD are synonyms of LDMIA.
Registers are stored on the stack in numerical order, with the lowest numbered register at the lowest
address.
Thumb instructions
A subset of these instructions are available in the Thumb instruction set.
The following restriction applies to the 16-bit POP instruction:
• reglist can only include the Lo registers and the PC.
Example
POP {r0,r10,pc} ; no 16-bit version available
Related references
10.41 LDM on page 10-342.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-395
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.72 POP
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-396
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.73 PUSH
10.73 PUSH
Push registers onto a full descending stack.
Syntax
PUSH{cond} reglist
where:
cond
is an optional condition code.
reglist
is a non-empty list of registers, enclosed in braces. It can contain register ranges. It must be
comma separated if it contains more than one register or register range.
Operation
PUSH is a synonym for STMDB sp!, reglist. PUSH is the preferred mnemonic.
Note
STMFD is a synonym of STMDB.
Registers are stored on the stack in numerical order, with the lowest numbered register at the lowest
address.
Thumb instructions
The following restriction applies to the 16-bit PUSH instruction:
• reglist can only include the Lo registers and the LR.
Examples
PUSH {r0,r4-r7}
PUSH {r2,lr}
Related references
10.41 LDM on page 10-342.
10.72 POP on page 10-395.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-397
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.74 QADD
10.74 QADD
Signed saturating addition.
Syntax
QADD{cond} {Rd}, Rm, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the registers holding the operands.
Operation
The QADD instruction adds the values in Rm and Rn. It saturates the result to the signed range –231 ≤ x ≤
231–1.
Note
All values are treated as two’s complement signed integers by this instruction.
Register restrictions
You cannot use PC for any operand.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs, this instruction sets the Q flag. To read the state of the Q flag, use an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
QADD r0, r1, r9
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-398
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.75 QADD8
10.75 QADD8
Signed saturating parallel byte-wise addition.
Syntax
QADD8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs four signed integer additions on the corresponding bytes of the operands and
writes the results into the corresponding bytes of the destination. It saturates the results to the signed
range –27 ≤ x ≤ 27 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-399
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.76 QADD16
10.76 QADD16
Signed saturating parallel halfword-wise addition.
Syntax
QADD16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs two signed integer additions on the corresponding halfwords of the operands
and writes the results into the corresponding halfwords of the destination. It saturates the results to the
signed range –215 ≤ x ≤ 215 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-400
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.77 QASX
10.77 QASX
Signed saturating parallel add and subtract halfwords with exchange.
Syntax
QASX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs an addition on the
two top halfwords of the operands and a subtraction on the bottom two halfwords. It writes the results
into the corresponding halfwords of the destination. It saturates the results to the signed range –215 ≤ x ≤
215 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-401
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.78 QDADD
10.78 QDADD
Signed saturating Double and Add.
Syntax
QDADD{cond} {Rd}, Rm, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the registers holding the operands.
Operation
QDADD calculates SAT(Rm + SAT(Rn * 2)). It saturates the result to the signed range –231 ≤ x ≤ 231–1.
Saturation can occur on the doubling operation, on the addition, or on both. If saturation occurs on the
doubling but not on the addition, the Q flag is set but the final result is unsaturated.
Note
All values are treated as two’s complement signed integers by this instruction.
Register restrictions
You cannot use PC for any operand.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs, this instruction sets the Q flag. To read the state of the Q flag, use an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-402
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.79 QDSUB
10.79 QDSUB
Signed saturating Double and Subtract.
Syntax
QDSUB{cond} {Rd}, Rm, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the registers holding the operands.
Operation
QDSUB calculates SAT(Rm - SAT(Rn * 2)). It saturates the result to the signed range –231 ≤ x ≤ 231–1.
Saturation can occur on the doubling operation, on the subtraction, or on both. If saturation occurs on the
doubling but not on the subtraction, the Q flag is set but the final result is unsaturated.
Note
All values are treated as two’s complement signed integers by this instruction.
Register restrictions
You cannot use PC for any operand.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs, this instruction sets the Q flag. To read the state of the Q flag, use an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
QDSUBLT r9, r0, r1
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-403
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.80 QSAX
10.80 QSAX
Signed saturating parallel subtract and add halfwords with exchange.
Syntax
QSAX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs a subtraction on the
two top halfwords of the operands and an addition on the bottom two halfwords. It writes the results into
the corresponding halfwords of the destination. It saturates the results to the signed range –215 ≤ x ≤ 215
–1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-404
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.81 QSUB
10.81 QSUB
Signed saturating Subtract.
Syntax
QSUB{cond} {Rd}, Rm, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the registers holding the operands.
Operation
The QSUB instruction subtracts the value in Rn from the value in Rm. It saturates the result to the signed
range –231 ≤ x ≤ 231–1.
Note
All values are treated as two’s complement signed integers by this instruction.
Register restrictions
You cannot use PC for any operand.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs, this instruction sets the Q flag. To read the state of the Q flag, use an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-405
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.82 QSUB8
10.82 QSUB8
Signed saturating parallel byte-wise subtraction.
Syntax
QSUB8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each byte of the second operand from the corresponding byte of the first
operand and writes the results into the corresponding bytes of the destination. It saturates the results to
the signed range –27 ≤ x ≤ 27 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-406
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.83 QSUB16
10.83 QSUB16
Signed saturating parallel halfword-wise subtraction.
Syntax
QSUB16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each halfword of the second operand from the corresponding halfword of the
first operand and writes the results into the corresponding halfwords of the destination. It saturates the
results to the signed range –215 ≤ x ≤ 215 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related concepts
2.15 The Q flag on page 2-45.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-407
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.84 RBIT
10.84 RBIT
Reverse the bit order in a 32-bit word.
Syntax
RBIT{cond} Rd, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the operand.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6T2 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Example
RBIT r7, r8
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-408
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.85 REV
10.85 REV
Reverse the byte order in a word.
Syntax
REV{cond} Rd, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the operand.
Usage
You can use this instruction to change endianness. REV converts 32-bit big-endian data into little-endian
data or 32-bit little-endian data into big-endian data.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
16-bit instructions
The following form of this instruction is available in Thumb code, and is a 16-bit instruction:
REV Rd, Rm
Rd and Rm must both be Lo registers.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6 and above.
Example
REV r3, r7
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-409
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.86 REV16
10.86 REV16
Reverse the byte order in each halfword independently.
Syntax
REV16{cond} Rd, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the operand.
Usage
You can use this instruction to change endianness. REV16 converts 16-bit big-endian data into little-
endian data or 16-bit little-endian data into big-endian data.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
16-bit instructions
The following form of this instruction is available in Thumb code, and is a 16-bit instruction:
REV16 Rd, Rm
Rd and Rm must both be Lo registers.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6 and above.
Example
REV16 r0, r0
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-410
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.87 REVSH
10.87 REVSH
Reverse the byte order in the bottom halfword, and sign extend to 32 bits.
Syntax
REVSH{cond} Rd, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the operand.
Usage
You can use this instruction to change endianness. REVSH converts either:
• 16-bit signed big-endian data into 32-bit signed little-endian data.
• 16-bit signed little-endian data into 32-bit signed big-endian data.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
16-bit instructions
The following form of this instruction is available in Thumb code, and is a 16-bit instruction:
REVSH Rd, Rm
Rd and Rm must both be Lo registers.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6 and above.
Example
REVSH r0, r5 ; Reverse Signed Halfword
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-411
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.88 RFE
10.88 RFE
Return From Exception.
Syntax
RFE{addr_mode}{cond} Rn{!}
where:
addr_mode
is any one of the following:
IA
Increment address After each transfer (Full Descending stack)
IB
Increment address Before each transfer (ARM only)
DA
Decrement address After each transfer (ARM only)
DB
Decrement address Before each transfer.
If addr_mode is omitted, it defaults to Increment After.
cond
is an optional condition code.
Note
cond is permitted only in Thumb code, using a preceding IT instruction. This is an
unconditional instruction in ARM code.
Rn
specifies the base register. Rn must not be PC.
!
is an optional suffix. If ! is present, the final address is written back into Rn.
Usage
You can use RFE to return from an exception if you previously saved the return state using the SRS
instruction. Rn is usually the SP where the return state information was saved.
Operation
Loads the PC and the CPSR from the address contained in Rn, and the following address. Optionally
updates Rn.
Notes
RFE writes an address to the PC. The alignment of this address must be correct for the instruction set in
use after the exception return:
• For a return to ARM, the address written to the PC must be word-aligned.
• For a return to Thumb, the address written to the PC must be halfword-aligned.
• For a return to Jazelle, there are no alignment restrictions on the address written to the PC.
No special precautions are required in software to follow these rules, if you use the instruction to return
after a valid exception entry mechanism.
Where addresses are not word-aligned, RFE ignores the least significant two bits of Rn.
The time order of the accesses to individual words of memory generated by RFE is not architecturally
defined. Do not use this instruction on memory-mapped I/O locations where access order matters.
Do not use RFE in unprivileged software execution.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-412
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.88 RFE
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above, except the ARMv7-M architecture.
There is no 16-bit version of this instruction.
Example
RFE sp!
Related concepts
2.4 Processor modes, and privileged and unprivileged software execution on page 2-33.
Related references
10.125 SRS on page 10-458.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-413
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.89 ROR
10.89 ROR
Rotate Right. This instruction is a preferred synonym for MOV instructions with shifted register operands.
Syntax
ROR{S}{cond} Rd, Rm, Rs
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rm
is the register holding the first operand. This operand is shifted right.
Rs
is a register holding a shift value to apply to the value in Rm. Only the least significant byte is
used.
sh
is a constant shift. The range of values is 1-31.
Operation
ROR provides the value of the contents of a register rotated by a value. The bits that are rotated off the
right end are inserted into the vacated bit positions on the left.
Caution
Do not use the S suffix when using PC as Rd in User mode or System mode. The assembler cannot warn
you about this because it has no information about what the processor mode is likely to be at execution
time.
You cannot use PC for Rd or any operand in this instruction if it has a register-controlled shift.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-414
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.89 ROR
Condition flags
If S is specified, the instruction updates the N and Z flags according to the result.
The C flag is unaffected if the shift value is 0. Otherwise, the C flag is updated to the last bit shifted out.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
RORS Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used outside an IT block.
ROR{cond} Rd, Rd, Rs
Rd and Rs must both be Lo registers. This form can only be used inside an IT block.
Architectures
This ARM instruction is available in all architectures.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv4T and above.
Example
ROR r4, r5, r6
Related references
10.55 MOV on page 10-370.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-415
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.90 RRX
10.90 RRX
Rotate Right with Extend. This instruction is a preferred synonym for MOV instructions with shifted
register operands.
Syntax
RRX{S}{cond} Rd, Rm
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
Rd
is the destination register.
Rm
is the register holding the first operand. This operand is shifted right.
Operation
RRX provides the value of the contents of a register shifted right one bit. The old carry flag is shifted into
bit[31]. If the S suffix is present, the old bit[0] is placed in the carry flag.
Caution
Do not use the S suffix when using PC as Rd in User mode or System mode. The assembler cannot warn
you about this because it has no information about what the processor mode is likely to be at execution
time.
You cannot use PC for Rd or any operand in this instruction if it has a register-controlled shift.
Condition flags
If S is specified, the instruction updates the N and Z flags according to the result.
The C flag is unaffected if the shift value is 0. Otherwise, the C flag is updated to the last bit shifted out.
Architectures
This ARM instruction is available in all architectures.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-416
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.90 RRX
Related references
10.55 MOV on page 10-370.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-417
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.91 RSB
10.91 RSB
Reverse Subtract without carry.
Syntax
RSB{S}{cond} {Rd}, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Operation
The RSB instruction subtracts the value in Rn from the value of Operand2. This is useful because of the
wide range of options for Operand2.
In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when
reading disassembly listings.
Condition flags
If S is specified, the RSB instruction updates the N, Z, C and V flags according to the result.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-418
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.91 RSB
Example
RSB r4, r4, #1280 ; subtracts contents of R4 from 1280
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-419
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.92 RSC
10.92 RSC
Reverse Subtract with Carry.
Syntax
RSC{S}{cond} {Rd}, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Usage
The RSC instruction subtracts the value in Rn from the value of Operand2. If the carry flag is clear, the
result is reduced by one.
You can use RSC to synthesize multiword arithmetic.
In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when
reading disassembly listings.
RSC is not available in Thumb code.
Use of PC and SP
You cannot use PC for Rd or any operand in an RSC instruction that has a register-controlled shift.
Use of PC for any operand in RSC instructions without register-controlled shift, is deprecated.
If you use PC (R15) as Rn or Rm, the value used is the address of the instruction plus 8.
If you use PC as Rd:
• Execution branches to the address corresponding to the result.
• If you use the S suffix, see the SUBS pc,lr instruction.
Use of SP in RSC instructions is deprecated.
Note
The deprecation of SP and PC is only in ARMv6T2 and above.
Condition flags
If S is specified, the RSC instruction updates the N, Z, C and V flags according to the result.
Correct example
RSCSLE r0,r5,r0,LSL r4 ; conditional, flags set
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-420
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.92 RSC
Incorrect example
RSCSLE r0,pc,r0,LSL r4 ; PC not permitted with register
; controlled shift
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-421
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.93 SADD8
10.93 SADD8
Signed parallel byte-wise addition.
Syntax
SADD8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs four signed integer additions on the corresponding bytes of the operands and
writes the results into the corresponding bytes of the destination. The results are modulo 28. It sets the
APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[0]
for bits[7:0] of the result.
GE[1]
for bits[15:8] of the result.
GE[2]
for bits[23:16] of the result.
GE[3]
for bits[31:24] of the result.
It sets a GE flag to 1 to indicate that the corresponding result is greater than or equal to zero. This is
equivalent to an ADDS instruction setting the N and V condition flags to the same value, so that the GE
condition passes.
You can use these flags to control a following SEL instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-422
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.94 SADD16
10.94 SADD16
Signed parallel halfword-wise addition.
Syntax
SADD16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs two signed integer additions on the corresponding halfwords of the operands
and writes the results into the corresponding halfwords of the destination. The results are modulo 216. It
sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets a pair of GE flags to 1 to indicate that the corresponding result is greater than or equal to zero.
This is equivalent to an ADDS instruction setting the N and V condition flags to the same value, so that the
GE condition passes.
You can use these flags to control a following SEL instruction.
Note
GE[1:0] are set or cleared together, and GE[3:2] are set or cleared together.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-423
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.95 SASX
10.95 SASX
Signed parallel add and subtract halfwords with exchange.
Syntax
SASX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs an addition on the
two top halfwords of the operands and a subtraction on the bottom two halfwords. It writes the results
into the corresponding halfwords of the destination. The results are modulo 216. It sets the APSR GE
flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets a pair of GE flags to 1 to indicate that the corresponding result is greater than or equal to zero.
This is equivalent to an ADDS or SUBS instruction setting the N and V condition flags to the same value,
so that the GE condition passes.
You can use these flags to control a following SEL instruction.
Note
GE[1:0] are set or cleared together, and GE[3:2] are set or cleared together.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-424
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.95 SASX
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-425
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.96 SBC
10.96 SBC
Subtract with Carry.
Syntax
SBC{S}{cond} {Rd}, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
Usage
The SBC (Subtract with Carry) instruction subtracts the value of Operand2 from the value in Rn. If the
carry flag is clear, the result is reduced by one.
You can use SBC to synthesize multiword arithmetic.
In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when
reading disassembly listings.
Condition flags
If S is specified, the SBC instruction updates the N, Z, C and V flags according to the result.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-426
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.96 SBC
For clarity, the above examples use consecutive registers for multiword values. There is no requirement
to do this. The following, for example, is perfectly valid:
SUBS r6, r6, r9
SBCS r9, r2, r1
SBC r2, r8, r11
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-427
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.97 SBFX
10.97 SBFX
Signed Bit Field Extract.
Syntax
SBFX{cond} Rd, Rn, #lsb, #width
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the source register.
lsb
is the bit number of the least significant bit in the bitfield, in the range 0 to 31.
width
is the width of the bitfield, in the range 1 to (32–lsb).
Operation
Copies adjacent bits from one register into the least significant bits of a second register, and sign extends
to 32 bits.
Register restrictions
You cannot use PC for any register.
You can use SP in the ARM instruction but this is deprecated in ARMv6T2 and above. You cannot use
SP in the Thumb instruction.
Condition flags
This instruction does not alter any flags.
Architectures
This ARM instruction is available in ARMv6T2 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-428
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.98 SDIV
10.98 SDIV
Signed Divide.
Syntax
SDIV{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the value to be divided.
Rm
is a register holding the divisor.
Register restrictions
PC or SP cannot be used for Rd, Rn or Rm.
Architectures
This 32-bit Thumb instruction is available in ARMv7-R and ARMv7-M.
This ARM instruction is optional in ARMv7-R.
There is no 16-bit Thumb SDIV instruction.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-429
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.99 SEL
10.99 SEL
Select bytes from each operand according to the state of the APSR GE flags.
Syntax
SEL{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Rm
is the register holding the second operand.
Operation
The SEL instruction selects bytes from Rn or Rm according to the APSR GE flags:
• If GE[0] is set, Rd[7:0] come from Rn[7:0], otherwise from Rm[7:0].
• If GE[1] is set, Rd[15:8] come from Rn[15:8], otherwise from Rm[15:8].
• If GE[2] is set, Rd[23:16] come from Rn[23:16], otherwise from Rm[23:16].
• If GE[3] is set, Rd[31:24] come from Rn[31:24], otherwise from Rm[31:24].
Usage
Use the SEL instruction after one of the signed parallel instructions. You can use this to select maximum
or minimum values in multiple byte or halfword data.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
SEL r0, r4, r5
SELLT r4, r0, r4
The following instruction sequence sets each byte in R4 equal to the unsigned minimum of the
corresponding bytes of R1 and R2:
USUB8 r4, r1, r2
SEL r4, r2, r1
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-430
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.99 SEL
Related concepts
2.14 Application Program Status Register on page 2-44.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-431
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.100 SETEND
10.100 SETEND
Set the endianness bit in the CPSR, without affecting any other bits in the CPSR.
Syntax
SETEND specifier
where:
specifier
is one of:
BE
Big-endian.
LE
Little-endian.
Usage
Use SETEND to access data of different endianness, for example, to access several big-endian DMA-
formatted data fields from an otherwise little-endian application.
SETEND cannot be conditional, and is not permitted in an IT block.
Architectures
This ARM instruction is available in ARMv6 and above.
This 16-bit Thumb instruction is available in T variants of ARMv6 and above, except the ARMv6-M and
ARMv7-M architectures.
There is no 32-bit version of this instruction in Thumb.
Example
SETEND BE ; Set the CPSR E bit for big-endian accesses
LDR r0, [r2, #header]
LDR r1, [r2, #CRC32]
SETEND le ; Set the CPSR E bit for little-endian accesses
; for the rest of the application
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-432
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.101 SEV
10.101 SEV
Set Event.
Syntax
SEV{cond}
where:
cond
is an optional condition code.
Operation
This is a hint instruction. It is optional whether it is implemented or not. If it is not implemented, it
executes as a NOP. The assembler produces a diagnostic message if the instruction executes as a NOP on
the target.
SEV executes as a NOP instruction in ARMv6T2.
SEV causes an event to be signaled to all cores within a multiprocessor system. If SEV is implemented,
WFE must also be implemented.
Architectures
This ARM instruction is available in ARMv6K and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6T2 and above.
Related references
10.67 NOP on page 10-387.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-433
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.102 SHADD8
10.102 SHADD8
Signed halving parallel byte-wise addition.
Syntax
SHADD8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs four signed integer additions on the corresponding bytes of the operands,
halves the results, and writes the results into the corresponding bytes of the destination. This cannot
cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-434
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.103 SHADD16
10.103 SHADD16
Signed halving parallel halfword-wise addition.
Syntax
SHADD16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs two signed integer additions on the corresponding halfwords of the operands,
halves the results, and writes the results into the corresponding halfwords of the destination. This cannot
cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-435
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.104 SHASX
10.104 SHASX
Signed halving parallel add and subtract halfwords with exchange.
Syntax
SHASX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs an addition on the
two top halfwords of the operands and a subtraction on the bottom two halfwords. It halves the results
and writes them into the corresponding halfwords of the destination. This cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-436
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.105 SHSAX
10.105 SHSAX
Signed halving parallel subtract and add halfwords with exchange.
Syntax
SHSAX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs a subtraction on the
two top halfwords of the operands and an addition on the bottom two halfwords. It halves the results and
writes them into the corresponding halfwords of the destination. This cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-437
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.106 SHSUB8
10.106 SHSUB8
Signed halving parallel byte-wise subtraction.
Syntax
SHSUB8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each byte of the second operand from the corresponding byte of the first
operand, halves the results, and writes the results into the corresponding bytes of the destination. This
cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-438
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.107 SHSUB16
10.107 SHSUB16
Signed halving parallel halfword-wise subtraction.
Syntax
SHSUB16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each halfword of the second operand from the corresponding halfword of the
first operand, halves the results, and writes the results into the corresponding halfwords of the
destination. This cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-439
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.108 SMC
10.108 SMC
Secure Monitor Call.
Syntax
SMC{cond} #imm4
where:
cond
is an optional condition code.
imm4
is a 4-bit immediate value. This is ignored by the ARM processor, but can be used by the SMC
exception handler to determine what service is being requested.
Note
SMC was called SMI in earlier versions of the ARM assembly language. SMI instructions disassemble to
SMC, with a comment to say that this was formerly SMI.
Architectures
This ARM instruction is available in implementations of ARMv6 and above, if they have the Security
Extensions.
This 32-bit Thumb instruction is available in implementations of ARMv6T2 and above, if they have the
Security Extensions.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-440
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.109 SMLAxy
10.109 SMLAxy
Signed Multiply Accumulate, with 16-bit operands and a 32-bit result and accumulator.
Syntax
SMLA<x><y>{cond} Rd, Rn, Rm, Ra
where:
<x>
is either B or T. B means use the bottom half (bits [15:0]) of Rn, T means use the top half (bits
[31:16]) of Rn.
<y>
is either B or T. B means use the bottom half (bits [15:0]) of Rm, T means use the top half (bits
[31:16]) of Rm.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the values to be multiplied.
Ra
is the register holding the value to be added.
Operation
SMLAxy multiplies the 16-bit signed integers from the selected halves of Rn and Rm, adds the 32-bit result
to the 32-bit value in Ra, and places the result in Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, or V flags.
If overflow occurs in the accumulation, SMLAxy sets the Q flag. To read the state of the Q flag, use an MRS
instruction.
Note
SMLAxy never clears the Q flag. To clear the Q flag, use an MSR instruction.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
SMLABBNE r0, r2, r1, r10
SMLABT r0, r0, r3, r5
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-441
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.109 SMLAxy
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-442
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.110 SMLAD
10.110 SMLAD
Dual 16-bit Signed Multiply with Addition of products and 32-bit accumulation.
Syntax
SMLAD{X}{cond} Rd, Rn, Rm, Ra
where:
cond
is an optional condition code.
X
is an optional parameter. If X is present, the most and least significant halfwords of the second
operand are exchanged before the multiplications occur.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Ra
is the register holding the accumulate operand.
Operation
SMLAD multiplies the bottom halfword of Rn with the bottom halfword of Rm, and the top halfword of Rn
with the top halfword of Rm. It then adds both products to the value in Ra and stores the sum to Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
SMLADLT r1, r2, r4, r1
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-443
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.111 SMLAL
10.111 SMLAL
Signed Long Multiply, with optional Accumulate, with 32-bit operands, and 64-bit result and
accumulator.
Syntax
SMLAL{S}{cond} RdLo, RdHi, Rn, Rm
where:
S
is an optional suffix available in ARM state only. If S is specified, the condition flags are
updated on the result of the operation.
cond
is an optional condition code.
RdLo, RdHi
are the destination registers. They also hold the accumulating value. RdLo and RdHi must be
different registers
Rn, Rm
are ARM registers holding the operands.
Operation
The SMLAL instruction interprets the values from Rn and Rm as two’s complement signed integers. It
multiplies these integers, and adds the 64-bit result to the 64-bit signed integer contained in RdHi and
RdLo.
Register restrictions
Rn must be different from RdLo and RdHi in architectures before ARMv6.
Condition flags
If S is specified, this instruction:
• Updates the N and Z flags according to the result.
• Does not affect the C or V flags.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-444
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.112 SMLALD
10.112 SMLALD
Dual 16-bit Signed Multiply with Addition of products and 64-bit Accumulation.
Syntax
SMLALD{X}{cond} RdLo, RdHi, Rn, Rm
where:
X
is an optional parameter. If X is present, the most and least significant halfwords of the second
operand are exchanged before the multiplications occur.
cond
is an optional condition code.
RdLo, RdHi
are the destination registers for the 64-bit result. They also hold the 64-bit accumulate operand.
RdHi and RdLo must be different registers.
Rn, Rm
are the registers holding the operands.
Operation
SMLALD multiplies the bottom halfword of Rn with the bottom halfword of Rm, and the top halfword of Rn
with the top halfword of Rm. It then adds both products to the value in RdLo, RdHi and stores the sum to
RdLo, RdHi.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
SMLALD r10, r11, r5, r1
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-445
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.113 SMLALxy
10.113 SMLALxy
Signed Multiply-Accumulate with 16-bit operands and a 64-bit accumulator.
Syntax
SMLAL<x><y>{cond} RdLo, RdHi, Rn, Rm
where:
<x>
is either B or T. B means use the bottom half (bits [15:0]) of Rn, T means use the top half (bits
[31:16]) of Rn.
<y>
is either B or T. B means use the bottom half (bits [15:0]) of Rm, T means use the top half (bits
[31:16]) of Rm.
cond
is an optional condition code.
RdLo, RdHi
are the destination registers. They also hold the accumulate value. RdHi and RdLo must be
different registers.
Rn, Rm
are the registers holding the values to be multiplied.
Operation
SMLALxy multiplies the signed integer from the selected half of Rm by the signed integer from the selected
half of Rn, and adds the 32-bit result to the 64-bit value in RdHi and RdLo.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Note
SMLALxy cannot raise an exception. If overflow occurs on this instruction, the result wraps round without
any warning.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
SMLALTB r2, r3, r7, r1
SMLALBTVS r0, r1, r9, r2
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-446
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.114 SMLAWy
10.114 SMLAWy
Signed Multiply-Accumulate Wide, with one 32-bit operand and one 16-bit operand, and a 32-bit
accumulate value, providing the top 32 bits of the result.
Syntax
SMLAW<y>{cond} Rd, Rn, Rm, Ra
where:
<y>
is either B or T. B means use the bottom half (bits [15:0]) of Rm, T means use the top half (bits
[31:16]) of Rm.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the values to be multiplied.
Ra
is the register holding the value to be added.
Operation
SMLAWy multiplies the signed 16-bit integer from the selected half of Rm by the signed 32-bit integer from
Rn, adds the top 32 bits of the 48-bit result to the 32-bit value in Ra, and places the result in Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, or V flags.
If overflow occurs in the accumulation, SMLAWy sets the Q flag.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-447
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.115 SMLSD
10.115 SMLSD
Dual 16-bit Signed Multiply with Subtraction of products and 32-bit accumulation.
Syntax
SMLSD{X}{cond} Rd, Rn, Rm, Ra
where:
cond
is an optional condition code.
X
is an optional parameter. If X is present, the most and least significant halfwords of the second
operand are exchanged before the multiplications occur.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Ra
is the register holding the accumulate operand.
Operation
SMLSD multiplies the bottom halfword of Rn with the bottom halfword of Rm, and the top halfword of Rn
with the top halfword of Rm. It then subtracts the second product from the first, adds the difference to the
value in Ra, and stores the result to Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, this
instruction is only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
SMLSD r1, r2, r0, r7
SMLSDX r11, r10, r2, r3
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-448
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.116 SMLSLD
10.116 SMLSLD
Dual 16-bit Signed Multiply with Subtraction of products and 64-bit accumulation.
Syntax
SMLSD{X}{cond} RdLo, RdHi, Rn, Rm
where:
X
is an optional parameter. If X is present, the most and least significant halfwords of the second
operand are exchanged before the multiplications occur.
cond
is an optional condition code.
RdLo, RdHi
are the destination registers for the 64-bit result. They also hold the 64-bit accumulate operand.
RdHi and RdLo must be different registers.
Rn, Rm
are the registers holding the operands.
Operation
SMLSLD multiplies the bottom halfword of Rn with the bottom halfword of Rm, and the top halfword of Rn
with the top halfword of Rm. It then subtracts the second product from the first, adds the difference to the
value in RdLo, RdHi, and stores the result to RdLo, RdHi.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
SMLSLD r3, r0, r5, r1
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-449
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.117 SMMLA
10.117 SMMLA
Signed Most significant word Multiply with Accumulation.
Syntax
SMMLA{R}{cond} Rd, Rn, Rm, Ra
where:
R
is an optional parameter. If R is present, the result is rounded, otherwise it is truncated.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Ra
is a register holding the value to be added or subtracted from.
Operation
SMMLA multiplies the values from Rn and Rm, adds the value in Ra to the most significant 32 bits of the
product, and stores the result in Rd.
If the optional R parameter is specified, 0x80000000 is added before extracting the most significant 32
bits. This has the effect of rounding the result.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-450
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.118 SMMLS
10.118 SMMLS
Signed Most significant word Multiply with Subtraction.
Syntax
SMMLS{R}{cond} Rd, Rn, Rm, Ra
where:
R
is an optional parameter. If R is present, the result is rounded, otherwise it is truncated.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Ra
is a register holding the value to be added or subtracted from.
Operation
SMMLS multiplies the values from Rn and Rm, subtracts the product from the value in Ra shifted left by 32
bits, and stores the most significant 32 bits of the result in Rd.
If the optional R parameter is specified, 0x80000000 is added before extracting the most significant 32
bits. This has the effect of rounding the result.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-451
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.119 SMMUL
10.119 SMMUL
Signed Most significant word Multiply.
Syntax
SMMUL{R}{cond} {Rd}, Rn, Rm
where:
R
is an optional parameter. If R is present, the result is rounded, otherwise it is truncated.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Ra
is a register holding the value to be added or subtracted from.
Operation
SMMUL multiplies the 32-bit values from Rn and Rm, and stores the most significant 32 bits of the 64-bit
result to Rd.
If the optional R parameter is specified, 0x80000000 is added before extracting the most significant 32
bits. This has the effect of rounding the result.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
SMMULGE r6, r4, r3
SMMULR r2, r2, r2
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-452
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.120 SMUAD
10.120 SMUAD
Dual 16-bit Signed Multiply with Addition of products, and optional exchange of operand halves.
Syntax
SMUAD{X}{cond} {Rd}, Rn, Rm
where:
X
is an optional parameter. If X is present, the most and least significant halfwords of the second
operand are exchanged before the multiplications occur.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Operation
SMUAD multiplies the bottom halfword of Rn with the bottom halfword of Rm, and the top halfword of Rn
with the top halfword of Rm. It then adds the products and stores the sum to Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
The SMUAD instruction sets the Q flag if the addition overflows.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
SMUAD r2, r3, r2
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-453
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.121 SMULxy
10.121 SMULxy
Signed Multiply, with 16-bit operands and a 32-bit result.
Syntax
SMUL<x><y>{cond} {Rd}, Rn, Rm
where:
<x>
is either B or T. B means use the bottom half (bits [15:0]) of Rn, T means use the top half (bits
[31:16]) of Rn.
<y>
is either B or T. B means use the bottom half (bits [15:0]) of Rm, T means use the top half (bits
[31:16]) of Rm.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the values to be multiplied.
Operation
SMULxy multiplies the 16-bit signed integers from the selected halves of Rn and Rm, and places the 32-bit
result in Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
These instructions do not affect the N, Z, C, or V flags.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
SMULTBEQ r8, r7, r9
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.63 MSR (general-purpose register to PSR) on page 10-380.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-454
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.122 SMULL
10.122 SMULL
Signed Long Multiply, with 32-bit operands and 64-bit result.
Syntax
SMULL{S}{cond} RdLo, RdHi, Rn, Rm
where:
S
is an optional suffix available in ARM state only. If S is specified, the condition flags are
updated on the result of the operation.
cond
is an optional condition code.
RdLo, RdHi
are the destination registers. RdLo and RdHi must be different registers
Rn, Rm
are ARM registers holding the operands.
Operation
The SMULL instruction interprets the values from Rn and Rm as two’s complement signed integers. It
multiplies these integers and places the least significant 32 bits of the result in RdLo, and the most
significant 32 bits of the result in RdHi.
Register restrictions
Rn must be different from RdLo and RdHi in architectures before ARMv6.
Condition flags
If S is specified, this instruction:
• Updates the N and Z flags according to the result.
• Does not affect the C or V flags.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-455
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.123 SMULWy
10.123 SMULWy
Signed Multiply Wide, with one 32-bit and one 16-bit operand, providing the top 32 bits of the result.
Syntax
SMULW<y>{cond} {Rd}, Rn, Rm
where:
<y>
is either B or T. B means use the bottom half (bits [15:0]) of Rm, T means use the top half (bits
[31:16]) of Rm.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the values to be multiplied.
Operation
SMULWy multiplies the signed integer from the selected half of Rm by the signed integer from Rn, and
places the upper 32-bits of the 48-bit result in Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, or V flags.
Architectures
This ARM instruction is available in ARMv6 and above, and E variants of ARMv5T.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-456
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.124 SMUSD
10.124 SMUSD
Dual 16-bit Signed Multiply with Subtraction of products, and optional exchange of operand halves.
Syntax
SMUSD{X}{cond} {Rd}, Rn, Rm
where:
X
is an optional parameter. If X is present, the most and least significant halfwords of the second
operand are exchanged before the multiplications occur.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Operation
SMUSD multiplies the bottom halfword of Rn with the bottom halfword of Rm, and the top halfword of Rn
with the top halfword of Rm. It then subtracts the second product from the first, and stores the difference
to Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
SMUSDXNE r0, r1, r2
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-457
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.125 SRS
10.125 SRS
Store Return State onto a stack.
Syntax
SRS{addr_mode}{cond} sp{!}, #modenum
where:
addr_mode
is any one of the following:
IA
Increment address After each transfer
IB
Increment address Before each transfer (ARM only)
DA
Decrement address After each transfer (ARM only)
DB
Decrement address Before each transfer (Full Descending stack).
If addr_mode is omitted, it defaults to Increment After. You can also use stack oriented
addressing mode suffixes, for example, when implementing stacks.
cond
is an optional condition code.
Note
cond is permitted only in Thumb code, using a preceding IT instruction. This is an
unconditional instruction in ARM.
!
is an optional suffix. If ! is present, the final address is written back into the SP of the mode
specified by modenum.
modenum
specifies the number of the mode whose banked SP is used as the base register. You must use
only the defined mode numbers.
Operation
SRS stores the LR and the SPSR of the current mode, at the address contained in SP of the mode
specified by modenum, and the following word respectively. Optionally updates SP of the mode specified
by modenum. This is compatible with the normal use of the STM instruction for stack accesses.
Note
For full descending stack, you must use SRSFD or SRSDB.
Usage
You can use SRS to store return state for an exception handler on a different stack from the one
automatically selected.
Notes
Where addresses are not word-aligned, SRS ignores the least significant two bits of the specified address.
The time order of the accesses to individual words of memory generated by SRS is not architecturally
defined. Do not use this instruction on memory-mapped I/O locations where access order matters.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-458
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.125 SRS
Do not use SRS in User and System modes because these modes do not have a SPSR.
SRS is not permitted in a non-secure state if modenum specifies monitor mode.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above, except the ARMv7-M architecture.
There is no 16-bit version of this instruction.
Example
R13_usr EQU 16
SRSFD sp,#R13_usr
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
2.4 Processor modes, and privileged and unprivileged software execution on page 2-33.
Related references
10.41 LDM on page 10-342.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-459
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.126 SSAT
10.126 SSAT
Signed Saturate to any bit position, with optional shift before saturating.
Syntax
SSAT{cond} Rd, #sat, Rm{, shift}
where:
cond
is an optional condition code.
Rd
is the destination register.
sat
specifies the bit position to saturate to, in the range 1 to 32.
Rm
is the register containing the operand.
shift
is an optional shift. It must be one of the following:
ASR #n
where n is in the range 1-32 (ARM) or 1-31 (Thumb)
LSL #n
where n is in the range 0-31.
Operation
The SSAT instruction applies the specified shift, then saturates a signed value to the signed range –2sat–1 ≤
x ≤ 2sat–1 –1.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs, this instruction sets the Q flag. To read the state of the Q flag, use an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Example
SSAT r7, #16, r7, LSL #4
Related references
10.127 SSAT16 on page 10-461.
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-460
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.127 SSAT16
10.127 SSAT16
Parallel halfword Saturate.
Syntax
SSAT16{cond} Rd, #sat, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
sat
specifies the bit position to saturate to, in the range 1 to 16.
Rn
is the register holding the operand.
Operation
Halfword-wise signed saturation to any bit position.
The SSAT16 instruction saturates each signed halfword to the signed range –2sat–1 ≤ x ≤ 2sat–1 –1.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs on either halfword, this instruction sets the Q flag. To read the state of the Q flag, use
an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Correct example
SSAT16 r7, #12, r7
Incorrect example
SSAT16 r1, #16, r2, LSL #4 ; shifts not permitted with halfword
; saturations
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-461
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.128 SSAX
10.128 SSAX
Signed parallel subtract and add halfwords with exchange.
Syntax
SSAX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs a subtraction on the
two top halfwords of the operands and an addition on the bottom two halfwords. It writes the results into
the corresponding halfwords of the destination. The results are modulo 216. It sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets a pair of GE flags to 1 to indicate that the corresponding result is greater than or equal to zero.
This is equivalent to an ADDS or SUBS instruction setting the N and V condition flags to the same value,
so that the GE condition passes.
You can use these flags to control a following SEL instruction.
Note
GE[1:0] are set or cleared together, and GE[3:2] are set or cleared together.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-462
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.129 SSUB8
10.129 SSUB8
Signed parallel byte-wise subtraction.
Syntax
SSUB8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each byte of the second operand from the corresponding byte of the first
operand and writes the results into the corresponding bytes of the destination. The results are modulo 28.
It sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[0]
for bits[7:0] of the result.
GE[1]
for bits[15:8] of the result.
GE[2]
for bits[23:16] of the result.
GE[3]
for bits[31:24] of the result.
It sets a GE flag to 1 to indicate that the corresponding result is greater than or equal to zero. This is
equivalent to a SUBS instruction setting the N and V condition flags to the same value, so that the GE
condition passes.
You can use these flags to control a following SEL instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-463
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.130 SSUB16
10.130 SSUB16
Signed parallel halfword-wise subtraction.
Syntax
SSUB16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each halfword of the second operand from the corresponding halfword of the
first operand and writes the results into the corresponding halfwords of the destination. The results are
modulo 216. It sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets a pair of GE flags to 1 to indicate that the corresponding result is greater than or equal to zero.
This is equivalent to a SUBS instruction setting the N and V condition flags to the same value, so that the
GE condition passes.
You can use these flags to control a following SEL instruction.
Note
GE[1:0] are set or cleared together, and GE[3:2] are set or cleared together.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-464
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.131 STC and STC2
Syntax
op{L}{cond} coproc, CRd, [Rn]
where:
op
is one of STC or STC2.
cond
is an optional condition code.
In ARM code, cond is not permitted for STC2.
L
is an optional suffix specifying a long transfer.
coproc
is the name of the coprocessor the instruction is for. The standard name is pn, where n is an
integer in the range 0 to 15.
CRd
is the coprocessor register to store.
Rn
is the register on which the memory address is based. If PC is specified, the value used is the
address of the current instruction plus eight.
-
is an optional minus sign. If - is present, the offset is subtracted from Rn. Otherwise, the offset is
added to Rn.
offset
is an expression evaluating to a multiple of 4, in the range 0 to 1020.
!
is an optional suffix. If ! is present, the address including the offset is written back into Rn.
option
is a coprocessor option in the range 0-255, enclosed in braces.
Usage
The use of these instructions depends on the coprocessor. See the coprocessor documentation for details.
Architectures
STC is available in all versions of the ARM architecture.
Register restrictions
You cannot use PC for Rn in the pre-index and post-index instructions. These are the forms that write
back to Rn.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-465
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.131 STC and STC2
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-466
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.132 STM
10.132 STM
Store Multiple registers.
Syntax
STM{addr_mode}{cond} Rn{!}, reglist{^}
where:
addr_mode
is any one of the following:
IA
Increment address After each transfer. This is the default, and can be omitted.
IB
Increment address Before each transfer (ARM only).
DA
Decrement address After each transfer (ARM only).
DB
Decrement address Before each transfer.
You can also use the stack-oriented addressing mode suffixes, for example when implementing
stacks.
cond
is an optional condition code.
Rn
is the base register, the ARM register holding the initial address for the transfer. Rn must not be
PC.
!
is an optional suffix. If ! is present, the final address is written back into Rn.
reglist
is a list of one or more registers to be stored, enclosed in braces. It can contain register ranges. It
must be comma-separated if it contains more than one register or register range. Any
combination of registers R0 to R15 (PC) can be transferred in ARM state, but there are some
restrictions in Thumb state.
^
is an optional suffix, available in ARM state only. You must not use it in User mode or System
mode. Data is transferred into or out of the User mode registers instead of the current mode
registers.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-467
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.132 STM
16-bit instruction
A 16-bit version of this instruction is available in Thumb code.
The following restrictions apply to the 16-bit instruction:
• All registers in reglist must be Lo registers.
• Rn must be a Lo register.
• addr_mode must be omitted (or IA), meaning increment address after each transfer.
• Writeback must be specified for STM instructions.
Note
16-bit Thumb STM instructions with writeback that specify Rn as the lowest register in the reglist are
deprecated in ARMv6T2 and above.
In addition, the PUSH and POP instructions are subsets of the STM and LDM instructions and can therefore
be expressed using the STM and LDM instructions. Some forms of PUSH and POP are also 16-bit
instructions.
Correct example
STMDB r1!,{r3-r6,r11,r12}
Incorrect example
STM r5!,{r5,r4,r9} ; value stored for R5 unknown
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
6.16 Address alignment on page 6-128.
Related references
10.72 POP on page 10-395.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-468
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.133 STR (immediate offset)
Syntax
STR{type}{cond} Rt, [Rn {, #offset}] ; immediate offset
where:
type
can be any one of:
B
Byte.
H
Halfword.
-
omitted, for Word.
cond
is an optional condition code.
Rt
is the register to store.
Rn
is the register on which the memory address is based.
offset
is an offset. If offset is omitted, the address is the contents of Rn.
Rt2
is the additional register to store for doubleword operations.
Not all options are available in every instruction set and architecture.
Table 10-15 Offsets and architectures, STR, word, halfword, and byte
ARM, word or byte –4095 to 4095 –4095 to 4095 –4095 to 4095 All
Thumb 32-bit encoding, word, halfword, or byte –255 to 4095 –255 to 255 –255 to 255 T2
Thumb 32-bit encoding, doubleword –1020 to 1020 ab –1020 to 1020 ab –1020 to 1020 ab T2
ab Must be divisible by 4.
ac Rt and Rn must be in the range R0-R7.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-469
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.133 STR (immediate offset)
Table 10-15 Offsets and architectures, STR, word, halfword, and byte (continued)
Register restrictions
Rn must be different from Rt in the pre-index and post-index forms.
For Thumb instructions, you must not specify SP or PC for either Rt or Rt2.
For ARM instructions:
• Rt must be an even-numbered register.
• Rt must not be LR.
• ARM strongly recommends that you do not use R12 for Rt.
• Rt2 must be R(t + 1).
Use of PC
In ARM instructions you can use PC for Rt in STR word instructions and PC for Rn in STR instructions
with immediate offset syntax (that is the forms that do not writeback to the Rn). However, this is
deprecated in ARMv6T2 and above.
Other uses of PC are not permitted in these ARM instructions.
In Thumb code, using PC in STR instructions is not permitted.
Use of SP
You can use SP for Rn.
In ARM code, you can use SP for Rt in word instructions. You can use SP for Rt in non-word
instructions in ARM code but this is deprecated in ARMv6T2 and above.
In Thumb code, you can use SP for Rt in word instructions only. All other use of SP for Rt in this
instruction is not permitted in Thumb code.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-470
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.133 STR (immediate offset)
Example
STR r2,[r9,#consta-struc] ; consta-struc is an expression
; evaluating to a constant in
; the range 0-4095.
Related concepts
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-471
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.134 STR (register offset)
Syntax
STR{type}{cond} Rt, [Rn, ±Rm {, shift}] ; register offset
STRD{cond} Rt, Rt2, [Rn, ±Rm] ; register offset, doubleword ; ARM only
where:
type
can be any one of:
B
Byte.
H
Halfword.
-
omitted, for Word.
cond
is an optional condition code.
Rt
is the register to store.
Rn
is the register on which the memory address is based.
Rm
is a register containing a value to be used as the offset. –Rm is not permitted in Thumb code.
shift
is an optional shift.
Rt2
is the additional register to store for doubleword operations.
Not all options are available in every instruction set and architecture.
af Where +/–Rm is shown, you can use –Rm, +Rm, or Rm. Where +Rm is shown, you cannot use –Rm.
ag Rt, Rn, and Rm must all be in the range R0-R7.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-472
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.134 STR (register offset)
Register restrictions
In the pre-index and post-index forms:
• Rn must be different from Rt.
• Rn must be different from Rm in architectures before ARMv6.
Use of PC
In ARM instructions you can use PC for Rt in STR word instructions, and you can use PC for Rn in STR
instructions with register offset syntax (that is, the forms that do not writeback to the Rn). However, this
is deprecated in ARMv6T2 and above.
Other uses of PC are not permitted in ARM instructions.
Use of PC in STR Thumb instructions is not permitted.
Use of SP
You can use SP for Rn.
In ARM code, you can use SP for Rt in word instructions. You can use SP for Rt in non-word ARM
instructions but this is deprecated in ARMv6T2 and above.
You can use SP for Rm in ARM instructions but this is deprecated in ARMv6T2 and above.
In Thumb code, you can use SP for Rt in word instructions only. All other use of SP for Rt in this
instruction is not permitted in Thumb code.
Use of SP for Rm is not permitted in Thumb state.
Related concepts
6.16 Address alignment on page 6-128.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-473
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.134 STR (register offset)
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-474
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.135 STR, unprivileged
Syntax
STR{type}T{cond} Rt, [Rn {, #offset}] ; immediate offset (Thumb, 32-bit encoding
only)
where:
type
can be any one of:
B
Byte.
H
Halfword.
-
omitted, for Word.
cond
is an optional condition code.
Rt
is the register to load or store.
Rn
is the register on which the memory address is based.
offset
is an offset. If offset is omitted, the address is the value in Rn.
Rm
is a register containing a value to be used as the offset. Rm must not be PC.
shift
is an optional shift.
Operation
When these instructions are executed by privileged software, they access memory with the same
restrictions as they would have if they were executed by unprivileged software.
When executed by unprivileged software, these instructions behave in exactly the same way as the
corresponding store instruction, for example STRBT behaves in the same way as STRB.
ARM, word or byte Not available –4095 to 4095 +/–Rm LSL #0-31 All
LSR #1-32
ASR #1-32
ROR #1-31
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-475
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.135 STR, unprivileged
RRX
Thumb 32-bit encoding, word, halfword, or byte 0 to 255 Not available Not available T2
Related concepts
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-476
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.136 STREX
10.136 STREX
Store Register Exclusive.
Syntax
STREX{cond} Rd, Rt, [Rn {, #offset}]
where:
cond
is an optional condition code.
Rd
is the destination register for the returned status.
Rt
is the register to store.
Rt2
is the second register for doubleword stores.
Rn
is the register on which the memory address is based.
offset
is an optional offset applied to the value in Rn. offset is permitted only in Thumb instructions.
If offset is omitted, an offset of 0 is assumed.
Operation
STREX performs a conditional store to memory. The conditions are as follows:
• If the physical address does not have the Shared TLB attribute, and the executing processor has an
outstanding tagged physical address, the store takes place, the tag is cleared, and the value 0 is
returned in Rd.
• If the physical address does not have the Shared TLB attribute, and the executing processor does not
have an outstanding tagged physical address, the store does not take place, and the value 1 is returned
in Rd.
• If the physical address has the Shared TLB attribute, and the physical address is tagged as exclusive
access for the executing processor, the store takes place, the tag is cleared, and the value 0 is returned
in Rd.
• If the physical address has the Shared TLB attribute, and the physical address is not tagged as
exclusive access for the executing processor, the store does not take place, and the value 1 is returned
in Rd.
Restrictions
PC must not be used for any of Rd, Rt, Rt2, or Rn.
For STREX, Rd must not be the same register as Rt, Rt2, or Rn.
For ARM instructions:
• SP can be used but use of SP for any of Rd, Rt, or Rt2 is deprecated in ARMv6T2 and above.
• For STREXD, Rt must be an even numbered register, and not LR.
• Rt2 must be R(t+1).
• offset is not permitted.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-477
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.136 STREX
Usage
Use LDREX and STREX to implement interprocess communication in multiple-processor and shared-
memory systems.
For reasons of performance, keep the number of instructions between corresponding LDREX and STREX
instructions to a minimum.
Note
The address used in a STREX instruction must be the same as the address in the most recently executed
LDREX instruction.
Architectures
ARM STREX is available in ARMv6 and above.
ARM STREXB, STREXD, and STREXH are available in ARMv6K and above.
All these 32-bit Thumb instructions are available in ARMv6T2 and above, except that STREXD is not
available in the ARMv7-M architecture.
There are no 16-bit versions of these instructions.
Examples
MOV r1, #0x1 ; load the ‘lock taken’ value
try
LDREX r0, [LockAddr] ; load the lock value
CMP r0, #0 ; is the lock free?
STREXEQ r0, r1, [LockAddr] ; try and claim the lock
CMPEQ r0, #0 ; did this succeed?
BNE try ; no – try again
.... ; yes – we have the lock
Related concepts
6.16 Address alignment on page 6-128.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-478
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.137 SUB
10.137 SUB
Subtract without carry.
Syntax
SUB{S}{cond} {Rd}, Rn, Operand2
where:
S
is an optional suffix. If S is specified, the condition flags are updated on the result of the
operation.
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Operand2
is a flexible second operand.
imm12
is any value in the range 0-4095.
Operation
The SUB instruction subtracts the value of Operand2 or imm12 from the value in Rn.
In certain circumstances, the assembler can substitute one instruction for another. Be aware of this when
reading disassembly listings.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-479
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.137 SUB
Condition flags
If S is specified, the SUB instruction updates the N, Z, C and V flags according to the result.
16-bit instructions
The following forms of this instruction are available in Thumb code, and are 16-bit instructions:
SUBS Rd, Rn, Rm
Rd, Rn and Rm must all be Lo registers. This form can only be used outside an IT block.
SUB{cond} Rd, Rn, Rm
Rd, Rn and Rm must all be Lo registers. This form can only be used inside an IT block.
SUBS Rd, Rn, #imm
imm range 0-7. Rd and Rn must both be Lo registers. This form can only be used outside an IT
block.
SUB{cond} Rd, Rn, #imm
imm range 0-7. Rd and Rn must both be Lo registers. This form can only be used inside an IT
block.
SUBS Rd, Rd, #imm
imm range 0-255. Rd must be a Lo register. This form can only be used outside an IT block.
SUB{cond} Rd, Rd, #imm
imm range 0-255. Rd must be a Lo register. This form can only be used inside an IT block.
SUB{cond} SP, SP, #imm
imm range 0-508, word aligned.
Example
SUBS r8, r6, #240 ; sets the flags based on the result
For clarity, the above examples use consecutive registers for multiword values. There is no requirement
to do this. The following, for example, is perfectly valid:
SUBS r6, r6, r9
SBCS r9, r2, r1
SBC r2, r8, r11
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.138 SUBS pc, lr on page 10-481.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-480
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.138 SUBS pc, lr
Syntax
SUBS{cond} pc, lr, #imm ; ARM and Thumb code
where:
op1
is one of ADC, ADD, AND, BIC, EOR, ORN, ORR, RSB, RSC, SBC, and SUB.
op2
is one of MOV and MVN.
cond
is an optional condition code.
imm
is an immediate value. In Thumb code, it is limited to the range 0-255. In ARM code, it is a
flexible second operand.
Rn
is the first operand register. ARM deprecates the use of any register except LR.
Rm
is the optionally shifted second or only operand register.
shift
is an optional condition code.
Usage
SUBS pc, lr, #imm subtracts a value from the link register and loads the PC with the result, then copies
the SPSR to the CPSR.
You can use SUBS pc, lr, #imm to return from an exception if there is no return state on the stack. The
value of #imm depends on the exception to return from.
Notes
SUBS pc, lr, #imm writes an address to the PC. The alignment of this address must be correct for the
instruction set in use after the exception return:
• For a return to ARM, the address written to the PC must be word-aligned.
• For a return to Thumb, the address written to the PC must be halfword-aligned.
• For a return to Jazelle, there are no alignment restrictions on the address written to the PC.
No special precautions are required in software to follow these rules, if you use the instruction to return
after a valid exception entry mechanism.
In Thumb, only SUBS{cond} pc, lr, #imm is a valid instruction. MOVS pc, lr is a synonym of SUBS
pc, lr, #0. Other instructions are undefined.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-481
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.138 SUBS pc, lr
In ARM, only SUBS{cond} pc, lr, #imm and MOVS{cond} pc, lr are valid instructions. Other
instructions are deprecated in ARMv6T2 and above.
Caution
Do not use these instructions in User mode or System mode. The assembler cannot warn you about this.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above, except the ARMv7-M architecture.
There is no 16-bit version of this instruction in Thumb.
Related references
10.14 AND on page 10-301.
10.55 MOV on page 10-370.
10.3 Flexible second operand (Operand2) on page 10-282.
10.10 ADD on page 10-292.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-482
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.139 SVC
10.139 SVC
SuperVisor Call.
Syntax
SVC{cond} #imm
where:
cond
is an optional condition code.
imm
is an expression evaluating to an integer in the range:
• 0 to 224–1 (a 24-bit value) in an ARM instruction.
• 0-255 (an 8-bit value) in a Thumb instruction.
Operation
The SVC instruction causes an exception. This means that the processor mode changes to Supervisor, the
CPSR is saved to the Supervisor mode SPSR, and execution branches to the SVC vector.
imm is ignored by the processor. However, it can be retrieved by the exception handler to determine what
service is being requested.
Note
SVC was called SWI in earlier versions of the ARM assembly language. SWI instructions disassemble to
SVC, with a comment to say that this was formerly SWI.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 16-bit Thumb instruction is available in all T variants of the ARM architecture.
There is no 32-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-483
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.140 SWP and SWPB
Syntax
SWP{B}{cond} Rt, Rt2, [Rn]
where:
cond
is an optional condition code.
B
is an optional suffix. If B is present, a byte is swapped. Otherwise, a 32-bit word is swapped.
Rt
is the destination register. Rt must not be PC.
Rt2
is the source register. Rt2 can be the same register as Rt. Rt2 must not be PC.
Rn
contains the address in memory. Rn must be a different register from both Rt and Rt2. Rn must
not be PC.
Usage
You can use SWP and SWPB to implement semaphores:
• Data from memory is loaded into Rt.
• The contents of Rt2 are saved to memory.
• If Rt2 is the same register as Rt, the contents of the register are swapped with the contents of the
memory location.
Note
The use of SWP and SWPB is deprecated in ARMv6 and above. You can use LDREX and STREX instructions
to implement more sophisticated semaphores in ARMv6 and above.
Architectures
These ARM instructions are available in all versions of the ARM architecture.
There are no Thumb SWP or SWPB instructions.
Related references
10.48 LDREX on page 10-360.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-484
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.141 SXTAB
10.141 SXTAB
Sign extend Byte with Add, to extend an 8-bit value to a 32-bit value.
Syntax
SXTAB{cond} {Rd}, Rn, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the number to add.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
This instruction does the following:
1. Rotate the value from Rm right by 0, 8, 16 or 24 bits.
2. Extract bits[7:0] from the value obtained.
3. Sign extend to 32 bits.
4. Add the value from Rn.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-485
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.142 SXTAB16
10.142 SXTAB16
Sign extend two Bytes with Add, to extend two 8-bit values to two 16-bit values.
Syntax
SXTAB16{cond} {Rd}, Rn, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the number to add.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
This instruction does the following:
1. Rotate the value from Rm right by 0, 8, 16 or 24 bits.
2. Extract bits[23:16] and bits[7:0] from the value obtained.
3. Sign extend to 16 bits.
4. Add them to bits[31:16] and bits[15:0] respectively of Rn to form bits[31:16] and bits[15:0] of the
result.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-486
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.143 SXTAH
10.143 SXTAH
Sign extend Halfword with Add, to extend a 16-bit value to a 32-bit value.
Syntax
SXTAH{cond} {Rd}, Rn, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the number to add.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
This instruction does the following:
1. Rotate the value from Rm right by 0, 8, 16 or 24 bits.
2. Extract bits[15:0] from the value obtained.
3. Sign extend to 32 bits.
4. Add the value from Rn.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-487
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.144 SXTB
10.144 SXTB
Sign extend Byte, to extend an 8-bit value to a 32-bit value.
Syntax
SXTB{cond} {Rd}, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
This instruction does the following:
1. Rotates the value from Rm right by 0, 8, 16 or 24 bits.
2. Extracts bits[7:0] from the value obtained.
3. Sign extends to 32 bits.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
16-bit instructions
The following form of this instruction is available in Thumb code, and is a 16-bit instruction:
SXTB Rd, Rm
Rd and Rm must both be Lo registers.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
This 16-bit Thumb instruction is available in ARMv6 and above.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-488
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.145 SXTB16
10.145 SXTB16
Sign extend two bytes.
Syntax
SXTB16{cond} {Rd}, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
SXTB16 extends two 8-bit values to two 16-bit values. It does this by:
1. Rotating the value from Rm right by 0, 8, 16 or 24 bits.
2. Extracting bits[23:16] and bits[7:0] from the value obtained.
3. Sign extending to 16 bits each.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-489
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.146 SXTH
10.146 SXTH
Sign extend Halfword.
Syntax
SXTH{cond} {Rd}, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
SXTH extends a 16-bit value to a 32-bit value. It does this by:
1. Rotating the value from Rm right by 0, 8, 16 or 24 bits.
2. Extracting bits[15:0] from the value obtained.
3. Sign extending to 32 bits.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
16-bit instructions
The following form of this instruction is available in Thumb code, and is a 16-bit instruction:
SXTH Rd, Rm
Rd and Rm must both be Lo registers.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
This 16-bit Thumb instruction is available in ARMv6 and above.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-490
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.146 SXTH
Example
SXTH r3, r9, r4
Incorrect example
SXTH r9, r3, r2, ROR #12 ; rotation must be by 0, 8, 16, or 24.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-491
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.147 SYS
10.147 SYS
Execute system coprocessor instruction.
Syntax
SYS{cond} instruction{, Rn}
where:
cond
is an optional condition code.
instruction
is the coprocessor instruction to execute.
Rn
is an operand to the instruction. For instructions that take an argument, Rn is compulsory. For
instructions that do not take an argument, Rn is optional and if it is not specified, R0 is used. Rn
must not be PC.
Usage
You can use this pseudo-instruction to execute special coprocessor instructions such as cache, branch
predictor, and TLB operations. The instructions operate by writing to special write-only coprocessor
registers. The instruction names are the same as the write-only coprocessor register names and are listed
in the ARMv7-AR Architecture Reference Manual. For example:
SYS ICIALLUIS ; invalidates all instruction caches Inner Shareable
; to Point of Unification and also flushes branch
; target cache.
Architectures
The SYS pseudo-instruction is available in ARMv7-R in ARM and 32-bit Thumb code.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-492
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.148 TBB and TBH
Syntax
TBB [Rn, Rm]
where:
Rn
is the base register. This contains the address of the table of branch lengths. Rn must not be SP.
If PC is specified for Rn, the value used is the address of the instruction plus 4.
Rm
is the index register. This contains an index into the table.
Rm must not be PC or SP.
Operation
These instructions cause a PC-relative forward branch using a table of single byte offsets (TBB) or
halfword offsets (TBH). Rn provides a pointer to the table, and Rm supplies an index into the table. The
branch length is twice the value of the byte (TBB) or the halfword (TBH) returned from the table. The
target of the branch table must be in the same execution state.
Architectures
These 32-bit Thumb instructions are available in ARMv6T2 and above.
There are no versions of these instructions in ARM or in 16-bit Thumb encodings.
Related concepts
6.16 Address alignment on page 6-128.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-493
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.149 TEQ
10.149 TEQ
Test Equivalence.
Syntax
TEQ{cond} Rn, Operand2
where:
cond
is an optional condition code.
Rn
is the ARM register holding the first operand.
Operand2
is a flexible second operand.
Usage
This instruction tests the value in a register against Operand2. It updates the condition flags on the result,
but does not place the result in any register.
The TEQ instruction performs a bitwise Exclusive OR operation on the value in Rn and the value of
Operand2. This is the same as an EORS instruction, except that the result is discarded.
Use the TEQ instruction to test if two values are equal, without affecting the V or C flags (as CMP does).
TEQ is also useful for testing the sign of a value. After the comparison, the N flag is the logical Exclusive
OR of the sign bits of the two operands.
Register restrictions
In this Thumb instruction, you cannot use SP or PC for Rn or Operand2.
In this ARM instruction, use of SP or PC is deprecated in ARMv6T2 and above.
For ARM instructions:
• If you use PC (R15) as Rn, the value used is the address of the instruction plus 8.
• You cannot use PC for any operand in any data processing instruction that has a register-controlled
shift.
Condition flags
This instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
Architectures
This ARM instruction is available in all architectures that support the ARM instruction set.
The TEQ Thumb instruction is available in ARMv6T2 and above.
Correct example
TEQEQ r10, r9
Incorrect example
TEQ pc, r1, ROR r0 ; PC not permitted with register
; controlled shift
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-494
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.149 TEQ
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-495
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.150 TST
10.150 TST
Test bits.
Syntax
TST{cond} Rn, Operand2
where:
cond
is an optional condition code.
Rn
is the ARM register holding the first operand.
Operand2
is a flexible second operand.
Operation
This instruction tests the value in a register against Operand2. It updates the condition flags on the result,
but does not place the result in any register.
The TST instruction performs a bitwise AND operation on the value in Rn and the value of Operand2.
This is the same as an ANDS instruction, except that the result is discarded.
Register restrictions
In this Thumb instruction, you cannot use SP or PC for Rn or Operand2.
In this ARM instruction, use of SP or PC is deprecated in ARMv6T2 and above.
For ARM instructions:
• If you use PC (R15) as Rn, the value used is the address of the instruction plus 8.
• You cannot use PC for any operand in any data processing instruction that has a register-controlled
shift.
Condition flags
This instruction:
• Updates the N and Z flags according to the result.
• Can update the C flag during the calculation of Operand2.
• Does not affect the V flag.
16-bit instructions
The following form of the TST instruction is available in Thumb code, and is a 16-bit instruction:
TST Rn, Rm
Rn and Rm must both be Lo registers.
Architectures
This ARM instruction is available in all architectures that support the ARM instruction set.
The TST Thumb instruction is available in all architectures that support the Thumb instruction set.
Examples
TST r0, #0x3F8
TSTNE r1, r5, ASR r1
Related references
10.3 Flexible second operand (Operand2) on page 10-282.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-496
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.151 UADD8
10.151 UADD8
Unsigned parallel byte-wise addition.
Syntax
UADD8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs four unsigned integer additions on the corresponding bytes of the operands and
writes the results into the corresponding bytes of the destination. The results are modulo 28. It sets the
APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[0]
for bits[7:0] of the result.
GE[1]
for bits[15:8] of the result.
GE[2]
for bits[23:16] of the result.
GE[3]
for bits[31:24] of the result.
It sets a GE flag to 1 to indicate that the corresponding result overflowed, generating a carry. This is
equivalent to an ADDS instruction setting the C condition flag to 1.
You can use these flags to control a following SEL instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-497
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.152 UADD16
10.152 UADD16
Unsigned parallel halfword-wise addition.
Syntax
UADD16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs two unsigned integer additions on the corresponding halfwords of the operands
and writes the results into the corresponding halfwords of the destination. The results are modulo 216. It
sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets a pair of GE flags to 1 to indicate that the corresponding result overflowed, generating a carry.
This is equivalent to an ADDS instruction setting the C condition flag to 1.
You can use these flags to control a following SEL instruction.
Note
GE[1:0] are set or cleared together, and GE[3:2] are set or cleared together.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-498
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.153 UASX
10.153 UASX
Unsigned parallel add and subtract halfwords with exchange.
Syntax
UASX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs an addition on the
two top halfwords of the operands and a subtraction on the bottom two halfwords. It writes the results
into the corresponding halfwords of the destination. The results are modulo 216. It sets the APSR GE
flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets GE[1:0] to 1 to indicate that the subtraction gave a result greater than or equal to zero, meaning a
borrow did not occur. This is equivalent to a SUBS instruction setting the C condition flag to 1.
It sets GE[3:2] to 1 to indicate that the addition overflowed, generating a carry. This is equivalent to an
ADDS instruction setting the C condition flag to 1.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-499
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.153 UASX
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-500
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.154 UBFX
10.154 UBFX
Unsigned Bit Field Extract.
Syntax
UBFX{cond} Rd, Rn, #lsb, #width
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the source register.
lsb
is the bit number of the least significant bit in the bitfield, in the range 0 to 31.
width
is the width of the bitfield, in the range 1 to (32–lsb).
Operation
Copies adjacent bits from one register into the least significant bits of a second register, and zero extends
to 32 bits.
Register restrictions
You cannot use PC for any register.
You can use SP in the ARM instruction but this is deprecated in ARMv6T2 and above. You cannot use
SP in the Thumb instruction.
Condition flags
This instruction does not alter any flags.
Architectures
This ARM instruction is available in ARMv6T2 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-501
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.155 UDIV
10.155 UDIV
Unsigned Divide.
Syntax
UDIV{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the value to be divided.
Rm
is a register holding the divisor.
Register restrictions
PC or SP cannot be used for Rd, Rn, or Rm.
Architectures
This 32-bit Thumb instruction is available in ARMv7-R and ARMv7-M.
This ARM instruction is optional in ARMv7-R.
There is no 16-bit Thumb UDIV instruction.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-502
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.156 UHADD8
10.156 UHADD8
Unsigned halving parallel byte-wise addition.
Syntax
UHADD8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs four unsigned integer additions on the corresponding bytes of the operands,
halves the results, and writes the results into the corresponding bytes of the destination. This cannot
cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-503
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.157 UHADD16
10.157 UHADD16
Unsigned halving parallel halfword-wise addition.
Syntax
UHADD16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs two unsigned integer additions on the corresponding halfwords of the
operands, halves the results, and writes the results into the corresponding halfwords of the destination.
This cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-504
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.158 UHASX
10.158 UHASX
Unsigned halving parallel add and subtract halfwords with exchange.
Syntax
UHASX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs an addition on the
two top halfwords of the operands and a subtraction on the bottom two halfwords. It halves the results
and writes them into the corresponding halfwords of the destination. This cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-505
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.159 UHSAX
10.159 UHSAX
Unsigned halving parallel subtract and add halfwords with exchange.
Syntax
UHSAX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs a subtraction on the
two top halfwords of the operands and an addition on the bottom two halfwords. It halves the results and
writes them into the corresponding halfwords of the destination. This cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-506
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.160 UHSUB8
10.160 UHSUB8
Unsigned halving parallel byte-wise subtraction.
Syntax
UHSUB8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each byte of the second operand from the corresponding byte of the first
operand, halves the results, and writes the results into the corresponding bytes of the destination. This
cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-507
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.161 UHSUB16
10.161 UHSUB16
Unsigned halving parallel halfword-wise subtraction.
Syntax
UHSUB16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each halfword of the second operand from the corresponding halfword of the
first operand, halves the results, and writes the results into the corresponding halfwords of the
destination. This cannot cause overflow.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-508
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.162 UMAAL
10.162 UMAAL
Unsigned Multiply Accumulate Accumulate Long.
Syntax
UMAAL{cond} RdLo, RdHi, Rn, Rm
where:
cond
is an optional condition code.
RdLo, RdHi
are the destination registers for the 64-bit result. They also hold the two 32-bit accumulate
operands. RdLo and RdHi must be different registers.
Rn, Rm
are the registers holding the multiply operands.
Operation
The UMAAL instruction multiplies the 32-bit values in Rn and Rm, adds the two 32-bit values in RdHi and
RdLo, and stores the 64-bit result to RdLo, RdHi.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Examples
UMAAL r8, r9, r2, r3
UMAALGE r2, r0, r5, r3
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-509
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.163 UMLAL
10.163 UMLAL
Unsigned Long Multiply, with optional Accumulate, with 32-bit operands and 64-bit result and
accumulator.
Syntax
UMLAL{S}{cond} RdLo, RdHi, Rn, Rm
where:
S
is an optional suffix available in ARM state only. If S is specified, the condition flags are
updated based on the result of the operation.
cond
is an optional condition code.
RdLo, RdHi
are the destination registers. They also hold the accumulating value. RdLo and RdHi must be
different registers.
Rn, Rm
are ARM registers holding the operands.
Operation
The UMLAL instruction interprets the values from Rn and Rm as unsigned integers. It multiplies these
integers, and adds the 64-bit result to the 64-bit unsigned integer contained in RdHi and RdLo.
Register restrictions
Rn must be different from RdLo and RdHi in architectures before ARMv6.
Condition flags
If S is specified, this instruction:
• Updates the N and Z flags according to the result.
• Does not affect the C or V flags.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Example
UMLALS r4, r5, r3, r8
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-510
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.164 UMULL
10.164 UMULL
Unsigned Long Multiply, with 32-bit operands, and 64-bit result.
Syntax
UMULL{S}{cond} RdLo, RdHi, Rn, Rm
where:
S
is an optional suffix available in ARM state only. If S is specified, the condition flags are
updated based on the result of the operation.
cond
is an optional condition code.
RdLo, RdHi
are the destination registers. RdLo and RdHi must be different registers.
Rn, Rm
are ARM registers holding the operands.
Operation
The UMULL instruction interprets the values from Rn and Rm as unsigned integers. It multiplies these
integers and places the least significant 32 bits of the result in RdLo, and the most significant 32 bits of
the result in RdHi.
Register restrictions
Rn must be different from RdLo and RdHi in architectures before ARMv6.
Condition flags
If S is specified, this instruction:
• Updates the N and Z flags according to the result.
• Does not affect the C or V flags.
Architectures
This ARM instruction is available in all versions of the ARM architecture.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Example
UMULL r0, r4, r5, r6
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-511
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.165 UND pseudo-instruction
Syntax
UND{cond}{.W} {#expr}
where:
cond
is an optional condition code.
.W
is an optional instruction width specifier.
expr
evaluates to a numeric value. The following table shows the range and encoding of expr in the
instruction, where Y shows the locations of the bits that encode for expr and V is the 4 bits that
encode for the condition code.
If expr is omitted, the value 0 is used.
Usage
An attempt to execute an undefined instruction causes the Undefined instruction exception.
Architecturally undefined instructions are expected to remain undefined.
Disassembly
The encodings that this pseudo-instruction produces disassemble to DCI.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-512
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.166 UQADD8
10.166 UQADD8
Unsigned saturating parallel byte-wise addition.
Syntax
UQADD8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs four unsigned integer additions on the corresponding bytes of the operands and
writes the results into the corresponding bytes of the destination. It saturates the results to the unsigned
range 0 ≤ x ≤ 28 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-513
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.167 UQADD16
10.167 UQADD16
Unsigned saturating parallel halfword-wise addition.
Syntax
UQADD16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction performs two unsigned integer additions on the corresponding halfwords of the operands
and writes the results into the corresponding halfwords of the destination. It saturates the results to the
unsigned range 0 ≤ x ≤ 216 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-514
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.168 UQASX
10.168 UQASX
Unsigned saturating parallel add and subtract halfwords with exchange.
Syntax
UQASX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs an addition on the
two top halfwords of the operands and a subtraction on the bottom two halfwords. It writes the results
into the corresponding halfwords of the destination. It saturates the results to the unsigned range 0 ≤ x ≤
216 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-515
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.169 UQSAX
10.169 UQSAX
Unsigned saturating parallel subtract and add halfwords with exchange.
Syntax
UQSAX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs a subtraction on the
two top halfwords of the operands and an addition on the bottom two halfwords. It writes the results into
the corresponding halfwords of the destination. It saturates the results to the unsigned range 0 ≤ x ≤ 216 –
1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-516
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.170 UQSUB8
10.170 UQSUB8
Unsigned saturating parallel byte-wise subtraction.
Syntax
UQSUB8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each byte of the second operand from the corresponding byte of the first
operand and writes the results into the corresponding bytes of the destination. It saturates the results to
the unsigned range 0 ≤ x ≤ 28 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-517
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.171 UQSUB16
10.171 UQSUB16
Unsigned saturating parallel halfword-wise subtraction.
Syntax
UQSUB16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each halfword of the second operand from the corresponding halfword of the
first operand and writes the results into the corresponding halfwords of the destination. It saturates the
results to the unsigned range 0 ≤ x ≤ 216 –1. The Q flag is not affected even if this operation saturates.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, Q, or GE flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-518
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.172 USAD8
10.172 USAD8
Unsigned Sum of Absolute Differences.
Syntax
USAD8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Rm
is the register holding the second operand.
Operation
The USAD8 instruction finds the four differences between the unsigned values in corresponding bytes of
Rn and Rm. It adds the absolute values of the four differences, and saves the result to Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not alter any flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
USAD8 r2, r4, r6
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-519
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.173 USADA8
10.173 USADA8
Unsigned Sum of Absolute Differences and Accumulate.
Syntax
USADA8{cond} Rd, Rn, Rm, Ra
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the first operand.
Rm
is the register holding the second operand.
Ra
is the register holding the accumulate operand.
Operation
The USADA8 instruction adds the absolute values of the four differences to the value in Ra, and saves the
result to Rd.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not alter any flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Correct examples
USADA8 r0, r3, r5, r2
USADA8VS r0, r4, r0, r1
Incorrect examples
USADA8 r2, r4, r6 ; USADA8 requires four registers
USADA16 r0, r4, r0, r1 ; no such instruction
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-520
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.174 USAT
10.174 USAT
Unsigned Saturate to any bit position, with optional shift before saturating.
Syntax
USAT{cond} Rd, #sat, Rm{, shift}
where:
cond
is an optional condition code.
Rd
is the destination register.
sat
specifies the bit position to saturate to, in the range 0 to 31.
Rm
is the register containing the operand.
shift
is an optional shift. It must be one of the following:
ASR #n
where n is in the range 1-32 (ARM) or 1-31 (Thumb).
LSL #n
where n is in the range 0-31.
Operation
The USAT instruction applies the specified shift to a signed value, then saturates to the unsigned range 0 ≤
x ≤ 2sat – 1.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs, this instruction sets the Q flag. To read the state of the Q flag, use an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
There is no 16-bit version of this instruction in Thumb.
Example
USATNE r0, #7, r5
Related references
10.127 SSAT16 on page 10-461.
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-521
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.175 USAT16
10.175 USAT16
Parallel halfword Saturate.
Syntax
USAT16{cond} Rd, #sat, Rn
where:
cond
is an optional condition code.
Rd
is the destination register.
sat
specifies the bit position to saturate to, in the range 0 to 15.
Rn
is the register holding the operand.
Operation
Halfword-wise unsigned saturation to any bit position.
The USAT16 instruction saturates each signed halfword to the unsigned range 0 ≤ x ≤ 2sat –1.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Q flag
If saturation occurs on either halfword, this instruction sets the Q flag. To read the state of the Q flag, use
an MRS instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
USAT16 r0, #7, r5
Related references
10.60 MRS (PSR to general-purpose register) on page 10-376.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-522
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.176 USAX
10.176 USAX
Unsigned parallel subtract and add halfwords with exchange.
Syntax
USAX{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction exchanges the two halfwords of the second operand, then performs a subtraction on the
two top halfwords of the operands and an addition on the bottom two halfwords. It writes the results into
the corresponding halfwords of the destination. The results are modulo 216. It sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets GE[1:0] to 1 to indicate that the addition overflowed, generating a carry. This is equivalent to an
ADDS instruction setting the C condition flag to 1.
It sets GE[3:2] to 1 to indicate that the subtraction gave a result greater than or equal to zero, meaning a
borrow did not occur. This is equivalent to a SUBS instruction setting the C condition flag to 1.
You can use these flags to control a following SEL instruction.
Note
GE[1:0] are set or cleared together, and GE[3:2] are set or cleared together.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-523
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.176 USAX
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-524
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.177 USUB8
10.177 USUB8
Unsigned parallel byte-wise subtraction.
Syntax
USUB8{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each byte of the second operand from the corresponding byte of the first
operand and writes the results into the corresponding bytes of the destination. The results are modulo 28.
It sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
GE flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[0]
for bits[7:0] of the result.
GE[1]
for bits[15:8] of the result.
GE[2]
for bits[23:16] of the result.
GE[3]
for bits[31:24] of the result.
It sets a GE flag to 1 to indicate that the corresponding result is greater than or equal to zero, meaning a
borrow did not occur. This is equivalent to a SUBS instruction setting the C condition flag to 1.
You can use these flags to control a following SEL instruction.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-525
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.178 USUB16
10.178 USUB16
Unsigned parallel halfword-wise subtraction.
Syntax
USUB16{cond} {Rd}, Rn, Rm
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm, Rn
are the ARM registers holding the operands.
Operation
This instruction subtracts each halfword of the second operand from the corresponding halfword of the
first operand and writes the results into the corresponding halfwords of the destination. The results are
modulo 216. It sets the APSR GE flags.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not affect the N, Z, C, V, or Q flags.
It sets the GE flags in the APSR as follows:
GE[1:0]
for bits[15:0] of the result.
GE[3:2]
for bits[31:16] of the result.
It sets a pair of GE flags to 1 to indicate that the corresponding result is greater than or equal to zero,
meaning a borrow did not occur. This is equivalent to a SUBS instruction setting the C condition flag to 1.
You can use these flags to control a following SEL instruction.
Note
GE[1:0] are set or cleared together, and GE[3:2] are set or cleared together.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.99 SEL on page 10-430.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-526
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.179 UXTAB
10.179 UXTAB
Zero extend Byte and Add.
Syntax
UXTAB{cond} {Rd}, Rn, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the number to add.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
UXTAB extends an 8-bit value to a 32-bit value. It does this by:
1. Rotating the value from Rm right by 0, 8, 16 or 24 bits.
2. Extracting bits[7:0] from the value obtained.
3. Zero extending to 32 bits.
4. Adding the value from Rn.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it
are only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-527
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.180 UXTAB16
10.180 UXTAB16
Zero extend two Bytes and Add.
Syntax
UXTAB16{cond} {Rd}, Rn, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the number to add.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
UXTAB16 extends two 8-bit values to two 16-bit values. It does this by:
1. Rotating the value from Rm right by 0, 8, 16 or 24 bits.
2. Extracting bits[23:16] and bits[7:0] from the value obtained.
3. Zero extending them to 16 bits.
4. Adding them to bits[31:16] and bits[15:0] respectively of Rn to form bits[31:16] and bits[15:0] of the
result.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Example
UXTAB16EQ r0, r0, r4, ROR #16
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-528
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.180 UXTAB16
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-529
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.181 UXTAH
10.181 UXTAH
Zero extend Halfword and Add.
Syntax
UXTAH{cond} {Rd}, Rn, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rn
is the register holding the number to add.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
UXTAH extends a 16-bit value to a 32-bit value. It does this by:
1. Rotating the value from Rm right by 0, 8, 16 or 24 bits.
2. Extracting bits[15:0] from the value obtained.
3. Zero extending to 32 bits.
4. Adding the value from Rn.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-530
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.182 UXTB
10.182 UXTB
Zero extend Byte.
Syntax
UXTB{cond} {Rd}, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
UXTB extends an 8-bit value to a 32-bit value. It does this by:
1. Rotating the value from Rm right by 0, 8, 16, or 24 bits.
2. Extracting bits[7:0] from the value obtained.
3. Zero extending to 32 bits.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
16-bit instruction
The following form of this instruction is available in Thumb code, and is a 16-bit instruction:
UXTB Rd, Rm
Rd and Rm must both be Lo registers.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
This 16-bit Thumb instruction is available in ARMv6 and above.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-531
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.183 UXTB16
10.183 UXTB16
Zero extend two Bytes.
Syntax
UXTB16{cond} {Rd}, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
UXTB16 extends two 8-bit values to two 16-bit values. It does this by:
1. Rotating the value from Rm right by 0, 8, 16 or 24 bits.
2. Extracting bits[23:16] and bits[7:0] from the value obtained.
3. Zero extending each to 16 bits.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-532
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.184 UXTH
10.184 UXTH
Zero extend Halfword.
Syntax
UXTH{cond} {Rd}, Rm {,rotation}
where:
cond
is an optional condition code.
Rd
is the destination register.
Rm
is the register holding the value to extend.
rotation
is one of:
ROR #8
Value from Rm is rotated right 8 bits.
ROR #16
Value from Rm is rotated right 16 bits.
ROR #24
Value from Rm is rotated right 24 bits.
If rotation is omitted, no rotation is performed.
Operation
UXTH extends a 16-bit value to a 32-bit value. It does this by:
1. Rotating the value from Rm right by 0, 8, 16, or 24 bits.
2. Extracting bits[15:0] from the value obtained.
3. Zero extending to 32 bits.
Register restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP
in Thumb instructions.
Condition flags
This instruction does not change the flags.
16-bit instructions
The following form of this instruction is available in Thumb code, and is a 16-bit instruction:
UXTH Rd, Rm
Rd and Rm must both be Lo registers.
Architectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is
only available in an ARMv7E-M implementation.
This 16-bit Thumb instruction is available in ARMv6 and above.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-533
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.185 WFE
10.185 WFE
Wait For Event.
Syntax
WFE{cond}
where:
cond
is an optional condition code.
Operation
This is a hint instruction. It is optional whether this instruction is implemented or not. If this instruction
is not implemented, it executes as a NOP. The assembler produces a diagnostic message if the instruction
executes as a NOP on the target.
WFE executes as a NOP instruction in ARMv6T2.
If the Event Register is not set, WFE suspends execution until one of the following events occurs:
• An IRQ interrupt, unless masked by the CPSR I-bit.
• An FIQ interrupt, unless masked by the CPSR F-bit.
• An Imprecise Data abort, unless masked by the CPSR A-bit.
• A Debug Entry request, if Debug is enabled.
• An Event signaled by another processor using the SEV instruction.
If the Event Register is set, WFE clears it and returns immediately.
If WFE is implemented, SEV must also be implemented.
Architectures
This ARM instruction is available in ARMv6K and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6T2 and above.
Related references
10.67 NOP on page 10-387.
10.8 Condition code suffixes on page 10-289.
10.101 SEV on page 10-433.
10.186 WFI on page 10-535.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-534
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.186 WFI
10.186 WFI
Wait for Interrupt.
Syntax
WFI{cond}
where:
cond
is an optional condition code.
Operation
This is a hint instruction. It is optional whether this instruction is implemented or not. If this instruction
is not implemented, it executes as a NOP. The assembler produces a diagnostic message if the instruction
executes as a NOP on the target.
WFI executes as a NOP instruction in ARMv6T2.
Architectures
This ARM instruction is available in ARMv6K and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6T2 and above.
Related references
10.67 NOP on page 10-387.
10.8 Condition code suffixes on page 10-289.
10.185 WFE on page 10-534.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-535
reserved.
Non-Confidential
10 ARM and Thumb Instructions
10.187 YIELD
10.187 YIELD
Yield.
Syntax
YIELD{cond}
where:
cond
is an optional condition code.
Operation
This is a hint instruction. It is optional whether this instruction is implemented or not. If this instruction
is not implemented, it executes as a NOP. The assembler produces a diagnostic message if the instruction
executes as a NOP on the target.
YIELD executes as a NOP instruction in ARMv6T2.
YIELD indicates to the hardware that the current thread is performing a task, for example a spinlock, that
can be swapped out. Hardware can use this hint to suspend and resume threads in a multithreading
system.
Architectures
This ARM instruction is available in ARMv6K and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above.
This 16-bit Thumb instruction is available in ARMv6T2 and above.
Related references
10.67 NOP on page 10-387.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 10-536
reserved.
Non-Confidential
Chapter 11
VFP Instructions
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-537
reserved.
Non-Confidential
11 VFP Instructions
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-538
reserved.
Non-Confidential
11 VFP Instructions
11.1 Summary of VFP instructions
VCVTB, VCVTT Convert between half-precision and single-precision floating-point Half-precision, VFPv4
VFNMA, VFNMS Fused multiply accumulate with negation, Fused multiply subtract with negation VFPv4
Transfer from two ARM registers to two single-precision or one double-precision register All
Transfer from two single-precision registers or one double-precision register to two ARM All
registers
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-539
reserved.
Non-Confidential
11 VFP Instructions
11.1 Summary of VFP instructions
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-540
reserved.
Non-Confidential
11 VFP Instructions
11.2 VABS (floating-point)
Syntax
VABS{cond}.F32 Sd, Sm
VABS{cond}.F64 Dd, Dm
where:
cond
is an optional condition code.
Sd, Sm
are the single-precision registers for the result and operand.
Dd, Dm
are the double-precision registers for the result and operand.
Operation
The VABS instruction takes the contents of Sm or Dm, clears the sign bit, and places the result in Sd or Dd.
This gives the absolute value.
If the operand is a NaN, the sign bit is cleared, but no exception is produced.
Floating-point exceptions
VABS instructions do not produce any exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-541
reserved.
Non-Confidential
11 VFP Instructions
11.3 VADD (floating-point)
Syntax
VADD{cond}.F32 {Sd}, Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VADD instruction adds the values in the operand registers and places the result in the destination
register.
Floating-point exceptions
The VADD instruction can produce Invalid Operation, Overflow, or Inexact exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-542
reserved.
Non-Confidential
11 VFP Instructions
11.4 VCMP, VCMPE
Syntax
VCMP{E}{cond}.F32 Sd, Sm
VCMP{E}{cond}.F32 Sd, #0
VCMP{E}{cond}.F64 Dd, Dm
VCMP{E}{cond}.F64 Dd, #0
where:
E
if present, indicates that the instruction raises an Invalid Operation exception if either operand is
a quiet or signaling NaN. Otherwise, it raises the exception only if either operand is a signaling
NaN.
cond
is an optional condition code.
Sd, Sm
are the single-precision registers holding the operands.
Dd, Dm
are the double-precision registers holding the operands.
Operation
The VCMP{E} instruction subtracts the value in the second operand register (or 0 if the second operand is
#0) from the value in the first operand register, and sets the VFP condition flags based on the result.
Floating-point exceptions
VCMP{E} instructions can produce Invalid Operation exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-543
reserved.
Non-Confidential
11 VFP Instructions
11.5 VCVT (between single-precision and double-precision)
Syntax
VCVT{cond}.F64.F32 Dd, Sm
VCVT{cond}.F32.F64 Sd, Dm
where:
cond
is an optional condition code.
Dd
is a double-precision register for the result.
Sm
is a single-precision register holding the operand.
Sd
is a single-precision register for the result.
Dm
is a double-precision register holding the operand.
Operation
These instructions convert the single-precision value in Sm to double-precision, placing the result in Dd,
or the double-precision value in Dm to single-precision, placing the result in Sd.
Floating-point exceptions
These instructions can produce Invalid Operation, Input Denormal, Overflow, Underflow, or Inexact
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-544
reserved.
Non-Confidential
11 VFP Instructions
11.6 VCVT (between floating-point and integer)
Syntax
VCVT{R}{cond}.type.F64 Sd, Dm
VCVT{R}{cond}.type.F32 Sd, Sm
VCVT{cond}.F64.type Dd, Sm
VCVT{cond}.F32.type Sd, Sm
where:
R
makes the operation use the rounding mode specified by the FPSCR. Otherwise, the operation
rounds towards zero.
cond
is an optional condition code.
type
can be either U32 (unsigned 32-bit integer) or S32 (signed 32-bit integer).
Sd
is a single-precision register for the result.
Dd
is a double-precision register for the result.
Sm
is a single-precision register holding the operand.
Dm
is a double-precision register holding the operand.
Operation
The first two forms of this instruction convert from floating-point to integer.
The third and fourth forms convert from integer to floating-point.
Floating-point exceptions
These instructions can produce Input Denormal, Invalid Operation, or Inexact exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-545
reserved.
Non-Confidential
11 VFP Instructions
11.7 VCVT (between floating-point and fixed-point)
Syntax
VCVT{cond}.type.F64 Dd, Dd, #fbits
where:
cond
is an optional condition code.
type
can be any one of:
S16
16-bit signed fixed-point number.
U16
16-bit unsigned fixed-point number.
S32
32-bit signed fixed-point number.
U32
32-bit unsigned fixed-point number.
Sd
is a single-precision register for the operand and result.
Dd
is a double-precision register for the operand and result.
fbits
is the number of fraction bits in the fixed-point number, in the range 0-16 if type is S16 or U16,
or in the range 1-32 if type is S32 or U32.
Operation
The first two forms of this instruction convert from floating-point to fixed-point.
The third and fourth forms convert from fixed-point to floating-point.
In all cases the fixed-point number is contained in the least significant 16 or 32 bits of the register.
Floating-point exceptions
These instructions can produce Input Denormal, Invalid Operation, or Inexact exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-546
reserved.
Non-Confidential
11 VFP Instructions
11.8 VCVTB, VCVTT (half-precision extension)
Syntax
VCVTB{cond}.type Sd, Sm
VCVTT{cond}.type Sd, Sm
where:
cond
is an optional condition code.
type
can be any one of:
F32.F16
Convert from half-precision to single-precision.
F16.F32
Convert from single-precision to half-precision.
Sd
is a single word register for the result.
Sm
is a single word register for the operand.
Operation
VCVTB uses the bottom half (bits[15:0]) of the single word register to obtain or store the half-precision
value
VCVTT uses the top half (bits[31:16]) of the single word register to obtain or store the half-precision
value.
Architectures
The instructions are only available in VFPv3 systems with the half-precision extension, and VFPv4.
Floating-point exceptions
These instructions can produce Input Denormal, Invalid Operation, Overflow, Underflow, or Inexact
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-547
reserved.
Non-Confidential
11 VFP Instructions
11.9 VDIV
11.9 VDIV
Floating-point divide.
Syntax
VDIV{cond}.F32 {Sd}, Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VDIV instruction divides the value in the first operand register by the value in the second operand
register, and places the result in the destination register.
Floating-point exceptions
VDIV operations can produce Division by Zero, Invalid Operation, Overflow, Underflow, or Inexact
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-548
reserved.
Non-Confidential
11 VFP Instructions
11.10 VFMA, VFMS, VFNMA, VFNMS (floating-point)
Syntax
VF{N}op{cond}.F64 {Dd}, Dn, Dm
where:
op
is one of MA or MS.
N
negates the final result.
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
VFMA multiplies the values in the operand registers, adds the value in the destination register, and places
the final result in the destination register. The result of the multiply is not rounded before the
accumulation.
VFMS multiplies the values in the operand registers, subtracts the product from the value in the destination
register, and places the final result in the destination register. The result of the multiply is not rounded
before the subtraction.
In each case, the final result is negated if the N option is used.
Floating-point exceptions
These instructions can produce Input Denormal, Invalid Operation, Overflow, Underflow, or Inexact
exceptions.
Related references
11.23 VMUL (floating-point) on page 11-562.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-549
reserved.
Non-Confidential
11 VFP Instructions
11.11 VLDM (floating-point)
Syntax
VLDMmode{cond} Rn{!}, Registers
where:
mode
must be one of:
IA
meaning Increment address After each transfer. IA is the default, and can be omitted.
DB
meaning Decrement address Before each transfer.
EA
meaning Empty Ascending stack operation. This is the same as DB for loads.
FD
meaning Full Descending stack operation. This is the same as IA for loads.
cond
is an optional condition code.
Rn
is the ARM register holding the base address for the transfer.
!
is optional. ! specifies that the updated base address must be written back to Rn. If ! is not
specified, mode must be IA.
Registers
is a list of consecutive extension registers enclosed in braces, { and }. The list can be comma-
separated, or in range format. There must be at least one register in the list.
You can specify S or D registers, but they must not be mixed. The number of registers must not
exceed 16 D registers.
Note
VPOP Registers is equivalent to VLDM sp!, Registers.
You can use either form of this instruction. They both disassemble to VPOP.
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-550
reserved.
Non-Confidential
11 VFP Instructions
11.12 VLDR (floating-point)
Syntax
VLDR{cond}{.size} Fd, [Rn{, #offset}]
where:
cond
is an optional condition code.
size
is an optional data size specifier. Must be 32 if Fd is an S register, or 64 otherwise.
Fd
is the extension register to be loaded, and can be either a D or S register.
Rn
is the ARM register holding the base address for the transfer.
offset
is an optional numeric expression. It must evaluate to a numeric value at assembly time. The
value must be a multiple of 4, and lie in the range –1020 to +1020. The value is added to the
base address to form the address used for the transfer.
label
is a PC-relative expression.
label must be aligned on a word boundary within ±1KB of the current instruction.
Operation
The VLDR instruction loads an extension register from memory.
One word is transferred if Fd is an S register. Two words are transferred otherwise.
There is also a VLDR pseudo-instruction.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
11.14 VLDR pseudo-instruction on page 11-553.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-551
reserved.
Non-Confidential
11 VFP Instructions
11.13 VLDR (post-increment and pre-decrement, floating-point)
Note
There are also VLDR and VSTR instructions without post-increment and pre-decrement.
Syntax
VLDR{cond}{.size} Fd, [Rn], #offset ; post-increment
where:
cond
is an optional condition code.
size
is an optional data size specifier. Must be 32 if Fd is an S register, or 64 if Fd is a D register.
Fd
is the extension register to load. It can be either a double precision (Dd) or a single precision (Sd)
register.
Rn
is the ARM register holding the base address for the transfer.
offset
is a numeric expression that must evaluate to a numeric value at assembly time. The value must
be 4 if Fd is an S register, or 8 if Fd is a D register.
Operation
The post-increment instruction increments the base address in the register by the offset value, after the
transfer. The pre-decrement instruction decrements the base address in the register by the offset value,
and then performs the transfer using the new address in the register. This pseudo-instruction assembles to
a VLDM instruction.
Related references
11.11 VLDM (floating-point) on page 11-550.
11.12 VLDR (floating-point) on page 11-551.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-552
reserved.
Non-Confidential
11 VFP Instructions
11.14 VLDR pseudo-instruction
Note
This section describes the VLDR pseudo-instruction only.
Syntax
VLDR{cond}.datatype Dd,=constant
VLDR{cond}.datatype Sd,=constant
where:
datatype
must be either F32 or F64.
n
must be one of 8, 16, 32, or 64.
cond
is an optional condition code.
Dd or Sd
is the extension register to be loaded.
constant
is an immediate value of the appropriate type for datatype.
Operation
If an instruction (for example, VMOV) is available that can generate the constant directly into the register,
the assembler uses it. Otherwise, the assembler generates a doubleword literal pool entry containing the
constant and loads the constant using a VLDR instruction.
Related concepts
8.9 VFP data types on page 8-172.
Related references
11.12 VLDR (floating-point) on page 11-551.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-553
reserved.
Non-Confidential
11 VFP Instructions
11.15 VMLA (floating-point)
Syntax
VMLA{cond}.F32 Sd, Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VMLA instruction multiplies the values in the operand registers, adds the value in the destination
register, and places the final result in the destination register.
Floating-point exceptions
This instruction can produce Invalid Operation, Overflow, Underflow, Inexact, or Input Denormal
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-554
reserved.
Non-Confidential
11 VFP Instructions
11.16 VMLS (floating-point)
Syntax
VMLS{cond}.F32 Sd, Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VMLS instruction multiplies the values in the operand registers, subtracts the result from the value in
the destination register, and places the final result in the destination register.
Floating-point exceptions
This instruction can produce Invalid Operation, Overflow, Underflow, Inexact, or Input Denormal
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-555
reserved.
Non-Confidential
11 VFP Instructions
11.17 VMOV (floating-point)
Syntax
VMOV{cond}.F32 Sd, #imm
VMOV{cond}.F32 Sd, Sm
VMOV{cond}.F64 Dd, Dm
where:
cond
is an optional condition code.
Sd
is the single-precision destination register.
Dd
is the double-precision destination register.
imm
is the floating-point immediate value.
Sm
is the single-precision source register.
Dm
is the double-precision source register.
Immediate values
Any number that can be expressed as +/–n * 2–r,where n and r are integers, 16 <= n <= 31, 0 <= r <= 7.
Architectures
The instructions that copy immediate constants are available in VFPv3 and above.
The instructions that copy from registers are available in all VFP systems.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-556
reserved.
Non-Confidential
11 VFP Instructions
11.18 VMOV (between one ARM register and single precision VFP)
11.18 VMOV (between one ARM register and single precision VFP)
Transfer contents between a single-precision floating-point register and an ARM register.
Syntax
VMOV{cond} Rd, Sn
VMOV{cond} Sn, Rd
where:
cond
is an optional condition code.
Sn
is the VFP single-precision register.
Rd
is the ARM register. Rd must not be PC.
Operation
VMOV Rd, Sn transfers the contents of Sn into Rd.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-557
reserved.
Non-Confidential
11 VFP Instructions
11.19 VMOV (between two ARM registers and one or two extension registers)
11.19 VMOV (between two ARM registers and one or two extension registers)
Transfer contents between two ARM registers and either one 64-bit register or two consecutive 32-bit
registers.
Syntax
VMOV{cond} Dm, Rd, Rn
where:
cond
is an optional condition code.
Dm
is a 64-bit extension register.
Sm
is a VFP 32-bit register.
Sm1
is the next consecutive VFP 32-bit register after Sm.
Rd, Rn
are the ARM registers. Rd and Rn must not be PC.
Operation
VMOV Dm, Rd, Rn transfers the contents of Rd into the low half of Dm, and the contents of Rn into the
high half of Dm.
VMOV Rd, Rn, Dm transfers the contents of the low half of Dm into Rd, and the contents of the high half of
Dm into Rn.
VMOV Rd, Rn, Sm, Sm1 transfers the contents of Sm into Rd, and the contents of Sm1 into Rn.
VMOV Sm, Sm1, Rd, Rn transfers the contents of Rd into Sm, and the contents of Rn into Sm1.
Architectures
The instructions are available in VFPv2 and above.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-558
reserved.
Non-Confidential
11 VFP Instructions
11.20 VMOV (between an ARM register and half a double precision VFP register)
11.20 VMOV (between an ARM register and half a double precision VFP register)
Transfer contents between an ARM register and half a double precision VFP register.
Syntax
VMOV{cond}{.size} Dn[x], Rd
where:
cond
is an optional condition code.
size
is the data size. Must be either 32 or omitted. If omitted, size is 32.
Dn[x]
if x is 0, is the least significant half, or if x is 1, the most significant half of a double precision
VFP register.
Rd
is the ARM register. Rd must not be PC.
Operation
VMOV Dn[x], Rd transfers the contents of Rd into Dn[x].
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-559
reserved.
Non-Confidential
11 VFP Instructions
11.21 VMRS
11.21 VMRS
Transfer the contents of a VFP system register to an ARM register.
Syntax
VMRS{cond} Rd, extsysreg
where:
cond
is an optional condition code.
extsysreg
is the VFP system register, usually FPSCR, FPSID, or FPEXC.
Rd
is the ARM register. Rd must not be PC.
It can be APSR_nzcv, if extsysreg is FPSCR. In this case, the floating-point status flags are
transferred into the corresponding flags in the ARM APSR.
Operation
The VMRS instruction transfers the contents of extsysreg into Rd.
Note
This instruction stalls the processor until all current VFP operations complete.
Examples
VMRS r2,FPCID
VMRS APSR_nzcv, FPSCR ; transfer FP status register to ARM APSR
Related references
8.11 VFP system registers on page 8-174.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-560
reserved.
Non-Confidential
11 VFP Instructions
11.22 VMSR
11.22 VMSR
Transfer the contents of an ARM register to a VFP system register.
Syntax
VMSR{cond} extsysreg, Rd
where:
cond
is an optional condition code.
extsysreg
is the VFP system register, usually FPSCR, FPSID, or FPEXC.
Rd
is the ARM register. Rd must not be PC.
Operation
The VMSR instruction transfers the contents of Rd into extsysreg.
Note
This instruction stalls the processor until all current VFP operations complete.
Example
VMSR FPSCR, r4
Related references
8.11 VFP system registers on page 8-174.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-561
reserved.
Non-Confidential
11 VFP Instructions
11.23 VMUL (floating-point)
Syntax
VMUL{cond}.F32 {Sd,} Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VMUL operation multiplies the values in the operand registers and places the result in the destination
register.
Floating-point exceptions
This instruction can produce Invalid Operation, Overflow, Underflow, Inexact, or Input Denormal
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-562
reserved.
Non-Confidential
11 VFP Instructions
11.24 VNEG (floating-point)
Syntax
VNEG{cond}.F32 Sd, Sm
VNEG{cond}.F64 Dd, Dm
where:
cond
is an optional condition code.
Sd, Sm
are the single-precision registers for the result and operand.
Dd, Dm
are the double-precision registers for the result and operand.
Operation
The VNEG instruction takes the contents of Sm or Dm, changes the sign bit, and places the result in Sd or Dd.
This gives the negation of the value.
If the operand is a NaN, the sign bit is changed, but no exception is produced.
Floating-point exceptions
VNEG instructions do not produce any exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-563
reserved.
Non-Confidential
11 VFP Instructions
11.25 VNMLA (floating-point)
Syntax
VNMLA{cond}.F32 Sd, Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VNMLA instruction multiplies the values in the operand registers, adds the value to the destination
register, and places the negated final result in the destination register.
Floating-point exceptions
This instruction can produce Invalid Operation, Overflow, Underflow, Inexact, or Input Denormal
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-564
reserved.
Non-Confidential
11 VFP Instructions
11.26 VNMLS (floating-point)
Syntax
VNMLS{cond}.F32 Sd, Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VNMLS instruction multiplies the values in the operand registers, subtracts the result from the value in
the destination register, and places the negated final result in the destination register.
Floating-point exceptions
This instruction can produce Invalid Operation, Overflow, Underflow, Inexact, or Input Denormal
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-565
reserved.
Non-Confidential
11 VFP Instructions
11.27 VNMUL (floating-point)
Syntax
VNMUL{cond}.F32 {Sd,} Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VNMUL instruction multiplies the values in the operand registers and places the negated result in the
destination register.
Floating-point exceptions
This instruction can produce Invalid Operation, Overflow, Underflow, Inexact, or Input Denormal
exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-566
reserved.
Non-Confidential
11 VFP Instructions
11.28 VPOP (floating-point)
Syntax
VPOP{cond} Registers
where:
cond
is an optional condition code.
Registers
is a list of consecutive extension registers enclosed in braces, { and }. The list can be comma-
separated, or in range format. There must be at least one register in the list.
You can specify S or D registers, but they must not be mixed. The number of registers must not
exceed 16 D registers.
Note
VPOP Registers is equivalent to VLDM sp!, Registers.
You can use either form of this instruction. They both disassemble to VPOP.
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
Related references
10.8 Condition code suffixes on page 10-289.
11.29 VPUSH (floating-point) on page 11-568.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-567
reserved.
Non-Confidential
11 VFP Instructions
11.29 VPUSH (floating-point)
Syntax
VPUSH{cond} Registers
where:
cond
is an optional condition code.
Registers
is a list of consecutive extension registers enclosed in braces, { and }. The list can be comma-
separated, or in range format. There must be at least one register in the list.
You can specify S or D registers, but they must not be mixed. The number of registers must not
exceed 16 D registers.
Note
VPUSH Registers is equivalent to VSTMDB sp!, Registers.
You can use either form of this instruction. They both disassemble to VPUSH.
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
Related references
10.8 Condition code suffixes on page 10-289.
11.28 VPOP (floating-point) on page 11-567.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-568
reserved.
Non-Confidential
11 VFP Instructions
11.30 VSQRT
11.30 VSQRT
Floating-point square root.
Syntax
VSQRT{cond}.F32 Sd, Sm
VSQRT{cond}.F64 Dd, Dm
where:
cond
is an optional condition code.
Sd, Sm
are the single-precision registers for the result and operand.
Dd, Dm
are the double-precision registers for the result and operand.
Operation
The VSQRT instruction takes the square root of the contents of Sm or Dm, and places the result in Sd or Dd.
Floating-point exceptions
VSQRT instructions can produce Invalid Operation or Inexact exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-569
reserved.
Non-Confidential
11 VFP Instructions
11.31 VSTM (floating-point)
Syntax
VSTMmode{cond} Rn{!}, Registers
where:
mode
must be one of:
IA
meaning Increment address After each transfer. IA is the default, and can be omitted.
DB
meaning Decrement address Before each transfer.
EA
meaning Empty Ascending stack operation. This is the same as IA for stores.
FD
meaning Full Descending stack operation. This is the same as DB for stores.
cond
is an optional condition code.
Rn
is the ARM register holding the base address for the transfer.
!
is optional. ! specifies that the updated base address must be written back to Rn. If ! is not
specified, mode must be IA.
Registers
is a list of consecutive extension registers enclosed in braces, { and }. The list can be comma-
separated, or in range format. There must be at least one register in the list.
You can specify S or D registers, but they must not be mixed. The number of registers must not
exceed 16 D registers.
Note
VPUSH Registers is equivalent to VSTMDB sp!, Registers.
You can use either form of this instruction. They both disassemble to VPUSH.
Related concepts
4.15 Stack implementation using LDM and STM on page 4-77.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-570
reserved.
Non-Confidential
11 VFP Instructions
11.32 VSTR (floating-point)
Syntax
VSTR{cond}{.size} Fd, [Rn{, #offset}]
where:
cond
is an optional condition code.
size
is an optional data size specifier. Must be 32 if Fd is an S register, or 64 otherwise.
Fd
is the extension register to be saved. It can be either a D or S register.
Rn
is the ARM register holding the base address for the transfer.
offset
is an optional numeric expression. It must evaluate to a numeric value at assembly time. The
value must be a multiple of 4, and lie in the range –1020 to +1020. The value is added to the
base address to form the address used for the transfer.
Operation
The VSTR instruction saves the contents of an extension register to memory.
One word is transferred if Fd is an S register. Two words are transferred otherwise.
Related concepts
7.5 Register-relative and PC-relative expressions on page 7-136.
Related references
11.14 VLDR pseudo-instruction on page 11-553.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-571
reserved.
Non-Confidential
11 VFP Instructions
11.33 VSTR (post-increment and pre-decrement, floating-point)
Note
There are also VLDR and VSTR instructions without post-increment and pre-decrement.
Syntax
VSTR{cond}{.size} Fd, [Rn], #offset ; post-increment
where:
cond
is an optional condition code.
size
is an optional data size specifier. Must be 32 if Fd is an S register, or 64 if Fd is a D register.
Fd
is the extension register to be saved. It can be either a double precision (Dd) or a single precision
(Sd) register.
Rn
is the ARM register holding the base address for the transfer.
offset
is a numeric expression that must evaluate to a numeric value at assembly time. The value must
be 4 if Fd is an S register, or 8 if Fd is a D register.
Operation
The post-increment instruction increments the base address in the register by the offset value, after the
transfer. The pre-decrement instruction decrements the base address in the register by the offset value,
and then performs the transfer using the new address in the register. This pseudo-instruction assembles to
a VSTM instruction.
Related references
11.32 VSTR (floating-point) on page 11-571.
11.31 VSTM (floating-point) on page 11-570.
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-572
reserved.
Non-Confidential
11 VFP Instructions
11.34 VSUB (floating-point)
Syntax
VSUB{cond}.F32 {Sd}, Sn, Sm
where:
cond
is an optional condition code.
Sd, Sn, Sm
are the single-precision registers for the result and operands.
Dd, Dn, Dm
are the double-precision registers for the result and operands.
Operation
The VSUB instruction subtracts the value in the second operand register from the value in the first operand
register, and places the result in the destination register.
Floating-point exceptions
The VSUB instruction can produce Invalid Operation, Overflow, or Inexact exceptions.
Related references
10.8 Condition code suffixes on page 10-289.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 11-573
reserved.
Non-Confidential
Chapter 12
Directives Reference
Describes the directives that are provided by the ARM assembler, armasm.
Note
None of these directives are available in the inline assemblers in the ARM C and C++ compilers.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-574
reserved.
Non-Confidential
12 Directives Reference
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-575
reserved.
Non-Confidential
12 Directives Reference
12.1 Alphabetical list of directives
CP FRAME RESTORE QN
DCW and DCWU IF, ELSE, ENDIF, and ELIF SPACE or FILL
DN IMPORT SUBT
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-576
reserved.
Non-Confidential
12 Directives Reference
12.2 About assembly control directives
Nesting directives
The following structures can be nested to a total depth of 256:
• MACRO definitions.
• WHILE...WEND loops.
• IF...ELSE...ENDIF conditional structures.
• INCLUDE file inclusions.
The limit applies to all structures taken together, regardless of how they are nested. The limit is not 256
of each type of structure.
Related references
12.52 MACRO and MEND on page 12-633.
12.54 MEXIT on page 12-637.
12.45 IF, ELSE, ENDIF, and ELIF on page 12-624.
12.68 WHILE and WEND on page 12-652.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-577
reserved.
Non-Confidential
12 Directives Reference
12.3 About frame directives
Related references
12.31 FRAME ADDRESS on page 12-610.
12.32 FRAME POP on page 12-611.
12.33 FRAME PUSH on page 12-612.
12.34 FRAME REGISTER on page 12-613.
12.35 FRAME RESTORE on page 12-614.
12.36 FRAME RETURN ADDRESS on page 12-615.
12.37 FRAME SAVE on page 12-616.
12.38 FRAME STATE REMEMBER on page 12-617.
12.39 FRAME STATE RESTORE on page 12-618.
12.40 FRAME UNWIND ON on page 12-619.
12.41 FRAME UNWIND OFF on page 12-620.
12.42 FUNCTION or PROC on page 12-621.
12.25 ENDFUNC or ENDP on page 12-603.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-578
reserved.
Non-Confidential
12 Directives Reference
12.4 ALIAS
12.4 ALIAS
The ALIAS directive creates an alias for a symbol.
Syntax
ALIAS name, aliasname
where:
name
is the name of the symbol to create an alias for.
aliasname
is the name of the alias to be created.
Usage
The symbol name must already be defined in the source file before creating an alias for it. Properties of
name set by the EXPORT directive are not inherited by aliasname, so you must use EXPORT on aliasname
if you want to make the alias available outside the current source file. Apart from the properties set by
the EXPORT directive, name and aliasname are identical.
Correct example
baz
bar PROC
BX lr
ENDP
ALIAS bar,foo ; foo is an alias for bar
EXPORT bar
EXPORT foo ; foo and bar have identical properties
; because foo was created using ALIAS
EXPORT baz ; baz and bar are not identical
; because the size field of baz is not set
Incorrect example
EXPORT bar
IMPORT car
ALIAS bar,foo ; ERROR - bar is not defined yet
ALIAS car,boo ; ERROR - car is external
bar PROC
BX lr
ENDP
Related references
12.28 EXPORT or GLOBAL on page 12-606.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-579
reserved.
Non-Confidential
12 Directives Reference
12.5 ALIGN
12.5 ALIGN
The ALIGN directive aligns the current location to a specified boundary by padding with zeros or NOP
instructions.
Syntax
ALIGN {expr{,offset{,pad{,padsize}}}}
where:
expr
is a numeric expression evaluating to any power of 2 from 20 to 231
offset
can be any numeric expression
pad
can be any numeric expression
padsize
can be 1, 2 or 4.
Operation
The current location is aligned to the next lowest address of the form:
offset + n * expr
If expr is not specified, ALIGN sets the current location to the next word (four byte) boundary. The
unused space between the previous and the new current location are filled with:
• Copies of pad, if pad is specified.
• NOP instructions, if all the following conditions are satisfied:
— pad is not specified.
— The ALIGN directive follows ARM or Thumb instructions.
— The current section has the CODEALIGN attribute set on the AREA directive.
• Zeros otherwise.
pad is treated as a byte, halfword, or word, according to the value of padsize. If padsize is not
specified, pad defaults to bytes in data sections, halfwords in Thumb code, or words in ARM code.
Usage
Use ALIGN to ensure that your data and code is aligned to appropriate boundaries. This is typically
required in the following circumstances:
• The ADR Thumb pseudo-instruction can only load addresses that are word aligned, but a label within
Thumb code might not be word aligned. Use ALIGN 4 to ensure four-byte alignment of an address
within Thumb code.
• Use ALIGN to take advantage of caches on some ARM processors. For example, the ARM940T has a
cache with 16-byte lines. Use ALIGN 16 to align function entries on 16-byte boundaries and
maximize the efficiency of the cache.
• In ARMv5TE, or in ARMv6 when SCTLR.U is 0, LDRD and STRD doubleword data transfers must be
eight-byte aligned. Use ALIGN 8 before memory allocation directives such as DCQ if the data is to be
accessed using LDRD or STRD. This is not required in ARMv6 when SCTLR.U is 1, or in ARMv7,
because in these versions, doubleword data transfers can be word-aligned.
• A label on a line by itself can be arbitrarily aligned. Following ARM code is word-aligned (Thumb
code is halfword aligned). The label therefore does not address the code correctly. Use ALIGN 4 (or
ALIGN 2 for Thumb) before the label.
Alignment is relative to the start of the ELF section where the routine is located. The section must be
aligned to the same, or coarser, boundaries. The ALIGN attribute on the AREA directive is specified
differently.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-580
reserved.
Non-Confidential
12 Directives Reference
12.5 ALIGN
Examples
AREA cacheable, CODE, ALIGN=3
rout1 ; code ; aligned on 8-byte boundary
; code
MOV pc,lr ; aligned only on 4-byte boundary
ALIGN 8 ; now aligned on 8-byte boundary
rout2 ; code
In the following example, the ALIGN directive tells the assembler that the next instruction is word aligned
and offset by 3 bytes. The 3 byte offset is counted from the previous word aligned address, resulting in
the second DCB placed in the last byte of the same word and 2 bytes of padding are to be added.
AREA OffsetExample, CODE
DCB 1 ; This example places the two bytes in the first
ALIGN 4,3 ; and fourth bytes of the same word.
DCB 1 ; The second DCB is offset by 3 bytes from the
; first DCB.
In the following example, the ALIGN directive tells the assembler that the next instruction is word aligned
and offset by 2 bytes. Here, the 2 byte offset is counted from the next word aligned address, so the value
n is set to 1 (n=0 clashes with the third DCB). This time three bytes of padding are to be added.
In the following example, the DCB directive makes the PC misaligned. The ALIGN directive ensures that
the label subroutine1 and the following instruction are word aligned.
AREA Example, CODE, READONLY
start LDR r6,=label1
; code
MOV pc,lr
label1 DCB 1 ; PC now misaligned
ALIGN ; ensures that subroutine1 addresses
subroutine1 ; the following instruction.
MOV r5,#0x5
Related references
12.6 AREA on page 12-582.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-581
reserved.
Non-Confidential
12 Directives Reference
12.6 AREA
12.6 AREA
The AREA directive instructs the assembler to assemble a new code or data section.
Syntax
AREA sectionname{,attr}{,attr}...
where:
sectionname
is the name to give to the section. Sections are independent, named, indivisible chunks of code
or data that are manipulated by the linker.
You can choose any name for your sections. However, names starting with a non-alphabetic
character must be enclosed in bars or a missing section name error is generated. For example, |
1_DataArea|.
Certain names are conventional. For example, |.text| is used for code sections produced by
the C compiler, or for code sections otherwise associated with the C library.
attr
are one or more comma-delimited section attributes. Valid attributes are:
ALIGN=expression
By default, ELF sections are aligned on a four-byte boundary. expression can have
any integer value from 0 to 31. The section is aligned on a 2expression-byte boundary. For
example, if expression is 10, the section is aligned on a 1KB boundary.
This is not the same as the way that the ALIGN directive is specified.
Note
Do not use ALIGN=0 or ALIGN=1 for ARM code sections.
Do not use ALIGN=0 for Thumb code sections.
ASSOC=section
section specifies an associated ELF section. sectionname must be included in any
link that includes section
CODE
Contains machine instructions. READONLY is the default.
CODEALIGN
Causes armasm to insert NOP instructions when the ALIGN directive is used after ARM
or Thumb instructions within the section, unless the ALIGN directive specifies a
different padding. CODEALIGN is the default for execute-only sections.
COMDEF
Is a common section definition. This ELF section can contain code or data. It must be
identical to any other section of the same name in other source files.
Identical ELF sections with the same name are overlaid in the same section of memory
by the linker. If any are different, the linker generates a warning and does not overlay
the sections.
COMGROUP=symbol_name
Is the signature that makes the AREA part of the named ELF section group. See the
GROUP=symbol_name for more information. The COMGROUP attribute marks the ELF
section group with the GRP_COMDAT flag.
COMMON
Is a common data section. You must not define any code or data in it. It is initialized to
zeros by the linker. All common sections with the same name are overlaid in the same
section of memory by the linker. They do not all have to be the same size. The linker
allocates as much space as is required by the largest common section of each name.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-582
reserved.
Non-Confidential
12 Directives Reference
12.6 AREA
DATA
Contains data, not instructions. READWRITE is the default.
EXECONLY
Indicates that the section is execute-only. Execute-only sections must also have the
CODE attribute, and must not have any of the following attributes:
• READONLY.
• READWRITE.
• DATA.
• ZEROALIGN.
armasm faults if any of the following occur in an execute-only section:
• Explicit data definitions, for example DCD and DCB.
• Implicit data definitions, for example LDR r0, =0xaabbccdd.
• Literal pool directives, for example LTORG, if there is literal data to be emitted.
• INCBIN or SPACE directives.
• ALIGN directives, if the required alignment cannot be accomplished by padding with
NOP instructions. armasm implicitly applies the CODEALIGN attribute to sections with
the EXECONLY attribute.
FINI_ARRAY
Sets the ELF type of the current area to SHT_FINI_ARRAY.
GROUP=symbol_name
Is the signature that makes the AREA part of the named ELF section group. It must be
defined by the source file, or a file included by the source file. All AREAS with the same
symbol_name signature are part of the same group. Sections within a group are kept or
discarded together.
INIT_ARRAY
Sets the ELF type of the current area to SHT_INIT_ARRAY.
LINKORDER=section
Specifies a relative location for the current section in the image. It ensures that the
order of all the sections with the LINKORDER attribute, with respect to each other, is the
same as the order of the corresponding named sections in the image.
MERGE=n
Indicates that the linker can merge the current section with other sections with the
MERGE=n attribute. n is the size of the elements in the section, for example n is 1 for
characters. You must not assume that the section is merged, because the attribute does
not force the linker to merge the sections.
NOALLOC
Indicates that no memory on the target system is allocated to this area.
NOINIT
Indicates that the data section is uninitialized, or initialized to zero. It contains only
space reservation directives SPACE or DCB, DCD, DCDU, DCQ, DCQU, DCW, or DCWU with
initialized values of zero. You can decide at link time whether an area is uninitialized or
zero-initialized.
Note
ARM Compiler does not support systems with ECC or parity protection where the
memory is not initialized.
PREINIT_ARRAY
Sets the ELF type of the current area to SHT_PREINIT_ARRAY.
READONLY
Indicates that this section must not be written to. This is the default for Code areas.
READWRITE
Indicates that this section can be read from and written to. This is the default for Data
areas.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-583
reserved.
Non-Confidential
12 Directives Reference
12.6 AREA
SECFLAGS=n
Adds one or more ELF flags, denoted by n, to the current section.
SECTYPE=n
Sets the ELF type of the current section to n.
STRINGS
Adds the SHF_STRINGS flag to the current section. To use the STRINGS attribute, you
must also use the MERGE=1 attribute. The contents of the section must be strings that are
nul-terminated using the DCB directive.
ZEROALIGN
Causes armasm to insert zeros when the ALIGN directive is used after ARM or Thumb
instructions within the section, unless the ALIGN directive specifies a different padding.
ZEROALIGN is the default for sections that are not execute-only.
Usage
Use the AREA directive to subdivide your source file into ELF sections. You can use the same name in
more than one AREA directive. All areas with the same name are placed in the same ELF section. Only the
attributes of the first AREA directive of a particular name are applied.
In general, ARM recommends that you use separate ELF sections for code and data. However, you can
put data in code sections. Large programs can usually be conveniently divided into several code sections.
Large independent data sets are also usually best placed in separate sections.
The scope of numeric local labels is defined by AREA directives, optionally subdivided by ROUT
directives.
There must be at least one AREA directive for an assembly.
Note
armasm emits R_ARM_TARGET1 relocations for the DCD and DCDU directives if the directive uses PC-
relative expressions and is in any of the PREINIT_ARRAY, FINI_ARRAY, or INIT_ARRAY ELF sections. You
can override the relocation using the RELOC directive after each DCD or DCDU directive. If this relocation is
used, read-write sections might become read-only sections at link time if the platform ABI permits this.
Example
The following example defines a read-only code section named Example:
AREA Example,CODE,READONLY ; An example code section.
; code
Related concepts
3.3 ELF sections and the AREA directive on page 3-54.
Related references
12.5 ALIGN on page 12-580.
12.57 RELOC on page 12-641.
12.16 DCD and DCDU on page 12-594.
Related information
Execute-only memory.
Building applications for execute-only memory.
Information about image structure and generation.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-584
reserved.
Non-Confidential
12 Directives Reference
12.7 ARM or CODE32
Syntax
ARM
Usage
In files that contain code using different instruction sets, ARM must precede any ARM code.
If necessary, this directive also inserts up to three bytes of padding to align to the next word boundary.
This directive does not assemble to any instructions. It also does not change the state. It only instructs the
assembler to assemble ARM instructions, and inserts padding if necessary.
Related references
12.11 CODE16 on page 12-589.
12.65 THUMB on page 12-649.
12.66 THUMBX on page 12-650.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-585
reserved.
Non-Confidential
12 Directives Reference
12.8 ASSERT
12.8 ASSERT
The ASSERT directive generates an error message during assembly if a given assertion is false.
Syntax
ASSERT logical-expression
where:
logical-expression
is an assertion that can evaluate to either {TRUE} or {FALSE}.
Usage
Use ASSERT to ensure that any necessary condition is met during assembly.
If the assertion is false an error message is generated and assembly fails.
Example
ASSERT label1 <= label2 ; Tests if the address
; represented by label1
; is <= the address
; represented by label2.
Related references
12.48 INFO on page 12-629.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-586
reserved.
Non-Confidential
12 Directives Reference
12.9 ATTR
12.9 ATTR
The ATTR set directives set values for the ABI build attributes. The ATTR scope directives specify the
scope for which the set value applies to.
Syntax
ATTR FILESCOPE
where:
name
is a section name or symbol name.
settype
can be any of:
• SETVALUE.
• SETSTRING.
• SETCOMPATWITHVALUE.
• SETCOMPATWITHSTRING.
tagid
is an attribute tag name (or its numerical value) defined in the ABI for the ARM Architecture.
value
depends on settype:
• is a 32-bit integer value when settype is SETVALUE or SETCOMPATWITHVALUE.
• is a nul-terminated string when settype is SETSTRING or SETCOMPATWITHSTRING.
Usage
The ATTR set directives following the ATTR FILESCOPE directive apply to the entire object file. The ATTR
set directives following the ATTR SCOPE name directive apply only to the named section or symbol.
For tags that expect an integer, you must use SETVALUE or SETCOMPATWITHVALUE. For tags that expect a
string, you must use SETSTRING or SETCOMPATWITHSTRING.
Use SETCOMPATWITHVALUE and SETCOMPATWITHSTRING to set tag values which the object file is also
compatible with.
Examples
ATTR SETSTRING Tag_CPU_raw_name, "Cortex-A8"
ATTR SETVALUE Tag_VFP_arch, 3 ; VFPv3 instructions permitted.
ATTR SETVALUE 10, 3 ; 10 is the numerical value of
; Tag_VFP_arch.
Related information
Addenda to, and Errata in, the ABI for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-587
reserved.
Non-Confidential
12 Directives Reference
12.10 CN
12.10 CN
The CN directive defines a name for a coprocessor register.
Syntax
name CN expr
where:
name
is the name to be defined for the coprocessor register. name cannot be the same as any of the
predefined names.
expr
evaluates to a coprocessor register number from 0 to 15.
Usage
Use CN to allocate convenient names to registers, to help you remember what you use each register for.
Note
Avoid conflicting uses of the same register under different names.
Example
power CN 6 ; defines power as a symbol for
; coprocessor register 6
Related references
2.10 Predeclared core register names on page 2-40.
2.11 Predeclared extension register names on page 2-41.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-588
reserved.
Non-Confidential
12 Directives Reference
12.11 CODE16
12.11 CODE16
The CODE16 directive instructs the assembler to interpret subsequent instructions as Thumb instructions,
using the pre-UAL assembly language syntax.
Syntax
CODE16
Usage
In files that contain code using different instruction sets, CODE16 must precede Thumb code written in
pre-UAL syntax.
If necessary, this directive also inserts one byte of padding to align to the next halfword boundary.
This directive does not assemble to any instructions. It also does not change the state. It only instructs the
assembler to assemble Thumb instructions, and inserts padding if necessary.
Related references
12.7 ARM or CODE32 on page 12-585.
12.65 THUMB on page 12-649.
12.66 THUMBX on page 12-650.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-589
reserved.
Non-Confidential
12 Directives Reference
12.12 COMMON
12.12 COMMON
The COMMON directive allocates a block of memory of the defined size, at the specified symbol.
Syntax
COMMON symbol{,size{,alignment}} {[attr]}
where:
symbol
is the symbol name. The symbol name is case-sensitive.
size
is the number of bytes to reserve.
alignment
is the alignment.
attr
can be any one of:
DYNAMIC
sets the ELF symbol visibility to STV_DEFAULT.
PROTECTED
sets the ELF symbol visibility to STV_PROTECTED.
HIDDEN
sets the ELF symbol visibility to STV_HIDDEN.
INTERNAL
sets the ELF symbol visibility to STV_INTERNAL.
Usage
You specify how the memory is aligned. If the alignment is omitted, the default alignment is four. If the
size is omitted, the default size is zero.
You can access this memory as you would any other memory, but no space is allocated by the assembler
in object files. The linker allocates the required space as zero-initialized memory during the link stage.
You cannot define, IMPORT or EXTERN a symbol that has already been created by the COMMON directive. In
the same way, if a symbol has already been defined or used with the IMPORT or EXTERN directive, you
cannot use the same symbol for the COMMON directive.
Correct example
LDR r0, =xyz
COMMON xyz,255,4 ; defines 255 bytes of ZI store, word-aligned
Incorrect example
COMMON foo,4,4
COMMON bar,4,4
foo DCD 0 ; cannot define label with same name as COMMON
IMPORT bar ; cannot import label with same name as COMMON
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-590
reserved.
Non-Confidential
12 Directives Reference
12.13 CP
12.13 CP
The CP directive defines a name for a specified coprocessor.
Syntax
name CP expr
where:
name
is the name to be assigned to the coprocessor. name cannot be the same as any of the predefined
names.
expr
evaluates to a coprocessor number within the range 0 to 15.
Usage
Use CP to allocate convenient names to coprocessors, to help you to remember what you use each one
for.
Note
Avoid conflicting uses of the same coprocessor under different names.
Example
dmu CP 6 ; defines dmu as a symbol for
; coprocessor 6
Related references
2.10 Predeclared core register names on page 2-40.
2.11 Predeclared extension register names on page 2-41.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-591
reserved.
Non-Confidential
12 Directives Reference
12.14 DATA
12.14 DATA
The DATA directive is no longer required. It is ignored by the assembler.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-592
reserved.
Non-Confidential
12 Directives Reference
12.15 DCB
12.15 DCB
The DCB directive allocates one or more bytes of memory, and defines the initial runtime contents of the
memory.
Syntax
{label} DCB expr{,expr}...
where:
expr
is either:
• A numeric expression that evaluates to an integer in the range –128 to 255.
• A quoted string. The characters of the string are loaded into consecutive bytes of store.
Usage
If DCB is followed by an instruction, use an ALIGN directive to ensure that the instruction is aligned.
= is a synonym for DCB.
Example
Unlike C strings, ARM assembler strings are not nul-terminated. You can construct a nul-terminated C
string using DCB as follows:
C_string DCB "C_string",0
Related concepts
7.14 Numeric expressions on page 7-145.
Related references
12.16 DCD and DCDU on page 12-594.
12.21 DCQ and DCQU on page 12-599.
12.22 DCW and DCWU on page 12-600.
12.64 SPACE or FILL on page 12-648.
12.5 ALIGN on page 12-580.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-593
reserved.
Non-Confidential
12 Directives Reference
12.16 DCD and DCDU
Syntax
{label} DCD{U} expr{,expr}
where:
expr
is either:
• A numeric expression.
• A PC-relative expression.
Usage
DCD inserts up to three bytes of padding before the first defined word, if necessary, to achieve four-byte
alignment.
Use DCDU if you do not require alignment.
& is a synonym for DCD.
Examples
data1 DCD 1,5,20 ; Defines 3 words containing
; decimal values 1, 5, and 20
data2 DCD mem06 + 4 ; Defines 1 word containing 4 +
; the address of the label mem06
AREA MyData, DATA, READWRITE
DCB 255 ; Now misaligned ...
data3 DCDU 1,5,20 ; Defines 3 words containing
; 1, 5 and 20, not word aligned
Related concepts
7.14 Numeric expressions on page 7-145.
Related references
12.15 DCB on page 12-593.
12.21 DCQ and DCQU on page 12-599.
12.22 DCW and DCWU on page 12-600.
12.64 SPACE or FILL on page 12-648.
12.20 DCI on page 12-598.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-594
reserved.
Non-Confidential
12 Directives Reference
12.17 DCDO
12.17 DCDO
The DCDO directive allocates one or more words of memory, aligned on four-byte boundaries, and defines
the initial runtime contents of the memory as an offset from the static base register, sb (R9).
Syntax
{label} DCDO expr{,expr}...
where:
expr
is a register-relative expression or label. The base register must be sb.
Usage
Use DCDO to allocate space in memory for static base register relative relocatable addresses.
Example
IMPORT externsym
DCDO externsym ; 32-bit word relocated by offset of
; externsym from base of SB section.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-595
reserved.
Non-Confidential
12 Directives Reference
12.18 DCFD and DCFDU
Syntax
{label} DCFD{U} fpliteral{,fpliteral}...
where:
fpliteral
is a double-precision floating-point literal.
Usage
Double-precision numbers occupy two words and must be word aligned to be used in arithmetic
operations. The assembler inserts up to three bytes of padding before the first defined number, if
necessary, to achieve four-byte alignment.
Use DCFDU if you do not require alignment.
The word order used when converting fpliteral to internal form is controlled by the floating-point
architecture selected. You cannot use DCFD or DCFDU if you select the --fpu none option.
The range for double-precision numbers is:
• Maximum 1.79769313486231571e+308.
• Minimum 2.22507385850720138e–308.
Examples
DCFD 1E308,-4E-100
DCFDU 10000,-.1,3.1E26
Related references
12.19 DCFS and DCFSU on page 12-597.
7.16 Syntax of floating-point literals on page 7-147.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-596
reserved.
Non-Confidential
12 Directives Reference
12.19 DCFS and DCFSU
Syntax
{label} DCFS{U} fpliteral{,fpliteral}...
where:
fpliteral
is a single-precision floating-point literal.
Usage
Single-precision numbers occupy one word and must be word aligned to be used in arithmetic
operations. DCFS inserts up to three bytes of padding before the first defined number, if necessary to
achieve four-byte alignment.
Use DCFSU if you do not require alignment.
The range for single-precision values is:
• Maximum 3.40282347e+38.
• Minimum 1.17549435e–38.
Examples
DCFS 1E3,-4E-9
DCFSU 1.0,-.1,3.1E6
Related references
12.18 DCFD and DCFDU on page 12-596.
7.16 Syntax of floating-point literals on page 7-147.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-597
reserved.
Non-Confidential
12 Directives Reference
12.20 DCI
12.20 DCI
The DCI directive allocates two or four-byte aligned memory and defines the initial runtime contents of
the memory.
Syntax
{label} DCI{.W} expr{,expr}
where:
expr
is a numeric expression.
.W
if present, indicates that four bytes must be inserted in Thumb code.
Usage
The DCI directive is very like the DCD or DCW directives, but the location is marked as code instead of
data. Use DCI when writing macros for new instructions not supported by the version of the assembler
you are using.
In ARM code, DCI allocates one or more words of memory, aligned on four-byte boundaries. It inserts up
to three bytes of padding before the first defined word, if necessary, to achieve four-byte alignment.
In Thumb code, DCI allocates one or more halfwords of memory, aligned on two-byte boundaries. It
inserts an initial byte of padding, if necessary, to achieve two-byte alignment.
You can use DCI to insert a bit pattern into the instruction stream. For example, use:
DCI 0x46c0
Example macro
MACRO ; this macro translates newinstr Rd,Rm
; to the appropriate machine code
newinst $Rd,$Rm
DCI 0xe16f0f10 :OR: ($Rd:SHL:12) :OR: $Rm
MEND
Related concepts
7.14 Numeric expressions on page 7-145.
Related references
12.16 DCD and DCDU on page 12-594.
12.22 DCW and DCWU on page 12-600.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-598
reserved.
Non-Confidential
12 Directives Reference
12.21 DCQ and DCQU
Syntax
{label} DCQ{U} {-}literal{,{-}literal…}
where:
literal
is a 64-bit numeric literal.
The range of numbers permitted is 0 to 264–1.
In addition to the characters normally permitted in a numeric literal, you can prefix literal
with a minus sign. In this case, the range of numbers permitted is –263 to –1.
The result of specifying -n is the same as the result of specifying 264–n.
Usage
DCQ inserts up to three bytes of padding before the first defined eight-byte block, if necessary, to achieve
four-byte alignment.
Use DCQU if you do not require alignment.
Correct example
AREA MiscData, DATA, READWRITE
data DCQ -225,2_101 ; 2_101 means binary 101.
Incorrect example
number EQU 2
DCQU number ; DCQ and DCQU only accept literals not
; expressions.
Related concepts
7.14 Numeric expressions on page 7-145.
Related references
12.15 DCB on page 12-593.
12.16 DCD and DCDU on page 12-594.
12.22 DCW and DCWU on page 12-600.
12.64 SPACE or FILL on page 12-648.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-599
reserved.
Non-Confidential
12 Directives Reference
12.22 DCW and DCWU
Syntax
{label} DCW{U} expr{,expr}...
where:
expr
is a numeric expression that evaluates to an integer in the range –32768 to 65535.
Usage
DCW inserts a byte of padding before the first defined halfword if necessary to achieve two-byte
alignment.
Use DCWU if you do not require alignment.
Examples
data DCW -225,2*number ; number must already be defined
DCWU number+4
Related concepts
7.14 Numeric expressions on page 7-145.
Related references
12.15 DCB on page 12-593.
12.16 DCD and DCDU on page 12-594.
12.21 DCQ and DCQU on page 12-599.
12.64 SPACE or FILL on page 12-648.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-600
reserved.
Non-Confidential
12 Directives Reference
12.23 DN and SN
12.23 DN and SN
The DN and SN directives define names for VFP registers.
Syntax
name directive expr{.type}
where:
name
is the name to be assigned to the extension register. name cannot be the same as any of the
predefined names.
directive
is DN or SN.
expr
Can be:
• An expression that evaluates to a number in the range:
— 0-15 if you are using DN in VFPv2.
— 0-31 otherwise.
• A predefined register name, or a register name that has already been defined in a previous
directive.
type
is any VFP datatype.
type is Extended notation.
Usage
Use DN or SN to allocate convenient names to extension registers, to help you to remember what you use
each one for.
The DN directive defines a name for a specified 64-bit extension register.
The SN directive defines a name for a specified single-precision VFP register.
Note
Avoid conflicting uses of the same register under different names.
Examples
energy DN 6 ; defines energy as a symbol for VFP double-precision register 6
mass SN 16 ; defines mass as a symbol for VFP single-precision register 16
Related concepts
8.9 VFP data types on page 8-172.
8.22 Overview of VFP directives and vector notation on page 8-186.
8.10 Extended notation extension for VFP on page 8-173.
Related references
2.10 Predeclared core register names on page 2-40.
2.11 Predeclared extension register names on page 2-41.
2.12 Predeclared coprocessor names on page 2-42.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-601
reserved.
Non-Confidential
12 Directives Reference
12.24 END
12.24 END
The END directive informs the assembler that it has reached the end of a source file.
Syntax
END
Usage
Every assembly language source file must end with END on a line by itself.
If the source file has been included in a parent file by a GET directive, the assembler returns to the parent
file and continues assembly at the first line following the GET directive.
If END is reached in the top-level source file during the first pass without any errors, the second pass
begins.
If END is reached in the top-level source file during the second pass, the assembler finishes the assembly
and writes the appropriate output.
Related references
12.44 GET or INCLUDE on page 12-623.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-602
reserved.
Non-Confidential
12 Directives Reference
12.25 ENDFUNC or ENDP
Related references
12.42 FUNCTION or PROC on page 12-621.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-603
reserved.
Non-Confidential
12 Directives Reference
12.26 ENTRY
12.26 ENTRY
The ENTRY directive declares an entry point to a program.
Syntax
ENTRY
Usage
A program must have an entry point. You can specify an entry point in the following ways:
• Using the ENTRY directive in assembly language source code.
• Providing a main() function in C or C++ source code.
• Using the armlink --entry command-line option.
You can declare more than one entry point in a program, although a source file cannot contain more than
one ENTRY directive. For example, a program could contain multiple assembly language source files,
each with an ENTRY directive. Or it could contain a C or C++ file with a main() function and one or more
assembly source files with an ENTRY directive.
If the program contains multiple entry points, then you must select one of them. You do this by exporting
the symbol for the ENTRY directive that you want to use as the entry point, then using the
armlink --entry option to select the exported symbol.
Example
AREA ARMex, CODE, READONLY
ENTRY ; Entry point for the application.
EXPORT ep1 ; Export the symbol so the linker can find it
ep1 ; in the object file.
; code
END
When you invoke armlink, if other entry points are declared in the program, then you must specify
--entry=ep1, to select ep1.
Related information
Image entry points.
--entry=location.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-604
reserved.
Non-Confidential
12 Directives Reference
12.27 EQU
12.27 EQU
The EQU directive gives a symbolic name to a numeric constant, a register-relative value or a PC-relative
value.
Syntax
name EQU expr{, type}
where:
name
is the symbolic name to assign to the value.
expr
is a register-relative address, a PC-relative address, an absolute address, or a 32-bit integer
constant.
type
is optional. type can be any one of:
• ARM.
• THUMB.
• CODE32.
• CODE16.
• DATA.
You can use type only if expr is an absolute address. If name is exported, the name entry in the
symbol table in the object file is marked as ARM, THUMB, CODE32, CODE16, or DATA, according to
type. This can be used by the linker.
Usage
Use EQU to define constants. This is similar to the use of #define to define a constant in C.
* is a synonym for EQU.
Examples
abc EQU 2 ; Assigns the value 2 to the symbol abc.
xyz EQU label+8 ; Assigns the address (label+8) to the
; symbol xyz.
fiq EQU 0x1C, CODE32 ; Assigns the absolute address 0x1C to
; the symbol fiq, and marks it as code.
Related references
12.49 KEEP on page 12-630.
12.28 EXPORT or GLOBAL on page 12-606.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-605
reserved.
Non-Confidential
12 Directives Reference
12.28 EXPORT or GLOBAL
Syntax
EXPORT {[WEAK]}
where:
symbol
is the symbol name to export. The symbol name is case-sensitive. If symbol is omitted, all
symbols are exported.
WEAK
symbol is only imported into other sources if no other source exports an alternative symbol. If
[WEAK] is used without symbol, all exported symbols are weak.
attr
can be any one of:
DYNAMIC
sets the ELF symbol visibility to STV_DEFAULT.
PROTECTED
sets the ELF symbol visibility to STV_PROTECTED.
HIDDEN
sets the ELF symbol visibility to STV_HIDDEN.
INTERNAL
sets the ELF symbol visibility to STV_INTERNAL.
type
specifies the symbol type:
DATA
symbol is treated as data when the source is assembled and linked.
CODE
symbol is treated as code when the source is assembled and linked.
ELFTYPE=n
symbol is treated as a particular ELF symbol, as specified by the value of n, where n
can be any number from 0 to 15.
If unspecified, the assembler determines the most appropriate type. Usually the assembler
determines the correct type so you are not required to specify it.
set
specifies the instruction set:
ARM
symbol is treated as an ARM symbol.
THUMB
symbol is treated as a Thumb symbol.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-606
reserved.
Non-Confidential
12 Directives Reference
12.28 EXPORT or GLOBAL
n
specifies the size and can be any 32-bit value. If the SIZE attribute is not specified, the
assembler calculates the size:
• For PROC and FUNCTION symbols, the size is set to the size of the code until its ENDP or
ENDFUNC.
• For other symbols, the size is the size of instruction or data on the same source line. If there
is no instruction or data, the size is zero.
Usage
Use EXPORT to give code in other files access to symbols in the current file.
Use the [WEAK] attribute to inform the linker that a different instance of symbol takes precedence over
this one, if a different one is available from another source. You can use the [WEAK] attribute with any of
the symbol visibility attributes.
Examples
AREA Example,CODE,READONLY
EXPORT DoAdd ; Export the function name
; to be used by external modules.
DoAdd ADD r0,r0,r1
Symbol visibility can be overridden for duplicate exports. In the following example, the last EXPORT
takes precedence for both binding and visibility:
EXPORT SymA[WEAK] ; Export as weak-hidden
EXPORT SymA[DYNAMIC] ; SymA becomes non-weak dynamic.
Related references
12.46 IMPORT and EXTERN on page 12-626.
Related information
ELF for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-607
reserved.
Non-Confidential
12 Directives Reference
12.29 EXPORTAS
12.29 EXPORTAS
The EXPORTAS directive enables you to export a symbol from the object file, corresponding to a different
symbol in the source file.
Syntax
EXPORTAS symbol1, symbol2
where:
symbol1
is the symbol name in the source file. symbol1 must have been defined already. It can be any
symbol, including an area name, a label, or a constant.
symbol2
is the symbol name you want to appear in the object file.
The symbol names are case-sensitive.
Usage
Use EXPORTAS to change a symbol in the object file without having to change every instance in the
source file.
Examples
AREA data1, DATA ; Starts a new area data1.
AREA data2, DATA ; Starts a new area data2.
EXPORTAS data2, data1 ; The section symbol referred to as data2
; appears in the object file string table as data1.
one EQU 2
EXPORTAS one, two ; The symbol 'two' appears in the object
EXPORT one ; file's symbol table with the value 2.
Related references
12.28 EXPORT or GLOBAL on page 12-606.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-608
reserved.
Non-Confidential
12 Directives Reference
12.30 FIELD
12.30 FIELD
The FIELD directive describes space within a storage map that has been defined using the MAP directive.
Syntax
{label} FIELD expr
where:
label
is an optional label. If specified, label is assigned the value of the storage location counter,
{VAR}. The storage location counter is then incremented by the value of expr.
expr
is an expression that evaluates to the number of bytes to increment the storage counter.
Usage
If a storage map is set by a MAP directive that specifies a base-register, the base register is implicit in
all labels defined by following FIELD directives, until the next MAP directive. These register-relative
labels can be quoted in load and store instructions.
# is a synonym for FIELD.
Examples
The following example shows how register-relative labels are defined using the MAP and FIELD
directives:
MAP 0,r9 ; set {VAR} to the address stored in R9
FIELD 4 ; increment {VAR} by 4 bytes
Lab FIELD 4 ; set Lab to the address [R9 + 4]
; and then increment {VAR} by 4 bytes
LDR r0,Lab ; equivalent to LDR r0,[r9,#4]
When using the MAP and FIELD directives, you must ensure that the values are consistent in both passes.
The following example shows a use of MAP and FIELD that causes inconsistent values for the symbol x. In
the first pass sym is not defined, so x is at 0x04+R9. In the second pass, sym is defined, so x is at
0x00+R0. This example results in an assembly error.
MAP 0, r0
if :LNOT: :DEF: sym
MAP 0, r9
FIELD 4 ; x is at 0x04+R9 in first pass
ENDIF
x FIELD 4 ; x is at 0x00+R0 in second pass
sym LDR r0, x ; inconsistent values for x results in assembly error
Related concepts
1.3 How the assembler works on page 1-25.
Related references
12.53 MAP on page 12-636.
1.4 Directives that can be omitted in pass 2 of the assembler on page 1-27.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-609
reserved.
Non-Confidential
12 Directives Reference
12.31 FRAME ADDRESS
Syntax
FRAME ADDRESS reg{,offset}
where:
reg
is the register on which the canonical frame address is to be based. This is SP unless the
function uses a separate frame pointer.
offset
is the offset of the canonical frame address from reg. If offset is zero, you can omit it.
Usage
Use FRAME ADDRESS if your code alters which register the canonical frame address is based on, or if it
changes the offset of the canonical frame address from the register. You must use FRAME ADDRESS
immediately after the instruction that changes the calculation of the canonical frame address.
You can only use FRAME ADDRESS in functions with FUNCTION and ENDFUNC or PROC and ENDP directives.
Note
If your code uses a single instruction to save registers and alter the stack pointer, you can use FRAME
PUSH instead of using both FRAME ADDRESS and FRAME SAVE.
If your code uses a single instruction to load registers and alter the stack pointer, you can use FRAME POP
instead of using both FRAME ADDRESS and FRAME RESTORE.
Example
_fn FUNCTION ; CFA (Canonical Frame Address) is value
; of SP on entry to function
PUSH {r4,fp,ip,lr,pc}
FRAME PUSH {r4,fp,ip,lr,pc}
SUB sp,sp,#4 ; CFA offset now changed
FRAME ADDRESS sp,24 ; - so we correct it
ADD fp,sp,#20
FRAME ADDRESS fp,4 ; New base register
; code using fp to base call-frame on, instead of SP
Related references
12.32 FRAME POP on page 12-611.
12.33 FRAME PUSH on page 12-612.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-610
reserved.
Non-Confidential
12 Directives Reference
12.32 FRAME POP
Syntax
There are the following alternative syntaxes for FRAME POP:
FRAME POP {reglist}
FRAME POP n
where:
reglist
is a list of registers restored to the values they had on entry to the function. There must be at
least one register in the list.
n
is the number of bytes that the stack pointer moves.
Usage
FRAME POP is equivalent to a FRAME ADDRESS and a FRAME RESTORE directive. You can use it when a
single instruction loads registers and alters the stack pointer.
You must use FRAME POP immediately after the instruction it refers to.
You can only use it within functions with FUNCTION and ENDFUNC or PROC and ENDP directives. You do
not have to do this after the last instruction in a function.
If n is not specified or is zero, the assembler calculates the new offset for the canonical frame address
from {reglist}. It assumes that:
• Each ARM register popped occupies four bytes on the stack.
• Each VFP single-precision register popped occupies four bytes on the stack, plus an extra four-byte
word for each list.
• Each VFP double-precision register popped occupies eight bytes on the stack, plus an extra four-byte
word for each list.
Related references
12.31 FRAME ADDRESS on page 12-610.
12.35 FRAME RESTORE on page 12-614.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-611
reserved.
Non-Confidential
12 Directives Reference
12.33 FRAME PUSH
Syntax
There are the following alternative syntaxes for FRAME PUSH:
FRAME PUSH {reglist}
FRAME PUSH n
where:
reglist
is a list of registers stored consecutively below the canonical frame address. There must be at
least one register in the list.
n
is the number of bytes that the stack pointer moves.
Usage
FRAME PUSH is equivalent to a FRAME ADDRESS and a FRAME SAVE directive. You can use it when a single
instruction saves registers and alters the stack pointer.
You must use FRAME PUSH immediately after the instruction it refers to.
You can only use it within functions with FUNCTION and ENDFUNC or PROC and ENDP directives.
If n is not specified or is zero, the assembler calculates the new offset for the canonical frame address
from {reglist}. It assumes that:
• Each ARM register pushed occupies four bytes on the stack.
• Each VFP single-precision register pushed occupies four bytes on the stack, plus an extra four-byte
word for each list.
• Each VFP double-precision register popped occupies eight bytes on the stack, plus an extra four-byte
word for each list.
Example
p PROC ; Canonical frame address is SP + 0
EXPORT p
PUSH {r4-r6,lr}
; SP has moved relative to the canonical frame address,
; and registers R4, R5, R6 and LR are now on the stack
FRAME PUSH {r4-r6,lr}
; Equivalent to:
; FRAME ADDRESS sp,16 ; 16 bytes in {R4-R6,LR}
; FRAME SAVE {r4-r6,lr},-16
Related references
12.31 FRAME ADDRESS on page 12-610.
12.37 FRAME SAVE on page 12-616.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-612
reserved.
Non-Confidential
12 Directives Reference
12.34 FRAME REGISTER
Syntax
FRAME REGISTER reg1, reg2
where:
reg1
is the register that held the argument on entry to the function.
reg2
is the register in which the value is preserved.
Usage
Use the FRAME REGISTER directive when you use a register to preserve an argument that was held in a
different register on entry to a function.
You can only use it within functions with FUNCTION and ENDFUNC or PROC and ENDP directives.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-613
reserved.
Non-Confidential
12 Directives Reference
12.35 FRAME RESTORE
Syntax
FRAME RESTORE {reglist}
where:
reglist
is a list of registers whose contents have been restored. There must be at least one register in the
list.
Usage
You can only use FRAME RESTORE within functions with FUNCTION and ENDFUNC or PROC and ENDP
directives. Use it immediately after the callee reloads registers from the stack. You do not have to do this
after the last instruction in a function.
reglist can contain integer registers or floating-point registers, but not both.
Note
If your code uses a single instruction to load registers and alter the stack pointer, you can use FRAME POP
instead of using both FRAME RESTORE and FRAME ADDRESS.
Related references
12.32 FRAME POP on page 12-611.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-614
reserved.
Non-Confidential
12 Directives Reference
12.36 FRAME RETURN ADDRESS
Syntax
FRAME RETURN ADDRESS reg
where:
reg
is the register used for the return address.
Usage
Use the FRAME RETURN ADDRESS directive in any function that does not use LR for its return address.
Otherwise, a debugger cannot backtrace through the function.
You can only use FRAME RETURN ADDRESS within functions with FUNCTION and ENDFUNC or PROC and
ENDP directives. Use it immediately after the FUNCTION or PROC directive that introduces the function.
Note
Any function that uses a register other than LR for its return address is not AAPCS compliant. Such a
function must not be exported.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-615
reserved.
Non-Confidential
12 Directives Reference
12.37 FRAME SAVE
Syntax
FRAME SAVE {reglist}, offset
where:
reglist
is a list of registers stored consecutively starting at offset from the canonical frame address.
There must be at least one register in the list.
Usage
You can only use FRAME SAVE within functions with FUNCTION and ENDFUNC or PROC and ENDP directives.
Use it immediately after the callee stores registers onto the stack.
reglist can include registers which are not required for backtracing. The assembler determines which
registers it requires to record in the DWARF call frame information.
Note
If your code uses a single instruction to save registers and alter the stack pointer, you can use FRAME
PUSH instead of using both FRAME SAVE and FRAME ADDRESS.
Related references
12.33 FRAME PUSH on page 12-612.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-616
reserved.
Non-Confidential
12 Directives Reference
12.38 FRAME STATE REMEMBER
Syntax
FRAME STATE REMEMBER
Usage
During an inline exit sequence the information about calculation of canonical frame address and
locations of saved register values can change. After the exit sequence another branch can continue using
the same information as before. Use FRAME STATE REMEMBER to preserve this information, and FRAME
STATE RESTORE to restore it.
These directives can be nested. Each FRAME STATE RESTORE directive must have a corresponding FRAME
STATE REMEMBER directive.
You can only use FRAME STATE REMEMBER within functions with FUNCTION and ENDFUNC or PROC and
ENDP directives.
Example
; function code
FRAME STATE REMEMBER
; save frame state before in-line exit sequence
POP {r4-r6,pc}
; do not have to FRAME POP here, as control has
; transferred out of the function
FRAME STATE RESTORE
; end of exit sequence, so restore state
exitB ; code for exitB
POP {r4-r6,pc}
ENDP
Related references
12.39 FRAME STATE RESTORE on page 12-618.
12.42 FUNCTION or PROC on page 12-621.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-617
reserved.
Non-Confidential
12 Directives Reference
12.39 FRAME STATE RESTORE
Syntax
FRAME STATE RESTORE
Usage
You can only use FRAME STATE RESTORE within functions with FUNCTION and ENDFUNC or PROC and ENDP
directives.
Related references
12.38 FRAME STATE REMEMBER on page 12-617.
12.42 FUNCTION or PROC on page 12-621.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-618
reserved.
Non-Confidential
12 Directives Reference
12.40 FRAME UNWIND ON
Syntax
FRAME UNWIND ON
Usage
You can use this directive outside functions. In this case, the assembler produces unwind tables for all
following functions until it reaches a FRAME UNWIND OFF directive.
Note
A FRAME UNWIND directive is not sufficient to turn on exception table generation. Furthermore a FRAME
UNWIND directive, without other FRAME directives, is not sufficient information for the assembler to
generate the unwind information.
Related references
9.29 --exceptions, --no_exceptions on page 9-225.
9.30 --exceptions_unwind, --no_exceptions_unwind on page 9-226.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-619
reserved.
Non-Confidential
12 Directives Reference
12.41 FRAME UNWIND OFF
Syntax
FRAME UNWIND OFF
Usage
You can use this directive outside functions. In this case, the assembler produces no unwind tables for all
following functions until it reaches a FRAME UNWIND ON directive.
Related references
9.29 --exceptions, --no_exceptions on page 9-225.
9.30 --exceptions_unwind, --no_exceptions_unwind on page 9-226.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-620
reserved.
Non-Confidential
12 Directives Reference
12.42 FUNCTION or PROC
Syntax
label FUNCTION [{reglist1} [, {reglist2}]]
where:
reglist1
is an optional list of callee-saved ARM registers. If reglist1 is not present, and your debugger
checks register usage, it assumes that the AAPCS is in use. If you use empty brackets, this
informs the debugger that all ARM registers are caller-saved.
reglist2
is an optional list of callee-saved VFP registers. If you use empty brackets, this informs the
debugger that all VFP registers are caller-saved.
Usage
Use FUNCTION to mark the start of functions. The assembler uses FUNCTION to identify the start of a
function when producing DWARF call frame information for ELF.
FUNCTION sets the canonical frame address to be R13 (SP), and the frame state stack to be empty.
Each FUNCTION directive must have a matching ENDFUNC directive. You must not nest FUNCTION and
ENDFUNC pairs, and they must not contain PROC or ENDP directives.
You can use the optional reglist parameters to inform the debugger about an alternative procedure call
standard, if you are using your own. Not all debuggers support this feature. See your debugger
documentation for details.
If you specify an empty reglist, using {}, this indicates that all registers for the function are caller-
saved. Typically you do this when writing a reset vector where the values in all registers are unknown on
execution. This avoids problems in a debugger if it tries to construct a backtrace from the values in the
registers.
Note
FUNCTION does not automatically cause alignment to a word boundary (or halfword boundary for
Thumb). Use ALIGN if necessary to ensure alignment, otherwise the call frame might not point to the start
of the function.
Examples
ALIGN ; Ensures alignment.
dadd FUNCTION ; Without the ALIGN directive this might not be word-aligned.
EXPORT dadd
PUSH {r4-r6,lr} ; This line automatically word-aligned.
FRAME PUSH {r4-r6,lr}
; subroutine body
POP {r4-r6,pc}
ENDFUNC
func6 PROC {r4-r8,r12},{D1-D3} ; Non-AAPCS-conforming function.
...
ENDP
func7 FUNCTION {} ; Another non-AAPCS-conforming function.
...
ENDFUNC
Related references
12.39 FRAME STATE RESTORE on page 12-618.
12.31 FRAME ADDRESS on page 12-610.
12.5 ALIGN on page 12-580.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-621
reserved.
Non-Confidential
12 Directives Reference
12.43 GBLA, GBLL, and GBLS
Syntax
gblx variable
where:
gblx
is one of GBLA, GBLL, or GBLS.
variable
is the name of the variable. variable must be unique among symbols within a source file.
Usage
The GBLA directive declares a global arithmetic variable, and initializes its value to 0.
The GBLL directive declares a global logical variable, and initializes its value to {FALSE}.
The GBLS directive declares a global string variable and initializes its value to a null string, "".
Using one of these directives for a variable that is already defined re-initializes the variable.
The scope of the variable is limited to the source file that contains it.
Set the value of the variable with a SETA, SETL, or SETS directive.
Global variables can also be set with the --predefine assembler command-line option.
Examples
The following example declares a variable objectsize, sets the value of objectsize to 0xFF, and then
uses it later in a SPACE directive:
GBLA objectsize ; declare the variable name
objectsize SETA 0xFF ; set its value
.
. ; other code
.
SPACE objectsize ; quote the variable
The following example shows how to declare and set a variable when you invoke armasm. Use this when
you want to set the value of a variable at assembly time. --pd is a synonym for --predefine.
armasm --predefine "objectsize SETA 0xFF" sourcefile -o objectfile
Related references
12.50 LCLA, LCLL, and LCLS on page 12-631.
12.63 SETA, SETL, and SETS on page 12-647.
9.57 --predefine "directive" on page 9-254.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-622
reserved.
Non-Confidential
12 Directives Reference
12.44 GET or INCLUDE
Syntax
GET filename
where:
filename
is the name of the file to be included in the assembly. The assembler accepts pathnames in either
UNIX or MS-DOS format.
Usage
GET is useful for including macro definitions, EQUs, and storage maps in an assembly. When assembly of
the included file is complete, assembly continues at the line following the GET directive.
By default the assembler searches the current place for included files. The current place is the directory
where the calling file is located. Use the -i assembler command line option to add directories to the
search path. File names and directory names containing spaces must not be enclosed in double quotes ( "
" ).
The included file can contain additional GET directives to include other files.
If the included file is in a different directory from the current place, this becomes the current place until
the end of the included file. The previous current place is then restored.
You cannot use GET to include object files.
Examples
AREA Example, CODE, READONLY
GET file1.s ; includes file1 if it exists in the current place
GET c:\project\file2.s ; includes file2
GET c:\Program files\file3.s ; space is permitted
Related references
12.47 INCBIN on page 12-628.
12.2 About assembly control directives on page 12-577.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-623
reserved.
Non-Confidential
12 Directives Reference
12.45 IF, ELSE, ENDIF, and ELIF
Syntax
IF logical-expression
…;code
{ELSE
…;code}
ENDIF
where:
logical-expression
is an expression that evaluates to either {TRUE} or {FALSE}.
Usage
Use IF with ENDIF, and optionally with ELSE, for sequences of instructions or directives that are only to
be assembled or acted on under a specified condition.
IF...ENDIF conditions can be nested.
The IF directive introduces a condition that controls whether to assemble a sequence of instructions and
directives. [ is a synonym for IF.
The ELSE directive marks the beginning of a sequence of instructions or directives that you want to be
assembled if the preceding condition fails. | is a synonym for ELSE.
The ENDIF directive marks the end of a sequence of instructions or directives that you want to be
conditionally assembled. ] is a synonym for ENDIF.
The ELIF directive creates a structure equivalent to ELSE IF, without the requirement for nesting or
repeating the condition.
Using ELIF
Without using ELIF, you can construct a nested set of conditional instructions like this:
IF logical-expression
instructions
ELSE
IF logical-expression2
instructions
ELSE
IF logical-expression3
instructions
ENDIF
ENDIF
ENDIF
This structure only adds one to the current nesting depth, for the IF...ENDIF pair.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-624
reserved.
Non-Confidential
12 Directives Reference
12.45 IF, ELSE, ENDIF, and ELIF
Examples
The following example assembles the first set of instructions if NEWVERSION is defined, or the alternative
set otherwise:
Assembly conditional on a variable being defined
IF :DEF:NEWVERSION
; first set of instructions or directives
ELSE
; alternative set of instructions or directives
ENDIF
Invoking armasm as follows defines NEWVERSION, so the first set of instructions and directives are
assembled:
armasm --predefine "NEWVERSION SETL {TRUE}" test.s
Invoking armasm as follows leaves NEWVERSION undefined, so the second set of instructions and
directives are assembled:
armasm test.s
The following example assembles the first set of instructions if NEWVERSION has the value {TRUE}, or the
alternative set otherwise:
Assembly conditional on a variable value
IF NEWVERSION = {TRUE}
; first set of instructions or directives
ELSE
; alternative set of instructions or directives
ENDIF
Invoking armasm as follows causes the first set of instructions and directives to be assembled:
armasm --predefine "NEWVERSION SETL {TRUE}" test.s
Invoking armasm as follows causes the second set of instructions and directives to be assembled:
armasm --predefine "NEWVERSION SETL {FALSE}" test.s
Related references
7.25 Relational operators on page 7-156.
12.2 About assembly control directives on page 12-577.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-625
reserved.
Non-Confidential
12 Directives Reference
12.46 IMPORT and EXTERN
Syntax
directive symbol {[SIZE=n]}
where:
directive
can be either:
IMPORT
imports the symbol unconditionally.
EXTERN
imports the symbol only if it is referred to in the current assembly.
symbol
is a symbol name defined in a separately assembled source file, object file, or library. The
symbol name is case-sensitive.
WEAK
prevents the linker generating an error message if the symbol is not defined elsewhere. It also
prevents the linker searching libraries that are not already included.
attr
can be any one of:
DYNAMIC
sets the ELF symbol visibility to STV_DEFAULT.
PROTECTED
sets the ELF symbol visibility to STV_PROTECTED.
HIDDEN
sets the ELF symbol visibility to STV_HIDDEN.
INTERNAL
sets the ELF symbol visibility to STV_INTERNAL.
type
specifies the symbol type:
DATA
symbol is treated as data when the source is assembled and linked.
CODE
symbol is treated as code when the source is assembled and linked.
ELFTYPE=n
symbol is treated as a particular ELF symbol, as specified by the value of n, where n
can be any number from 0 to 15.
If unspecified, the linker determines the most appropriate type.
n
specifies the size and can be any 32-bit value. If the SIZE attribute is not specified, the
assembler calculates the size:
• For PROC and FUNCTION symbols, the size is set to the size of the code until its ENDP or
ENDFUNC.
• For other symbols, the size is the size of instruction or data on the same source line. If there
is no instruction or data, the size is zero.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-626
reserved.
Non-Confidential
12 Directives Reference
12.46 IMPORT and EXTERN
Usage
The name is resolved at link time to a symbol defined in a separate object file. The symbol is treated as a
program address. If [WEAK] is not specified, the linker generates an error if no corresponding symbol is
found at link time.
If [WEAK] is specified and no corresponding symbol is found at link time:
• If the reference is the destination of a B or BL instruction, the value of the symbol is taken as the
address of the following instruction. This makes the B or BL instruction effectively a NOP.
• Otherwise, the value of the symbol is taken as zero.
Example
The example tests to see if the C++ library has been linked, and branches conditionally on the result.
AREA Example, CODE, READONLY
EXTERN __CPP_INITIALIZE[WEAK] ; If C++ library linked, gets the
; address of __CPP_INITIALIZE
; function.
LDR r0,=__CPP_INITIALIZE ; If not linked, address is zeroed.
CMP r0,#0 ; Test if zero.
BEQ nocplusplus ; Branch on the result.
Related references
12.28 EXPORT or GLOBAL on page 12-606.
Related information
ELF for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-627
reserved.
Non-Confidential
12 Directives Reference
12.47 INCBIN
12.47 INCBIN
The INCBIN directive includes a file within the file being assembled. The file is included as it is, without
being assembled.
Syntax
INCBIN filename
where:
filename
is the name of the file to be included in the assembly. The assembler accepts pathnames in either
UNIX or MS-DOS format.
Usage
You can use INCBIN to include executable files, literals, or any arbitrary data. The contents of the file are
added to the current ELF section, byte for byte, without being interpreted in any way. Assembly
continues at the line following the INCBIN directive.
By default, the assembler searches the current place for included files. The current place is the directory
where the calling file is located. Use the -i assembler command-line option to add directories to the
search path. File names and directory names containing spaces must not be enclosed in double quotes ( "
" ).
Example
AREA Example, CODE, READONLY
INCBIN file1.dat ; Includes file1 if it exists in the current place
INCBIN c:\project\file2.txt ; Includes file2.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-628
reserved.
Non-Confidential
12 Directives Reference
12.48 INFO
12.48 INFO
The INFO directive supports diagnostic generation on either pass of the assembly.
Syntax
INFO numeric-expression, string-expression{, severity}
where:
numeric-expression
is a numeric expression that is evaluated during assembly. If the expression evaluates to zero:
• No action is taken during pass one.
• string-expression is printed as a warning during pass two if severity is 1.
• string-expression is printed as a message during pass two if severity is 0 or not
specified.
If the expression does not evaluate to zero:
• string-expression is printed as an error message and the assembly fails irrespective of
whether severity is specified or not (non-zero values for severity are reserved in this
case).
string-expression
is an expression that evaluates to a string.
severity
is an optional number that controls the severity of the message. Its value can be either 0 or 1. All
other values are reserved.
Usage
INFO provides a flexible means of creating custom error messages.
Examples
INFO 0, "Version 1.0"
IF endofdata <= label1
INFO 4, "Data overrun at label1"
ENDIF
Related concepts
7.12 String expressions on page 7-143.
7.14 Numeric expressions on page 7-145.
Related references
12.8 ASSERT on page 12-586.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-629
reserved.
Non-Confidential
12 Directives Reference
12.49 KEEP
12.49 KEEP
The KEEP directive instructs the assembler to retain named local labels in the symbol table in the object
file.
Syntax
KEEP {label}
where:
label
is the name of the local label to keep. If label is not specified, all named local labels are kept
except register-relative labels.
Usage
By default, the only labels that the assembler describes in its output object file are:
• Exported labels.
• Labels that are relocated against.
Use KEEP to preserve local labels. This can help when debugging. Kept labels appear in the ARM
debuggers and in linker map files.
KEEP cannot preserve register-relative labels or numeric local labels.
Example
label ADC r2,r3,r4
KEEP label ; makes label available to debuggers
ADD r2,r2,r5
Related concepts
7.10 Numeric local labels on page 7-141.
Related references
12.53 MAP on page 12-636.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-630
reserved.
Non-Confidential
12 Directives Reference
12.50 LCLA, LCLL, and LCLS
Syntax
lclx variable
where:
lclx
is one of LCLA, LCLL, or LCLS.
variable
is the name of the variable. variable must be unique within the macro that contains it.
Usage
The LCLA directive declares a local arithmetic variable, and initializes its value to 0.
The LCLL directive declares a local logical variable, and initializes its value to {FALSE}.
The LCLS directive declares a local string variable, and initializes its value to a null string, "".
Using one of these directives for a variable that is already defined re-initializes the variable.
The scope of the variable is limited to a particular instantiation of the macro that contains it.
Set the value of the variable with a SETA, SETL, or SETS directive.
Example
MACRO ; Declare a macro
$label message $a ; Macro prototype line
LCLS err ; Declare local string
; variable err.
err SETS "error no: " ; Set value of err
$label ; code
INFO 0, "err":CC::STR:$a ; Use string
MEND
Related references
12.43 GBLA, GBLL, and GBLS on page 12-622.
12.63 SETA, SETL, and SETS on page 12-647.
12.52 MACRO and MEND on page 12-633.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-631
reserved.
Non-Confidential
12 Directives Reference
12.51 LTORG
12.51 LTORG
The LTORG directive instructs the assembler to assemble the current literal pool immediately.
Syntax
LTORG
Usage
The assembler assembles the current literal pool at the end of every code section. The end of a code
section is determined by the AREA directive at the beginning of the following section, or the end of the
assembly.
These default literal pools can sometimes be out of range of some LDR, VLDR, and WLDR pseudo-
instructions. Use LTORG to ensure that a literal pool is assembled within range.
Large programs can require several literal pools. Place LTORG directives after unconditional branches or
subroutine return instructions so that the processor does not attempt to execute the constants as
instructions.
The assembler word-aligns data in literal pools.
Example
AREA Example, CODE, READONLY
start BL func1
func1 ; function body
; code
LDR r1,=0x55555555 ; => LDR R1, [pc, #offset to Literal Pool 1]
; code
MOV pc,lr ; end function
LTORG ; Literal Pool 1 contains literal &55555555.
data SPACE 4200 ; Clears 4200 bytes of memory starting at current location.
END ; Default literal pool is empty.
Related references
10.46 LDR pseudo-instruction on page 10-356.
11.14 VLDR pseudo-instruction on page 11-553.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-632
reserved.
Non-Confidential
12 Directives Reference
12.52 MACRO and MEND
Syntax
These two directives define a macro. The syntax is:
MACRO
{$label} macroname{$cond} {$parameter{,$parameter}...}
; code
MEND
where:
$label
is a parameter that is substituted with a symbol given when the macro is invoked. The symbol is
usually a label.
macroname
is the name of the macro. It must not begin with an instruction or directive name.
$cond
is a special parameter designed to contain a condition code. Values other than valid condition
codes are permitted.
$parameter
is a parameter that is substituted when the macro is invoked. A default value for a parameter can
be set using this format:
$parameter="default value"
Double quotes must be used if there are any spaces within, or at either end of, the default value.
Usage
If you start any WHILE...WEND loops or IF...ENDIF conditions within a macro, they must be closed
before the MEND directive is reached. You can use MEXIT to enable an early exit from a macro, for
example, from within a loop.
Within the macro body, parameters such as $label, $parameter or $cond can be used in the same way
as other variables. They are given new values each time the macro is invoked. Parameters must begin
with $ to distinguish them from ordinary symbols. Any number of parameters can be used.
$label is optional. It is useful if the macro defines internal labels. It is treated as a parameter to the
macro. It does not necessarily represent the first instruction in the macro expansion. The macro defines
the locations of any labels.
Use | as the argument to use the default value of a parameter. An empty string is used if the argument is
omitted.
In a macro that uses several internal labels, it is useful to define each internal label as the base label with
a different suffix.
Use a dot between a parameter and following text, or a following parameter, if a space is not required in
the expansion. Do not use a dot between preceding text and a parameter.
You can use the $cond parameter for condition codes. Use the unary operator :REVERSE_CC: to find the
inverse condition code, and :CC_ENCODING: to find the 4-bit encoding of the condition code.
Macros define the scope of local variables.
Macros can be nested.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-633
reserved.
Non-Confidential
12 Directives Reference
12.52 MACRO and MEND
Examples
A macro that uses internal labels to implement loops:
; macro definition
MACRO ; start macro definition
$label xmac $p1,$p2
; code
$label.loop1 ; code
; code
BGE $label.loop1
$label.loop2 ; code
BL $p1
BGT $label.loop2
; code
ADR $p2
; code
MEND ; end macro definition
; macro invocation
abc xmac subr1,de ; invoke macro
; code ; this is what is
abcloop1 ; code ; is produced when
; code ; the xmac macro is
BGE abcloop1 ; expanded
abcloop2 ; code
BL subr1
BGT abcloop2
; code
ADR de
; code
When variables are being passed in as arguments, use of | might leave some variables unsubstituted. To
work around this, define the | in a LCLS or GBLS variable and pass this variable as an argument instead of
|. For example:
MACRO ; Macro definition
m2 $a,$b=r1,$c ; The default value for $b is r1
add $a,$b,$c ; The macro adds $b and $c and puts result in $a.
MEND ; Macro end
MACRO ; Macro definition
m1 $a,$b ; This macro adds $b to r1 and puts result in $a.
LCLS def ; Declare a local string variable for |
def SETS "|" ; Define |
m2 $a,$def,$b ; Invoke macro m2 with $def instead of |
; to use the default value for the second argument.
MEND ; Macro end
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-634
reserved.
Non-Confidential
12 Directives Reference
12.52 MACRO and MEND
Related concepts
4.21 Use of macros on page 4-85.
7.4 Assembly time substitution of variables on page 7-135.
Related references
12.54 MEXIT on page 12-637.
12.43 GBLA, GBLL, and GBLS on page 12-622.
12.50 LCLA, LCLL, and LCLS on page 12-631.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-635
reserved.
Non-Confidential
12 Directives Reference
12.53 MAP
12.53 MAP
The MAP directive sets the origin of a storage map to a specified address.
Syntax
MAP expr{,base-register}
where:
expr
is a numeric or PC-relative expression:
• If base-register is not specified, expr evaluates to the address where the storage map
starts. The storage map location counter is set to this address.
• If expr is PC-relative, you must have defined the label before you use it in the map. The map
requires the definition of the label during the first pass of the assembler.
base-register
specifies a register. If base-register is specified, the address where the storage map starts is
the sum of expr, and the value in base-register at runtime.
Usage
Use the MAP directive in combination with the FIELD directive to describe a storage map.
Specify base-register to define register-relative labels. The base register becomes implicit in all labels
defined by following FIELD directives, until the next MAP directive. The register-relative labels can be
used in load and store instructions.
The MAP directive can be used any number of times to define multiple storage maps.
The storage-map location counter, {VAR}, is set to the same address as that specified by the MAP directive.
The {VAR} counter is set to zero before the first MAP directive is used.
^ is a synonym for MAP.
Examples
MAP 0,r9
MAP 0xff,r9
Related concepts
1.3 How the assembler works on page 1-25.
Related references
12.30 FIELD on page 12-609.
1.4 Directives that can be omitted in pass 2 of the assembler on page 1-27.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-636
reserved.
Non-Confidential
12 Directives Reference
12.54 MEXIT
12.54 MEXIT
The MEXIT directive exits a macro definition before the end.
Usage
Use MEXIT when you require an exit from within the body of a macro. Any unclosed WHILE...WEND
loops or IF...ENDIF conditions within the body of the macro are closed by the assembler before the
macro is exited.
Example
MACRO
$abc example abc $param1,$param2
; code
WHILE condition1
; code
IF condition2
; code
MEXIT
ELSE
; code
ENDIF
WEND
; code
MEND
Related references
12.52 MACRO and MEND on page 12-633.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-637
reserved.
Non-Confidential
12 Directives Reference
12.55 NOFP
12.55 NOFP
The NOFP directive ensures that there are no floating-point instructions in an assembly language source
file.
Syntax
NOFP
Usage
Use NOFP to ensure that no floating-point instructions are used in situations where there is no support for
floating-point instructions either in software or in target hardware.
If a floating-point instruction occurs after the NOFP directive, an Unknown opcode error is generated and
the assembly fails.
If a NOFP directive occurs after a floating-point instruction, the assembler generates the error:
Too late to ban floating point instructions
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-638
reserved.
Non-Confidential
12 Directives Reference
12.56 OPT
12.56 OPT
The OPT directive sets listing options from within the source code.
Syntax
OPT n
where:
n
is the OPT directive setting. The following table lists the valid settings:
OPT n Effect
1 Turns on normal listing.
2 Turns off normal listing.
4 Page throw. Issues an immediate form feed and starts a new page.
8 Resets the line number counter to zero.
16 Turns on listing for SET, GBL and LCL directives.
32 Turns off listing for SET, GBL and LCL directives.
64 Turns on listing of macro expansions.
128 Turns off listing of macro expansions.
256 Turns on listing of macro invocations.
512 Turns off listing of macro invocations.
1024 Turns on the first pass listing.
2048 Turns off the first pass listing.
4096 Turns on listing of conditional directives.
8192 Turns off listing of conditional directives.
16384 Turns on listing of MEND directives.
32768 Turns off listing of MEND directives.
Usage
Specify the --list= assembler option to turn on listing.
By default the --list= option produces a normal listing that includes variable declarations, macro
expansions, call-conditioned directives, and MEND directives. The listing is produced on the second pass
only. Use the OPT directive to modify the default listing options from within your code.
You can use OPT to format code listings. For example, you can specify a new page before functions and
sections.
Example
AREA Example, CODE, READONLY
start ; code
; code
BL func1
; code
OPT 4 ; places a page break before func1
func1 ; code
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-639
reserved.
Non-Confidential
12 Directives Reference
12.56 OPT
Related references
9.43 --list=file on page 9-240.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-640
reserved.
Non-Confidential
12 Directives Reference
12.57 RELOC
12.57 RELOC
The RELOC directive explicitly encodes an ELF relocation in an object file.
Syntax
RELOC n, symbol
RELOC n
where:
n
must be an integer in the range 0 to 255 or one of the relocation names defined in the
Application Binary Interface for the ARM Architecture.
symbol
can be any PC-relative label.
Usage
Use RELOC n, symbol to create a relocation with respect to the address labeled by symbol.
If used immediately after an ARM or Thumb instruction, RELOC results in a relocation at that instruction.
If used immediately after a DCB, DCW, or DCD, or any other data generating directive, RELOC results in a
relocation at the start of the data. Any addend to be applied must be encoded in the instruction or in the
data.
If the assembler has already emitted a relocation at that place, the relocation is updated with the details in
the RELOC directive, for example:
DCD sym2 ; R_ARM_ABS32 to sym32
RELOC 55 ; ... makes it R_ARM_ABS32_NOI
RELOC is faulted in all other cases, for example, after any non-data generating directive, LTORG, ALIGN, or
as the first thing in an AREA.
Use RELOC n to create a relocation with respect to the anonymous symbol, that is, symbol 0 of the symbol
table. If you use RELOC n without a preceding assembler generated relocation, the relocation is with
respect to the anonymous symbol.
Examples
IMPORT impsym
LDR r0,[pc,#-8]
RELOC 4, impsym
DCD 0
RELOC 2, sym
DCD 0,1,2,3,4 ; the final word is relocated
RELOC 38,sym2 ; R_ARM_TARGET1
DCD impsym
RELOC R_ARM_TARGET1 ; relocation code 38
Related information
Application Binary Interface for the ARM Architecture.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-641
reserved.
Non-Confidential
12 Directives Reference
12.58 REQUIRE
12.58 REQUIRE
The REQUIRE directive specifies a dependency between sections.
Syntax
REQUIRE label
where:
label
is the name of the required label.
Usage
Use REQUIRE to ensure that a related section is included, even if it is not directly called. If the section
containing the REQUIRE directive is included in a link, the linker also includes the section containing the
definition of the specified label.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-642
reserved.
Non-Confidential
12 Directives Reference
12.59 REQUIRE8 and PRESERVE8
Syntax
REQUIRE8 {bool}
PRESERVE8 {bool}
where:
bool
is an optional Boolean constant, either {TRUE} or {FALSE}.
Usage
Where required, if your code preserves eight-byte alignment of the stack, use PRESERVE8 to set the PRES8
build attribute on your file. If your code does not preserve eight-byte alignment of the stack, use
PRESERVE8 {FALSE} to ensure that the PRES8 build attribute is not set. Use REQUIRE8 to set the REQ8
build attribute. If there are multiple REQUIRE8 or PRESERVE8 directives in a file, the assembler uses the
value of the last directive.
The linker checks that any code that requires eight-byte alignment of the stack is only called, directly or
indirectly, by code that preserves eight-byte alignment of the stack.
Note
If you omit both PRESERVE8 and PRESERVE8 {FALSE}, the assembler decides whether to set the PRES8
build attribute or not, by examining instructions that modify the SP. ARM recommends that you specify
PRESERVE8 explicitly.
You can enable a warning by using the --diag_warning 1546 option when invoking armasm.
This gives you warnings like:
"test.s", line 37: Warning: A1546W: Stack pointer update potentially breaks 8 byte stack
alignment
37 00000044 STMFD sp!,{r2,r3,lr}
Examples
REQUIRE8
REQUIRE8 {TRUE} ; equivalent to REQUIRE8
REQUIRE8 {FALSE} ; equivalent to absence of REQUIRE8
PRESERVE8 {TRUE} ; equivalent to PRESERVE8
PRESERVE8 {FALSE} ; NOT exactly equivalent to absence of PRESERVE8
Related references
9.22 --diag_warning=tag[,tag,…] on page 9-218.
Related information
Eight-byte Stack Alignment.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-643
reserved.
Non-Confidential
12 Directives Reference
12.60 RLIST
12.60 RLIST
The RLIST (register list) directive gives a name to a set of general-purpose registers.
Syntax
name RLIST {list-of-registers}
where:
name
is the name to be given to the set of registers. name cannot be the same as any of the predefined
names.
list-of-registers
is a comma-delimited list of register names and register ranges. The register list must be
enclosed in braces.
Usage
Use RLIST to give a name to a set of registers to be transferred by the LDM or STM instructions.
LDM and STM always put the lowest physical register numbers at the lowest address in memory, regardless
of the order they are supplied to the LDM or STM instruction. If you have defined your own symbolic
register names it can be less apparent that a register list is not in increasing register order.
Use the --diag_warning 1206 assembler option to ensure that the registers in a register list are supplied
in increasing register order. If registers are not supplied in increasing register order, a warning is issued.
Example
Context RLIST {r0-r6,r8,r10-r12,pc}
Related references
2.10 Predeclared core register names on page 2-40.
2.11 Predeclared extension register names on page 2-41.
2.12 Predeclared coprocessor names on page 2-42.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-644
reserved.
Non-Confidential
12 Directives Reference
12.61 RN
12.61 RN
The RN directive defines a name for a specified register.
Syntax
name RN expr
where:
name
is the name to be assigned to the register. name cannot be the same as any of the predefined
names.
expr
evaluates to a register number from 0 to 15.
Usage
Use RN to allocate convenient names to registers, to help you to remember what you use each register for.
Be careful to avoid conflicting uses of the same register under different names.
Examples
regname RN 11 ; defines regname for register 11
sqr4 RN r6 ; defines sqr4 for register 6
Related references
2.10 Predeclared core register names on page 2-40.
2.11 Predeclared extension register names on page 2-41.
2.12 Predeclared coprocessor names on page 2-42.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-645
reserved.
Non-Confidential
12 Directives Reference
12.62 ROUT
12.62 ROUT
The ROUT directive marks the boundaries of the scope of numeric local labels.
Syntax
{name} ROUT
where:
name
is the name to be assigned to the scope.
Usage
Use the ROUT directive to limit the scope of numeric local labels. This makes it easier for you to avoid
referring to a wrong label by accident. The scope of numeric local labels is the whole area if there are no
ROUT directives in it.
Use the name option to ensure that each reference is to the correct numeric local label. If the name of a
label or a reference to a label does not match the preceding ROUT directive, the assembler generates an
error message and the assembly fails.
Example
; code
routineA ROUT ; ROUT is not necessarily a routine
; code
3routineA ; code ; this label is checked
; code
BEQ %4routineA ; this reference is checked
; code
BGE %3 ; refers to 3 above, but not checked
; code
4routineA ; code ; this label is checked
; code
otherstuff ROUT ; start of next scope
Related concepts
7.10 Numeric local labels on page 7-141.
Related references
12.6 AREA on page 12-582.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-646
reserved.
Non-Confidential
12 Directives Reference
12.63 SETA, SETL, and SETS
Syntax
variable setx expr
where:
variable
is the name of a variable declared by a GBLA, GBLL, GBLS, LCLA, LCLL, or LCLS directive.
setx
is one of SETA, SETL, or SETS.
expr
is an expression that is:
• Numeric, for SETA.
• Logical, for SETL.
• String, for SETS.
Usage
The SETA directive sets the value of a local or global arithmetic variable.
The SETL directive sets the value of a local or global logical variable.
The SETS directive sets the value of a local or global string variable.
You must declare variable using a global or local declaration directive before using one of these
directives.
You can also predefine variable names on the command line.
Examples
GBLA VersionNumber
VersionNumber SETA 21
GBLL Debug
Debug SETL {TRUE}
GBLS VersionString
VersionString SETS "Version 1.0"
Related concepts
7.12 String expressions on page 7-143.
7.14 Numeric expressions on page 7-145.
7.17 Logical expressions on page 7-148.
Related references
12.43 GBLA, GBLL, and GBLS on page 12-622.
12.50 LCLA, LCLL, and LCLS on page 12-631.
9.57 --predefine "directive" on page 9-254.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-647
reserved.
Non-Confidential
12 Directives Reference
12.64 SPACE or FILL
Syntax
{label} SPACE expr
where:
label
is an optional label.
expr
evaluates to the number of bytes to fill or zero.
value
evaluates to the value to fill the reserved bytes with. value is optional and if omitted, it is 0.
value must be 0 in a NOINIT area.
valuesize
is the size, in bytes, of value. It can be any of 1, 2, or 4. valuesize is optional and if omitted, it
is 1.
Usage
Use the ALIGN directive to align any code following a SPACE or FILL directive.
% is a synonym for SPACE.
Example
AREA MyData, DATA, READWRITE
data1 SPACE 255 ; defines 255 bytes of zeroed store
data2 FILL 50,0xAB,1 ; defines 50 bytes containing 0xAB
Related concepts
7.14 Numeric expressions on page 7-145.
Related references
12.5 ALIGN on page 12-580.
12.15 DCB on page 12-593.
12.16 DCD and DCDU on page 12-594.
12.21 DCQ and DCQU on page 12-599.
12.22 DCW and DCWU on page 12-600.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-648
reserved.
Non-Confidential
12 Directives Reference
12.65 THUMB
12.65 THUMB
The THUMB directive instructs the assembler to interpret subsequent instructions as Thumb instructions,
using the UAL syntax.
Syntax
THUMB
Usage
In files that contain code using different instruction sets, THUMB must precede Thumb code written in
UAL syntax.
If necessary, this directive also inserts one byte of padding to align to the next halfword boundary.
This directive does not assemble to any instructions. It also does not change the state. It only instructs the
assembler to assemble Thumb instructions, and inserts padding if necessary.
Related references
12.7 ARM or CODE32 on page 12-585.
12.11 CODE16 on page 12-589.
12.66 THUMBX on page 12-650.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-649
reserved.
Non-Confidential
12 Directives Reference
12.66 THUMBX
12.66 THUMBX
The THUMBX directive instructs the assembler to interpret subsequent instructions as ThumbEE
instructions, using the UAL syntax.
Syntax
THUMBX
Usage
In files that contain code using different instruction sets, THUMBX must precede ThumbEE code written in
UAL syntax.
If necessary, this directive also inserts one byte of padding to align to the next halfword boundary.
This directive does not assemble to any instructions. It also does not change the state. It only instructs the
assembler to assemble ThumbEE instructions, and inserts padding if necessary.
Note
• ARM deprecates the use of ThumbEE instructions.
• For descriptions of ThumbEE instructions, see the ARM Architecture Reference Manual.
Related references
12.7 ARM or CODE32 on page 12-585.
12.11 CODE16 on page 12-589.
12.65 THUMB on page 12-649.
Related information
ARM Architecture Reference Manual.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-650
reserved.
Non-Confidential
12 Directives Reference
12.67 TTL and SUBT
Syntax
TTL title
SUBT subtitle
where:
title
is the title.
subtitle
is the subtitle.
Usage
Use the TTL directive to place a title at the top of each page of a listing file. If you want the title to appear
on the first page, the TTL directive must be on the first line of the source file.
Use additional TTL directives to change the title. Each new TTL directive takes effect from the top of the
next page.
Use SUBT to place a subtitle at the top of each page of a listing file. Subtitles appear in the line below the
titles. If you want the subtitle to appear on the first page, the SUBT directive must be on the first line of
the source file.
Use additional SUBT directives to change subtitles. Each new SUBT directive takes effect from the top of
the next page.
Examples
TTL First Title ; places title on first and subsequent pages of listing file.
SUBT First Subtitle ; places subtitle on second and subsequent pages of listing file.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-651
reserved.
Non-Confidential
12 Directives Reference
12.68 WHILE and WEND
Syntax
WHILE logical-expression
code
WEND
where:
logical-expression
is an expression that can evaluate to either {TRUE} or {FALSE}.
Usage
Use the WHILE directive, together with the WEND directive, to assemble a sequence of instructions a
number of times. The number of repetitions can be zero.
You can use IF...ENDIF conditions within WHILE...WEND loops.
WHILE...WEND loops can be nested.
Example
GBLA count ; declare local variable
count SETA 1 ; you are not restricted to
WHILE count <= 4 ; such simple conditions
count SETA count+1 ; In this case, this code is
; code ; executed four times
; code ;
WEND
Related concepts
7.17 Logical expressions on page 7-148.
Related references
12.2 About assembly control directives on page 12-577.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 12-652
reserved.
Non-Confidential
Chapter 13
Via File Syntax
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 13-653
reserved.
Non-Confidential
13 Via File Syntax
13.1 Overview of via files
Note
In general, you can use a via file to specify any command-line option to a tool, including --via. This
means that you can call multiple nested via files from within a via file.
Related references
13.2 Via file syntax rules on page 13-655.
9.69 --via=filename on page 9-266.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 13-654
reserved.
Non-Confidential
13 Via File Syntax
13.2 Via file syntax rules
A comment ends at the end of a line, or at the end of the file. There are no multi-line comments, and
there are no part-line comments.
Related concepts
13.1 Overview of via files on page 13-654.
Related references
9.69 --via=filename on page 9-266.
ARM DUI0379G Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights 13-655
reserved.
Non-Confidential