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