1 @--- 2 @ Run these test in both Thumb1 and Thumb2 modes, as all of the encodings 3 @ should be valid, and parse the same, in both. 4 @--- 5 @ RUN: llvm-mc -triple=thumbv6-apple-darwin -show-encoding < %s | FileCheck %s 6 @ RUN: llvm-mc -triple=thumbv7-apple-darwin -show-encoding < %s | FileCheck %s 7 .syntax unified 8 .globl _func 9 10 @ Check that the assembler can handle the documented syntax from the ARM ARM. 11 @ For complex constructs like shifter operands, check more thoroughly for them 12 @ once then spot check that following instructions accept the form generally. 13 @ This gives us good coverage while keeping the overall size of the test 14 @ more reasonable. 15 16 17 @ FIXME: Some 3-operand instructions have a 2-operand assembly syntax. 18 19 _func: 20 @ CHECK: _func 21 22 @------------------------------------------------------------------------------ 23 @ ADC (register) 24 @------------------------------------------------------------------------------ 25 adcs r4, r6 26 27 @ CHECK: adcs r4, r6 @ encoding: [0x74,0x41] 28 29 30 @------------------------------------------------------------------------------ 31 @ ADD (immediate) 32 @------------------------------------------------------------------------------ 33 adds r1, r2, #3 34 @ When Rd is not explicitly specified, encoding T2 is preferred even though 35 @ the literal is in the range [0,7] which would allow encoding T1. 36 adds r2, #3 37 adds r2, #8 38 39 @ CHECK: adds r1, r2, #3 @ encoding: [0xd1,0x1c] 40 @ CHECK: adds r2, #3 @ encoding: [0x03,0x32] 41 @ CHECK: adds r2, #8 @ encoding: [0x08,0x32] 42 43 44 @------------------------------------------------------------------------------ 45 @ ADD (register) 46 @------------------------------------------------------------------------------ 47 adds r1, r2, r3 48 add r2, r8 49 50 @ CHECK: adds r1, r2, r3 @ encoding: [0xd1,0x18] 51 @ CHECK: add r2, r8 @ encoding: [0x42,0x44] 52 53 54 @------------------------------------------------------------------------------ 55 @ ADD (SP plus immediate) 56 @------------------------------------------------------------------------------ 57 add sp, #4 58 add sp, #508 59 add sp, sp, #4 60 add r2, sp, #8 61 add r2, sp, #1020 62 add sp, sp, #-8 63 add sp, #-8 64 65 @ CHECK: add sp, #4 @ encoding: [0x01,0xb0] 66 @ CHECK: add sp, #508 @ encoding: [0x7f,0xb0] 67 @ CHECK: add sp, #4 @ encoding: [0x01,0xb0] 68 @ CHECK: add r2, sp, #8 @ encoding: [0x02,0xaa] 69 @ CHECK: add r2, sp, #1020 @ encoding: [0xff,0xaa] 70 @ CHECK: sub sp, #8 @ encoding: [0x82,0xb0] 71 @ CHECK: sub sp, #8 @ encoding: [0x82,0xb0] 72 73 74 @------------------------------------------------------------------------------ 75 @ ADD (SP plus register) 76 @------------------------------------------------------------------------------ 77 add sp, r3 78 add r2, sp, r2 79 80 @ CHECK: add sp, r3 @ encoding: [0x9d,0x44] 81 @ CHECK: add r2, sp, r2 @ encoding: [0x6a,0x44] 82 83 84 @------------------------------------------------------------------------------ 85 @ ADR 86 @------------------------------------------------------------------------------ 87 adr r2, _baz 88 adr r2, #3 89 90 @ CHECK: adr r2, _baz @ encoding: [A,0xa2] 91 @ fixup A - offset: 0, value: _baz, kind: fixup_thumb_adr_pcrel_10 92 @ CHECK: adr r2, #3 @ encoding: [0x03,0xa2] 93 94 @------------------------------------------------------------------------------ 95 @ ASR (immediate) 96 @------------------------------------------------------------------------------ 97 asrs r2, r3, #32 98 asrs r2, r3, #5 99 asrs r2, r3, #1 100 asrs r5, #21 101 asrs r5, r5, #21 102 asrs r3, r5, #21 103 104 @ CHECK: asrs r2, r3, #32 @ encoding: [0x1a,0x10] 105 @ CHECK: asrs r2, r3, #5 @ encoding: [0x5a,0x11] 106 @ CHECK: asrs r2, r3, #1 @ encoding: [0x5a,0x10] 107 @ CHECK: asrs r5, r5, #21 @ encoding: [0x6d,0x15] 108 @ CHECK: asrs r5, r5, #21 @ encoding: [0x6d,0x15] 109 @ CHECK: asrs r3, r5, #21 @ encoding: [0x6b,0x15] 110 111 112 @------------------------------------------------------------------------------ 113 @ ASR (register) 114 @------------------------------------------------------------------------------ 115 asrs r5, r2 116 117 @ CHECK: asrs r5, r2 @ encoding: [0x15,0x41] 118 119 120 @------------------------------------------------------------------------------ 121 @ B 122 @------------------------------------------------------------------------------ 123 b _baz 124 beq _bar 125 b #1838 126 b #-420 127 beq #336 128 beq #160 129 130 @ CHECK: b _baz @ encoding: [A,0xe0'A'] 131 @ fixup A - offset: 0, value: _baz, kind: fixup_arm_thumb_br 132 @ CHECK: beq _bar @ encoding: [A,0xd0] 133 @ fixup A - offset: 0, value: _bar, kind: fixup_arm_thumb_bcc 134 @ CHECK: b #1838 @ encoding: [0x97,0xe3] 135 @ CHECK: b #-420 @ encoding: [0x2e,0xe7] 136 @ CHECK: beq #336 @ encoding: [0xa8,0xd0] 137 @ CHECK: beq #160 @ encoding: [0x50,0xd0] 138 139 @------------------------------------------------------------------------------ 140 @ BL/BLX 141 @------------------------------------------------------------------------------ 142 blx #884800 143 blx #1769600 144 145 @ CHECK: blx #884800 @ encoding: [0xd8,0xf0,0x20,0xe8] 146 @ CHECK: blx #1769600 @ encoding: [0xb0,0xf1,0x40,0xe8] 147 148 @------------------------------------------------------------------------------ 149 @ BICS 150 @------------------------------------------------------------------------------ 151 bics r1, r6 152 153 @ CHECK: bics r1, r6 @ encoding: [0xb1,0x43] 154 155 156 @------------------------------------------------------------------------------ 157 @ BKPT 158 @------------------------------------------------------------------------------ 159 bkpt #0 160 bkpt #255 161 162 @ CHECK: bkpt #0 @ encoding: [0x00,0xbe] 163 @ CHECK: bkpt #255 @ encoding: [0xff,0xbe] 164 165 166 @------------------------------------------------------------------------------ 167 @ BL/BLX (immediate) 168 @------------------------------------------------------------------------------ 169 bl _bar 170 blx _baz 171 172 @ CHECK: bl _bar @ encoding: [A,0xf0'A',A,0xd0'A'] 173 @ fixup A - offset: 0, value: _bar, kind: fixup_arm_thumb_bl 174 @ CHECK: blx _baz @ encoding: [A,0xf0'A',A,0xc0'A'] 175 @ fixup A - offset: 0, value: _baz, kind: fixup_arm_thumb_blx 176 177 178 @------------------------------------------------------------------------------ 179 @ BLX (register) 180 @------------------------------------------------------------------------------ 181 blx r4 182 183 @ CHECK: blx r4 @ encoding: [0xa0,0x47] 184 185 186 @------------------------------------------------------------------------------ 187 @ BX 188 @------------------------------------------------------------------------------ 189 bx r2 190 191 @ CHECK: bx r2 @ encoding: [0x10,0x47] 192 193 194 @------------------------------------------------------------------------------ 195 @ CMN 196 @------------------------------------------------------------------------------ 197 198 cmn r5, r1 199 200 @ CHECK: cmn r5, r1 @ encoding: [0xcd,0x42] 201 202 203 @------------------------------------------------------------------------------ 204 @ CMP 205 @------------------------------------------------------------------------------ 206 cmp r6, #32 207 cmp r3, r4 208 cmp r8, r1 209 210 @ CHECK: cmp r6, #32 @ encoding: [0x20,0x2e] 211 @ CHECK: cmp r3, r4 @ encoding: [0xa3,0x42] 212 @ CHECK: cmp r8, r1 @ encoding: [0x88,0x45] 213 214 @------------------------------------------------------------------------------ 215 @ EOR 216 @------------------------------------------------------------------------------ 217 eors r4, r5 218 219 @ CHECK: eors r4, r5 @ encoding: [0x6c,0x40] 220 221 222 @------------------------------------------------------------------------------ 223 @ LDM 224 @------------------------------------------------------------------------------ 225 ldm r3, {r0, r1, r2, r3, r4, r5, r6, r7} 226 ldm r2!, {r1, r3, r4, r5, r7} 227 ldm r1, {r1} 228 229 @ CHECK: ldm r3, {r0, r1, r2, r3, r4, r5, r6, r7} @ encoding: [0xff,0xcb] 230 @ CHECK: ldm r2!, {r1, r3, r4, r5, r7} @ encoding: [0xba,0xca] 231 @ CHECK: ldm r1, {r1} @ encoding: [0x02,0xc9] 232 233 234 @------------------------------------------------------------------------------ 235 @ LDR (immediate) 236 @------------------------------------------------------------------------------ 237 ldr r1, [r5] 238 ldr r2, [r6, #32] 239 ldr r3, [r7, #124] 240 ldr r1, [sp] 241 ldr r2, [sp, #24] 242 ldr r3, [sp, #1020] 243 244 245 @ CHECK: ldr r1, [r5] @ encoding: [0x29,0x68] 246 @ CHECK: ldr r2, [r6, #32] @ encoding: [0x32,0x6a] 247 @ CHECK: ldr r3, [r7, #124] @ encoding: [0xfb,0x6f] 248 @ CHECK: ldr r1, [sp] @ encoding: [0x00,0x99] 249 @ CHECK: ldr r2, [sp, #24] @ encoding: [0x06,0x9a] 250 @ CHECK: ldr r3, [sp, #1020] @ encoding: [0xff,0x9b] 251 252 253 @------------------------------------------------------------------------------ 254 @ LDR (literal) 255 @------------------------------------------------------------------------------ 256 ldr r1, _foo 257 ldr r3, #604 258 ldr r3, #368 259 260 @ CHECK: ldr r1, _foo @ encoding: [A,0x49] 261 @ fixup A - offset: 0, value: _foo, kind: fixup_arm_thumb_cp 262 @ CHECK: ldr r3, [pc, #604] @ encoding: [0x97,0x4b] 263 @ CHECK: ldr r3, [pc, #368] @ encoding: [0x5c,0x4b] 264 265 @------------------------------------------------------------------------------ 266 @ LDR (register) 267 @------------------------------------------------------------------------------ 268 ldr r1, [r2, r3] 269 270 @ CHECK: ldr r1, [r2, r3] @ encoding: [0xd1,0x58] 271 272 273 @------------------------------------------------------------------------------ 274 @ LDRB (immediate) 275 @------------------------------------------------------------------------------ 276 ldrb r4, [r3] 277 ldrb r5, [r6, #0] 278 ldrb r6, [r7, #31] 279 280 @ CHECK: ldrb r4, [r3] @ encoding: [0x1c,0x78] 281 @ CHECK: ldrb r5, [r6] @ encoding: [0x35,0x78] 282 @ CHECK: ldrb r6, [r7, #31] @ encoding: [0xfe,0x7f] 283 284 285 @------------------------------------------------------------------------------ 286 @ LDRB (register) 287 @------------------------------------------------------------------------------ 288 ldrb r6, [r4, r5] 289 290 @ CHECK: ldrb r6, [r4, r5] @ encoding: [0x66,0x5d] 291 292 293 @------------------------------------------------------------------------------ 294 @ LDRH (immediate) 295 @------------------------------------------------------------------------------ 296 ldrh r3, [r3] 297 ldrh r4, [r6, #2] 298 ldrh r5, [r7, #62] 299 300 @ CHECK: ldrh r3, [r3] @ encoding: [0x1b,0x88] 301 @ CHECK: ldrh r4, [r6, #2] @ encoding: [0x74,0x88] 302 @ CHECK: ldrh r5, [r7, #62] @ encoding: [0xfd,0x8f] 303 304 305 @------------------------------------------------------------------------------ 306 @ LDRH (register) 307 @------------------------------------------------------------------------------ 308 ldrh r6, [r2, r6] 309 310 @ CHECK: ldrh r6, [r2, r6] @ encoding: [0x96,0x5b] 311 312 313 @------------------------------------------------------------------------------ 314 @ LDRSB/LDRSH 315 @------------------------------------------------------------------------------ 316 ldrsb r6, [r2, r6] 317 ldrsh r3, [r7, r1] 318 319 @ CHECK: ldrsb r6, [r2, r6] @ encoding: [0x96,0x57] 320 @ CHECK: ldrsh r3, [r7, r1] @ encoding: [0x7b,0x5e] 321 322 323 @------------------------------------------------------------------------------ 324 @ LSL (immediate) 325 @------------------------------------------------------------------------------ 326 lsls r4, r5, #0 327 lsls r4, r5, #4 328 lsls r3, #12 329 lsls r3, r3, #12 330 lsls r1, r3, #12 331 332 @ CHECK: lsls r4, r5, #0 @ encoding: [0x2c,0x00] 333 @ CHECK: lsls r4, r5, #4 @ encoding: [0x2c,0x01] 334 @ CHECK: lsls r3, r3, #12 @ encoding: [0x1b,0x03] 335 @ CHECK: lsls r3, r3, #12 @ encoding: [0x1b,0x03] 336 @ CHECK: lsls r1, r3, #12 @ encoding: [0x19,0x03] 337 338 339 @------------------------------------------------------------------------------ 340 @ LSL (register) 341 @------------------------------------------------------------------------------ 342 lsls r2, r6 343 344 @ CHECK: lsls r2, r6 @ encoding: [0xb2,0x40] 345 346 347 @------------------------------------------------------------------------------ 348 @ LSR (immediate) 349 @------------------------------------------------------------------------------ 350 lsrs r1, r3, #1 351 lsrs r1, r3, #32 352 lsrs r4, #20 353 lsrs r4, r4, #20 354 lsrs r2, r4, #20 355 356 @ CHECK: lsrs r1, r3, #1 @ encoding: [0x59,0x08] 357 @ CHECK: lsrs r1, r3, #32 @ encoding: [0x19,0x08] 358 @ CHECK: lsrs r4, r4, #20 @ encoding: [0x24,0x0d] 359 @ CHECK: lsrs r4, r4, #20 @ encoding: [0x24,0x0d] 360 @ CHECK: lsrs r2, r4, #20 @ encoding: [0x22,0x0d] 361 362 363 @------------------------------------------------------------------------------ 364 @ LSR (register) 365 @------------------------------------------------------------------------------ 366 lsrs r2, r6 367 368 @ CHECK: lsrs r2, r6 @ encoding: [0xf2,0x40] 369 370 371 @------------------------------------------------------------------------------ 372 @ MOV (immediate) 373 @------------------------------------------------------------------------------ 374 movs r2, #0 375 movs r2, #255 376 movs r2, #23 377 378 @ CHECK: movs r2, #0 @ encoding: [0x00,0x22] 379 @ CHECK: movs r2, #255 @ encoding: [0xff,0x22] 380 @ CHECK: movs r2, #23 @ encoding: [0x17,0x22] 381 382 383 @------------------------------------------------------------------------------ 384 @ MOV (register) 385 @------------------------------------------------------------------------------ 386 mov r3, r4 387 movs r1, r3 388 389 @ CHECK: mov r3, r4 @ encoding: [0x23,0x46] 390 @ CHECK: movs r1, r3 @ encoding: [0x19,0x00] 391 392 393 @------------------------------------------------------------------------------ 394 @ MUL 395 @------------------------------------------------------------------------------ 396 muls r1, r2, r1 397 muls r2, r2, r3 398 muls r3, r4 399 400 @ CHECK: muls r1, r2, r1 @ encoding: [0x51,0x43] 401 @ CHECK: muls r2, r3, r2 @ encoding: [0x5a,0x43] 402 @ CHECK: muls r3, r4, r3 @ encoding: [0x63,0x43] 403 404 405 @------------------------------------------------------------------------------ 406 @ MVN 407 @------------------------------------------------------------------------------ 408 mvns r6, r3 409 410 @ CHECK: mvns r6, r3 @ encoding: [0xde,0x43] 411 412 413 @------------------------------------------------------------------------------ 414 @ NEG 415 @------------------------------------------------------------------------------ 416 negs r3, r4 417 418 @ CHECK: rsbs r3, r4, #0 @ encoding: [0x63,0x42] 419 420 @------------------------------------------------------------------------------ 421 @ ORR 422 @------------------------------------------------------------------------------ 423 orrs r3, r4 424 425 @ CHECK-ERRORS: orrs r3, r4 @ encoding: [0x23,0x43] 426 427 428 @------------------------------------------------------------------------------ 429 @ POP 430 @------------------------------------------------------------------------------ 431 pop {r2, r3, r6} 432 433 @ CHECK: pop {r2, r3, r6} @ encoding: [0x4c,0xbc] 434 435 436 @------------------------------------------------------------------------------ 437 @ PUSH 438 @------------------------------------------------------------------------------ 439 push {r1, r2, r7} 440 441 @ CHECK: push {r1, r2, r7} @ encoding: [0x86,0xb4] 442 443 444 @------------------------------------------------------------------------------ 445 @ REV/REV16/REVSH 446 @------------------------------------------------------------------------------ 447 rev r6, r3 448 rev16 r7, r2 449 revsh r5, r1 450 451 @ CHECK: rev r6, r3 @ encoding: [0x1e,0xba] 452 @ CHECK: rev16 r7, r2 @ encoding: [0x57,0xba] 453 @ CHECK: revsh r5, r1 @ encoding: [0xcd,0xba] 454 455 456 @------------------------------------------------------------------------------ 457 @ ROR 458 @------------------------------------------------------------------------------ 459 rors r2, r7 460 461 @ CHECK: rors r2, r7 @ encoding: [0xfa,0x41] 462 463 464 @------------------------------------------------------------------------------ 465 @ RSB 466 @------------------------------------------------------------------------------ 467 rsbs r1, r3, #0 468 469 @ CHECK: rsbs r1, r3, #0 @ encoding: [0x59,0x42] 470 471 472 @------------------------------------------------------------------------------ 473 @ SBC 474 @------------------------------------------------------------------------------ 475 sbcs r4, r3 476 477 @ CHECK: sbcs r4, r3 @ encoding: [0x9c,0x41] 478 479 480 @------------------------------------------------------------------------------ 481 @ SETEND 482 @------------------------------------------------------------------------------ 483 setend be 484 setend le 485 486 @ CHECK: setend be @ encoding: [0x58,0xb6] 487 @ CHECK: setend le @ encoding: [0x50,0xb6] 488 489 490 @------------------------------------------------------------------------------ 491 @ STM 492 @------------------------------------------------------------------------------ 493 stm r1!, {r2, r6} 494 stm r1!, {r1, r2, r3, r7} 495 496 @ CHECK: stm r1!, {r2, r6} @ encoding: [0x44,0xc1] 497 @ CHECK: stm r1!, {r1, r2, r3, r7} @ encoding: [0x8e,0xc1] 498 499 500 @------------------------------------------------------------------------------ 501 @ STR (immediate) 502 @------------------------------------------------------------------------------ 503 str r2, [r7] 504 str r2, [r7, #0] 505 str r5, [r1, #4] 506 str r3, [r7, #124] 507 str r2, [sp] 508 str r3, [sp, #0] 509 str r4, [sp, #20] 510 str r5, [sp, #1020] 511 512 @ CHECK: str r2, [r7] @ encoding: [0x3a,0x60] 513 @ CHECK: str r2, [r7] @ encoding: [0x3a,0x60] 514 @ CHECK: str r5, [r1, #4] @ encoding: [0x4d,0x60] 515 @ CHECK: str r3, [r7, #124] @ encoding: [0xfb,0x67] 516 @ CHECK: str r2, [sp] @ encoding: [0x00,0x92] 517 @ CHECK: str r3, [sp] @ encoding: [0x00,0x93] 518 @ CHECK: str r4, [sp, #20] @ encoding: [0x05,0x94] 519 @ CHECK: str r5, [sp, #1020] @ encoding: [0xff,0x95] 520 521 522 @------------------------------------------------------------------------------ 523 @ STR (register) 524 @------------------------------------------------------------------------------ 525 str r2, [r7, r3] 526 527 @ CHECK: str r2, [r7, r3] @ encoding: [0xfa,0x50] 528 529 530 @------------------------------------------------------------------------------ 531 @ STRB (immediate) 532 @------------------------------------------------------------------------------ 533 strb r4, [r3] 534 strb r5, [r6, #0] 535 strb r6, [r7, #31] 536 537 @ CHECK: strb r4, [r3] @ encoding: [0x1c,0x70] 538 @ CHECK: strb r5, [r6] @ encoding: [0x35,0x70] 539 @ CHECK: strb r6, [r7, #31] @ encoding: [0xfe,0x77] 540 541 542 @------------------------------------------------------------------------------ 543 @ STRB (register) 544 @------------------------------------------------------------------------------ 545 strb r6, [r4, r5] 546 547 @ CHECK: strb r6, [r4, r5] @ encoding: [0x66,0x55] 548 549 550 @------------------------------------------------------------------------------ 551 @ STRH (immediate) 552 @------------------------------------------------------------------------------ 553 strh r3, [r3] 554 strh r4, [r6, #2] 555 strh r5, [r7, #62] 556 557 @ CHECK: strh r3, [r3] @ encoding: [0x1b,0x80] 558 @ CHECK: strh r4, [r6, #2] @ encoding: [0x74,0x80] 559 @ CHECK: strh r5, [r7, #62] @ encoding: [0xfd,0x87] 560 561 562 @------------------------------------------------------------------------------ 563 @ STRH (register) 564 @------------------------------------------------------------------------------ 565 strh r6, [r2, r6] 566 567 @ CHECK: strh r6, [r2, r6] @ encoding: [0x96,0x53] 568 569 570 @------------------------------------------------------------------------------ 571 @ SUB (immediate) 572 @------------------------------------------------------------------------------ 573 subs r1, r2, #3 574 subs r2, #3 575 subs r2, #8 576 577 @ CHECK: subs r1, r2, #3 @ encoding: [0xd1,0x1e] 578 @ CHECK: subs r2, #3 @ encoding: [0x03,0x3a] 579 @ CHECK: subs r2, #8 @ encoding: [0x08,0x3a] 580 581 582 @------------------------------------------------------------------------------ 583 @ SUB (SP minus immediate) 584 @------------------------------------------------------------------------------ 585 sub sp, #12 586 sub sp, sp, #508 587 588 @ CHECK: sub sp, #12 @ encoding: [0x83,0xb0] 589 @ CHECK: sub sp, #508 @ encoding: [0xff,0xb0] 590 591 592 @------------------------------------------------------------------------------ 593 @ SUB (register) 594 @------------------------------------------------------------------------------ 595 subs r1, r2, r3 596 597 @ CHECK: subs r1, r2, r3 @ encoding: [0xd1,0x1a] 598 599 600 @------------------------------------------------------------------------------ 601 @ SVC 602 @------------------------------------------------------------------------------ 603 svc #0 604 svc #255 605 606 @ CHECK: svc #0 @ encoding: [0x00,0xdf] 607 @ CHECK: svc #255 @ encoding: [0xff,0xdf] 608 609 610 @------------------------------------------------------------------------------ 611 @ SXTB/SXTH 612 @------------------------------------------------------------------------------ 613 sxtb r3, r5 614 sxth r3, r5 615 616 @ CHECK: sxtb r3, r5 @ encoding: [0x6b,0xb2] 617 @ CHECK: sxth r3, r5 @ encoding: [0x2b,0xb2] 618 619 620 @------------------------------------------------------------------------------ 621 @ TST 622 @------------------------------------------------------------------------------ 623 tst r6, r1 624 625 @ CHECK: tst r6, r1 @ encoding: [0x0e,0x42] 626 627 628 @------------------------------------------------------------------------------ 629 @ UXTB/UXTH 630 @------------------------------------------------------------------------------ 631 uxtb r7, r2 632 uxth r1, r4 633 634 @ CHECK: uxtb r7, r2 @ encoding: [0xd7,0xb2] 635 @ CHECK: uxth r1, r4 @ encoding: [0xa1,0xb2] 636 637 638