1 /* This tests the somewhat obscure 32-bit Intel aam and aad instructions */
2 /* by Vince Weaver (vince _at_ deater.net ) */
11 for (i
= 0; i
< 8; i
++)
16 int main(int argc
, char **argv
) {
18 printf("test begins\n");
21 int cf
__attribute__((unused
)),pf
,af
__attribute__((unused
)),zf
,sf
;
22 int of
__attribute__((unused
));
26 for(i
=0;i
<65535;i
++) {
27 // printf("%d, %d, %d\n",i,(i&0xff)/10,(i&0xff)%10);
29 __asm__
__volatile__ ("mov %2 ,%%ax\n"
35 :"=r"(out
), "=r"(flags
) /* outputs */
37 :"%eax" /* clobbered */
46 // printf("%d, %d, %d, ",i,(out>>8)&0xff,out&0xff);
47 // printf("%x CF=%d PF=%d AF=%d ZF=%d SF=%d OF=%d\n",
48 // flags,cf,pf,af,zf,sf,of);
50 if (zf
&& ((out
&0xff)!=0)) {
51 printf("Error with aam (zf)!\n");
53 if (pf
!= parity(out
&0xff)) {
54 printf("Error with aam (pf)!\n");
56 if (sf
!= !!(out
&0x80)) {
57 printf("Error with aam (sf)!\n");
61 if ( ((out
>>8)&0xff) != ((i
&0xff)/10)) {
62 printf("Error with aam!\n");
64 if ( (out
&0xff) != ((i
&0xff)%10)) {
65 printf("Error with aam!\n");
72 for(i
=0;i
<65535;i
++) {
73 // printf("%x, %d\n",i, ((((i>>8)&0xff)*10)+(i&0xff))&0xff );
75 __asm__
__volatile__ ("mov %2 ,%%ax\n"
81 :"=r"(out
), "=r"(flags
) /* outputs */
83 :"%eax" /* clobbered */
93 // printf("%x, %d ",i,out);
94 // printf("%x CF=%d PF=%d AF=%d ZF=%d SF=%d OF=%d\n",
95 // flags,cf,pf,af,zf,sf,of);
97 if (zf
&& ((out
&0xff)!=0)) {
98 printf("Error with aad (zf)!\n");
100 if (pf
!= parity(out
&0xff)) {
101 printf("Error with aad (pf)!\n");
103 if (sf
!= !!(out
&0x80)) {
104 printf("Error with aad (sf) %d %d!\n",sf
,!!(out
&0x80));
107 if ( out
!= ( ((((i
>>8)&0xff)*10)+(i
&0xff))&0xff) ) {
108 printf("Error with aad!\n");
112 printf("test completed\n");