1 2#include <stdio.h> 3 4long long int arg = 0; 5long long int res = 0; 6 7extern void loop_plain ( void ); 8asm("\n" 9".text\n" 10".globl loop_plain\n" 11"loop_plain:\n" 12"\tpushq %rcx\n" 13"\tmovq $999, %rax\n" 14"\tmovq arg, %rcx\n" 15 16".Lmn123plain:\n" 17"\tdecq %rax\n" 18"\tdecq %rax\n" 19"\tdecq %rax\n" 20"\tloop .Lmn123plain\n" 21 22"\tmovq %rax, res\n" 23"\tpopq %rcx\n" 24"\tret\n" 25); 26 27extern void loop_ne ( void ); 28asm("\n" 29".text\n" 30".globl loop_ne\n" 31"loop_ne:\n" 32"\tpushq %rcx\n" 33"\tmovq $999, %rax\n" 34"\tmovq arg, %rcx\n" 35 36".Lmn123ne:\n" 37"\tdecq %rax\n" 38"\tdecq %rax\n" 39"\tdecq %rax\n" 40"\tloopne .Lmn123ne\n" 41 42"\tmovq %rax, res\n" 43"\tpopq %rcx\n" 44"\tret\n" 45); 46 47extern void loop_e ( void ); 48asm("\n" 49".text\n" 50".globl loop_e\n" 51"loop_e:\n" 52"\tpushq %rcx\n" 53"\tmovq $999, %rax\n" 54"\tmovq arg, %rcx\n" 55 56".Lmn123e:\n" 57"\tdecq %rax\n" 58"\tdecq %rax\n" 59"\tdecq %rax\n" 60/* invert the Z flag */ 61"\tpushfq\n" 62"\txorq $64, 0(%rsp)\n" 63"\tpopfq\n" 64"\tloope .Lmn123e\n" 65 66"\tmovq %rax, res\n" 67"\tpopq %rcx\n" 68"\tret\n" 69); 70 71int main ( void ) 72{ 73 res = 0; arg = 10; loop_plain(); printf("res = %lld\n", res); 74 75 res = 0; arg = 10; loop_ne(); printf("res = %lld\n", res); 76 res = 0; arg = 500; loop_ne(); printf("res = %lld\n", res); 77 78 res = 0; arg = 10; loop_e(); printf("res = %lld\n", res); 79 res = 0; arg = 500; loop_e(); printf("res = %lld\n", res); 80 81 return 0; 82} 83