tccasm: allow one-line prefix+op things like "rep stosb"
[tinycc.git] / tests / asmtest.S
blob452815ccac1d689ffb2835131a3735355598de2a
2 /* some directive tests */
4    .byte 0xff
5    .byte 1, 2, 3
6    .short 1, 2, 3
7    .word 1, 2, 3
8    .long 1, 2, 3
9    .int 1, 2, 3
10    .align 8
11    .byte 1
12 /* .align 16, 0x90 gas is too clever for us with 0x90 fill */
13    .align 16, 0x91 /* 0x91 tests the non-clever behaviour */
14    .skip 3
15    .skip 15, 0x90
16    .string "hello\0world"
18 /* some label tests */
20         movl %eax, %ebx
21 L1:
22         movl %eax, %ebx
23         mov 0x10000, %eax
24 L2:
25         movl $L2 - L1, %ecx
26 var1:
27         nop ; nop ; nop ; nop
29         mov var1, %eax
31 /* instruction tests */
32 movl %eax, %ebx
33 mov 0x10000, %eax
34 mov 0x10000, %ax
35 mov 0x10000, %al
36 mov %al, 0x10000
37                 
38 mov $1, %edx
39 mov $1, %dx
40 mov $1, %dl
41 movb $2, 0x100(%ebx,%edx,2)
42 movw $2, 0x100(%ebx,%edx,2)
43 movl $2, 0x100(%ebx,%edx,2)
44 movl %eax, 0x100(%ebx,%edx,2)
45 movl 0x100(%ebx,%edx,2), %edx
46 movw %ax, 0x100(%ebx,%edx,2)
48 mov %eax, 0x12(,%edx,2)
49         
50 mov %cr3, %edx
51 mov %ecx, %cr3
52 movl %cr3, %eax
53 movl %tr3, %eax
54 movl %db3, %ebx
55 movl %dr6, %eax
56 movl %fs, %ecx
57 movl %ebx, %fs
59      movsbl 0x1000, %eax
60      movsbw 0x1000, %ax
61      movswl 0x1000, %eax
63      movzbl 0x1000, %eax
64      movzbw 0x1000, %ax
65      movzwl 0x1000, %eax
66             
67      movzb 0x1000, %eax
68      movzb 0x1000, %ax
69                 
70         
71   pushl %eax
72   pushw %ax
73   push %eax
74   push %cs
75   push %gs
76   push $1
77   push $100
78                                                 
79   popl %eax
80   popw %ax
81   pop %eax
82   pop %ds
83   pop %fs
84           
85   xchg %eax, %ecx
86   xchg %edx, %eax
87   xchg %bx, 0x10000
88   xchg 0x10000, %ebx
89   xchg 0x10000, %dl
91   in $100, %al               
92   in $100, %ax               
93   in $100, %eax
94   in %dx, %al
95   in %dx, %ax               
96   in %dx, %eax
97   inb %dx
98   inw %dx               
99   inl %dx
101   out %al, $100                       
102   out %ax, $100                       
103   out %eax, $100                       
105   /* NOTE: gas is bugged here, so size must be added */
106   outb %al, %dx                       
107   outw %ax, %dx                       
108   outl %eax, %dx                       
110   leal 0x1000(%ebx), %ecx
111   lea 0x1000(%ebx), %ecx
113   les 0x2000, %eax
114   lds 0x2000, %ebx
115   lfs 0x2000, %ecx
116   lgs 0x2000, %edx
117   lss 0x2000, %edx
119 addl $0x123, %eax
120 add $0x123, %ebx
121 addl $0x123, 0x100
122 addl $0x123, 0x100(%ebx)
123 addl $0x123, 0x100(%ebx,%edx,2)
124 addl $0x123, 0x100(%esp)
125 addl $0x123, (%ebp)
126 addl $0x123, (%esp)
127 cmpl $0x123, (%esp)
129 add %eax, (%ebx)
130 add (%ebx), %eax
131                 
132 or %dx, (%ebx)
133 or (%ebx), %si
134         
135 add %cl, (%ebx)
136 add (%ebx), %dl
138     inc %edx
139     incl 0x10000
140     incb 0x10000
141     dec %dx
142   
143   test $1, %al
144   test $1, %cl
146   testl $1, 0x1000
147   testb $1, 0x1000
148   testw $1, 0x1000
149   test %eax, %ebx
150   test %eax, 0x1000
151   test 0x1000, %edx
153     not %edx
154     notw 0x10000
155     notl 0x10000
156     notb 0x10000
158     neg %edx
159     negw 0x10000
160     negl 0x10000
161     negb 0x10000
163     imul %ecx
164     mul %edx
165     mulb %cl
167     imul %eax, %ecx
168     imul 0x1000, %cx
169     imul $10, %eax, %ecx
170     imul $10, %ax, %cx
171     imul $10, %eax
172     imul $0x1100000, %eax
173     imul $1, %eax
174     
175     idivw 0x1000
176     div %ecx
177     div %bl
178     div %ecx, %eax
181 shl %edx
182 shl $10, %edx
183 shl %cl, %edx
185 shld $1, %eax, %edx
186 shld %cl, %eax, %edx
187 shld %eax, %edx
189 shrd $1, %eax, %edx
190 shrd %cl, %eax, %edx
191 shrd %eax, %edx
194 call 0x1000
195 call L4
196 call *%eax
197 call *0x1000
198 call func1
200 .global L5,L6
205 lcall $0x100, $0x1000
207 jmp 0x1000
208 jmp *%eax
209 jmp *0x1000
211 ljmp $0x100, $0x1000
214 retl
216 ret $10
217 retl $10
219 lret
221 lret $10
223 enter $1234, $10
226  jo 0x1000
227  jnp 0x1001
228  jne 0x1002
229  jg 0x1003
231  jo L3
232  jnp L3
233  jne L3
234  jg L3
236  loopne L3
237  loopnz L3
238  loope L3
239  loopz L3
240  loop L3
241  jecxz L3
243         
244  seto %al
245  setnp 0x1000
246  setl 0xaaaa
247  setg %dl
249  fadd
250  fadd %st(1), %st
251  fadd %st(3)
253  faddp %st(5)
254  faddp
255  faddp %st(1), %st
257  fadds 0x1000
258  fiadds 0x1002
259  faddl 0x1004
260  fiaddl 0x1006
262  fmul
263  fmul %st(1), %st
264  fmul %st(3)
266  fmulp %st(5)
267  fmulp
268  fmulp %st(1), %st
270  fmuls 0x1000
271  fimuls 0x1002
272  fmull 0x1004
273  fimull 0x1006
275  fsub
276  fsub %st(1), %st
277  fsub %st(3)
279  fsubp %st(5)
280  fsubp
281  fsubp %st(1), %st
283  fsubs 0x1000
284  fisubs 0x1002
285  fsubl 0x1004
286  fisubl 0x1006
288  fsubr
289  fsubr %st(1), %st
290  fsubr %st(3)
292  fsubrp %st(5)
293  fsubrp
294  fsubrp %st(1), %st
296  fsubrs 0x1000
297  fisubrs 0x1002
298  fsubrl 0x1004
299  fisubrl 0x1006
301  fdiv
302  fdiv %st(1), %st
303  fdiv %st(3)
305  fdivp %st(5)
306  fdivp
307  fdivp %st(1), %st
309  fdivs 0x1000
310  fidivs 0x1002
311  fdivl 0x1004
312  fidivl 0x1006
314  fcom %st(3)
316  fcoms 0x1000
317  ficoms 0x1002
318  fcoml 0x1004
319  ficoml 0x1006
321  fcomp %st(5)
322  fcomp
323  fcompp
325  fcomps 0x1000
326  ficomps 0x1002
327  fcompl 0x1004
328  ficompl 0x1006
330  fld %st(5)
331  fldl 0x1000
332  flds 0x1002
333  fildl 0x1004
334  fst %st(4)
335  fstp %st(6)
336  fstpt 0x1006
337  fbstp 0x1008
339  fxch
340  fxch %st(4)
342  fucom %st(6)
343  fucomp %st(3)
344  fucompp
346  finit
347  fninit
348  fldcw 0x1000
349  fnstcw 0x1002
350  fstcw 0x1002
351  fnstsw 0x1004
352  fnstsw (%eax)
353  fstsw 0x1004
354  fstsw (%eax)
355  fnclex
356  fclex
357  fnstenv 0x1000
358  fstenv 0x1000
359  fldenv 0x1000
360  fnsave 0x1002
361  fsave 0x1000
362  frstor 0x1000
363  ffree %st(7)
364  ffreep %st(6)
366     ftst
367     fxam
368     fld1
369     fldl2t
370     fldl2e
371     fldpi
372     fldlg2
373     fldln2
374     fldz
376     f2xm1
377     fyl2x
378     fptan
379     fpatan
380     fxtract
381     fprem1
382     fdecstp
383     fincstp
384     fprem
385     fyl2xp1
386     fsqrt
387     fsincos
388     frndint
389     fscale
390     fsin
391     fcos
392     fchs
393     fabs
394     fnop
395     fwait
397 bswap %edx
398 xadd %ecx, %edx
399 xaddb %dl, 0x1000
400 xaddw %ax, 0x1000
401 xaddl %eax, 0x1000
402 cmpxchg %ecx, %edx
403 cmpxchgb %dl, 0x1000
404 cmpxchgw %ax, 0x1000
405 cmpxchgl %eax, 0x1000
406 invlpg 0x1000
407 cmpxchg8b 0x1002
409 fcmovb %st(5), %st
410 fcmove %st(5), %st
411 fcmovbe %st(5), %st
412 fcmovu %st(5), %st
413 fcmovnb %st(5), %st
414 fcmovne %st(5), %st
415 fcmovnbe %st(5), %st
416 fcmovnu %st(5), %st
417 fcomi %st(5), %st
418 fucomi %st(5), %st
419 fcomip %st(5), %st
420 fucomip %st(5), %st
424  cmovo 0x1000, %eax
425  cmovs 0x1000, %eax
426  cmovns %edx, %edi
428 int $3
429 int $0x10
431     pusha
432     popa
433     clc
434     cld
435     cli
436     clts
437     cmc
438     lahf
439     sahf
440     pushfl
441     popfl
442     pushf
443     popf
444     stc
445     std
446     sti
447     aaa
448     aas
449     daa
450     das
451     aad
452     aam
453     cbw
454     cwd
455     cwde
456     cdq
457     cbtw
458     cwtd
459     cwtl
460     cltd
461     leave
462     int3
463     into
464     iret
465     rsm
466     hlt
467     wait
468     nop
470     /* XXX: handle prefixes */
471 #if 0
472     aword
473     addr16
474 #endif
475     lock
476     rep
477     repe
478     repz
479     repne
480     repnz
481     nop
483     lock ;negl (%eax)
484     wait ;pushf
485     rep  ;stosb
486     repe ;lodsb
487     repz ;cmpsb
488     repne;movsb
489     repnz;outsb
491     /* handle one-line prefix + ops */
492     lock  negl (%eax)
493     wait  pushf
494     rep   stosb
495     repe  lodsb
496     repz  cmpsb
497     repne movsb
498     repnz outsb
499     
500     invd
501     wbinvd
502     cpuid
503     wrmsr
504     rdtsc
505     rdmsr
506     rdpmc
507     ud2
509     emms
510     movd %edx, %mm3
511     movd 0x1000, %mm2
512     movd %mm4, %ecx
513     movd %mm5, 0x1000
514                     
515     movq 0x1000, %mm2
516     movq %mm4, 0x1000
517     
518     pand 0x1000, %mm3
519     pand %mm4, %mm5
520     
521     psllw $1, %mm6
522     psllw 0x1000, %mm7
523     psllw %mm2, %mm7
525     xlat
526     cmpsb
527     scmpw
528     insl
529     outsw
530     lodsb
531     slodl
532     movsb
533     movsl
534     smovb
535     scasb
536     sscaw
537     stosw
538     sstol
540     bsf 0x1000, %ebx
541     bsr 0x1000, %ebx
542     bt %edx, 0x1000
543     btl $2, 0x1000
544     btc %edx, 0x1000
545     btcl $2, 0x1000
546     btr %edx, 0x1000
547     btrl $2, 0x1000
548     bts %edx, 0x1000
549     btsl $2, 0x1000
551         
552         
553     boundl %edx, 0x10000
554     boundw %bx, 0x1000
555     
556     arpl %bx, 0x1000
557     lar 0x1000, %eax
558     lgdt 0x1000
559     lidt 0x1000
560     lldt 0x1000
561     lmsw 0x1000
562     lsl 0x1000, %ecx
563     ltr 0x1000
564     
565     sgdt 0x1000
566     sidt 0x1000
567     sldt 0x1000
568     smsw 0x1000
569     str 0x1000
570     
571     verr 0x1000
572     verw 0x1000
573   
574     push %ds
575     pushw %ds
576     pushl %ds
577     pop %ds
578     popw %ds
579     popl %ds
580     fxsave 1(%ebx)
581     fxrstor 1(%ecx)
582     pushl $1
583     pushw $1
584     push $1
586 #ifdef __ASSEMBLER__ // should be defined, for S files
587     inc %eax
588 #endif