sewardj | 09ea9c4 | 2005-08-12 23:40:55 +0000 | [diff] [blame] | 1 | |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | typedef unsigned long long int ULong; |
| 5 | typedef unsigned int UInt; |
| 6 | |
| 7 | ULong m64; |
| 8 | |
| 9 | UInt eax; |
| 10 | UInt ebx; |
| 11 | UInt ecx; |
| 12 | UInt edx; |
| 13 | UInt zout; |
| 14 | |
| 15 | extern void foo ( void ); |
| 16 | asm("\n" |
| 17 | "foo:\n" |
| 18 | "\tpushl %eax\n" |
| 19 | "\tpushl %ebx\n" |
| 20 | "\tpushl %ecx\n" |
| 21 | "\tpushl %edx\n" |
| 22 | |
| 23 | "\txorl %eax, %eax\n" // get eflags in a known state |
| 24 | |
| 25 | "\tmovl eax,%eax\n" |
| 26 | "\tmovl ebx,%ebx\n" |
| 27 | "\tmovl ecx,%ecx\n" |
| 28 | "\tmovl edx,%edx\n" |
| 29 | "\tcmpxchg8b m64\n" |
| 30 | "\tmovl %eax,eax\n" |
| 31 | "\tmovl %ebx,ebx\n" |
| 32 | "\tmovl %ecx,ecx\n" |
| 33 | "\tmovl %edx,edx\n" |
| 34 | "\tpushfl\n" |
| 35 | "\tpopl %eax\n" |
| 36 | "\tmovl %eax,zout\n" |
| 37 | |
| 38 | "\tpopl %edx\n" |
| 39 | "\tpopl %ecx\n" |
tom | 22b8748 | 2005-08-26 09:57:17 +0000 | [diff] [blame^] | 40 | "\tpopl %ebx\n" |
sewardj | 09ea9c4 | 2005-08-12 23:40:55 +0000 | [diff] [blame] | 41 | "\tpopl %eax\n" |
| 42 | "\tret\n" |
| 43 | ); |
| 44 | |
| 45 | int main ( void ) |
| 46 | { |
| 47 | edx = 0x11111111; eax = 0x22222222; |
| 48 | ecx = 0x33333333; ebx = 0x44444444; |
| 49 | zout = 0x55555555; |
| 50 | m64 = 0x1111111122222222ULL; |
| 51 | foo(); |
| 52 | printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n", |
| 53 | eax, ebx, ecx, edx, zout & 0xFFFF, m64 ); |
| 54 | |
| 55 | edx = 0x11111111; eax = 0x22222222; |
| 56 | ecx = 0x33333333; ebx = 0x44444444; |
| 57 | zout = 0x55555555; |
| 58 | m64 = 0x1111111122222222ULL; |
| 59 | m64 += 0x1ULL; |
| 60 | foo(); |
| 61 | printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n", |
| 62 | eax, ebx, ecx, edx, zout & 0xFFFF, m64 ); |
| 63 | |
| 64 | edx = 0x11111111; eax = 0x22222222; |
| 65 | ecx = 0x33333333; ebx = 0x44444444; |
| 66 | zout = 0x55555555; |
| 67 | m64 = 0x1111111122222222ULL; |
| 68 | m64 += 0x100000000ULL; |
| 69 | foo(); |
| 70 | printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n", |
| 71 | eax, ebx, ecx, edx, zout & 0xFFFF, m64 ); |
| 72 | |
| 73 | edx = 0x11111111; eax = 0x22222222; |
| 74 | ecx = 0x33333333; ebx = 0x44444444; |
| 75 | zout = 0x55555555; |
| 76 | m64 = 0x6666666677777777ULL; |
| 77 | foo(); |
| 78 | printf("0x%x 0x%x 0x%x 0x%x 0x%x 0x%llx\n", |
| 79 | eax, ebx, ecx, edx, zout & 0xFFFF, m64 ); |
| 80 | |
| 81 | return 0; |
| 82 | } |