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