Crutches for TCC inline Asm. The beginning of the story is here: http://lists.nongnu.org/archive/html/tinycc-devel/2017-07/msg00031.html http://lists.nongnu.org/archive/html/tinycc-devel/2017-07/msg00032.html
As I see, there are no good teaches among tinycc-devel. So, let's go on. Next program compiling well, but linking bad. #include <stdio.h> int main() { unsigned int a = 0; b: asm ( "cpuid" ); asm ( "rdtsc" ); asm ( "mov %eax, a" ); printf("%d\n", a); goto b; } :00000040 55 push ebp :00000041 89E5 mov ebp, esp :00000043 81EC04000000 sub esp, 00000004 :00000049 90 nop :0000004A B800000000 mov eax, 00000000 :0000004F 8945FC mov dword ptr [ebp-04], eax :00000052 0FA2 cpuid :00000054 0F31 rdtsc mistake :00000056 A300000000 mov dword ptr [00000000], eax :0000005B 8B45FC mov eax, dword ptr [ebp-04] :0000005E 50 push eax :0000005F B800000000 mov eax, 00000000 :00000064 50 push eax :00000065 E8FCFFFFFF call 00000066 :0000006A 83C408 add esp, 00000008 :0000006D EBE3 jmp 00000052 :0000006F C9 leave :00000070 C3 ret The next program compiling well, linking well, but brings bad results. #include <stdio.h> unsigned int a = 0; int main() { unsigned int a; b: asm ( "cpuid" ); asm ( "rdtsc" ); asm ( "mov %eax, a" ); printf("%d\n", a); goto b; } And now... THE CRUTCHES!!! A good pattern, for all beginners, who does not want to drown in such nonsense: int src = 1; int dst; asm ("mov %1, %0\n\t" "add $1, %0" : "=r" (dst) : "r" (src)); printf("%d\n", dst); ENJOY! #include <stdio.h> unsigned int temp0; int main() { unsigned int a; b: a = 0; temp0 = a; asm ( "cpuid" ); asm ( "rdtsc" ); asm ( "mov %eax, temp0" ); a = temp0; printf("%d\n", a); goto b; } As you see, TCC inline Assembler not see local variables. And it's not evil tongues from https://sites.google.com/site/excelmidi/universal_student_ide/universal_student_ide_en . A big piece of work has been done. But who really need this heap of trash: #include <stdio.h> int main() { int src = 1; int dst = 0; asm ("mov %1, %0\n\t" "add $1, %0" : "=r" (dst) : "r" (src)); printf("%d\n", dst); } :00000040 55 push ebp :00000041 89E5 mov ebp, esp :00000043 81EC08000000 sub esp, 00000008 :00000049 90 nop :0000004A B801000000 mov eax, 00000001 :0000004F 8945FC mov dword ptr [ebp-04], eax :00000052 B800000000 mov eax, 00000000 :00000057 8945F8 mov dword ptr [ebp-08], eax :0000005A 8B45FC mov eax, dword ptr [ebp-04] :0000005D 89C0 mov eax, eax :0000005F 0501000000 add eax, 00000001 :00000064 8945F8 mov dword ptr [ebp-08], eax :00000067 8B45F8 mov eax, dword ptr [ebp-08] :0000006A 50 push eax :0000006B B800000000 mov eax, 00000000 :00000070 50 push eax :00000071 E8FCFFFFFF call 00000072 :00000076 83C408 add esp, 00000008 :00000079 C9 leave :0000007A C3 ret Of couse, Fabrice will never patch TCC. Because of because. It is life. Welcome https://sites.google.com/site/excelmidi . Check your CPU. New funny bug all x86. Forget about optimization: https://sites.google.com/site/excelmidi/stupid-bug-x86-cpu-tupoj-bag-processora-h86 :)! _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel