1
2#include <stdio.h>
3
4typedef unsigned long long int ULong;
5typedef unsigned           int UInt;
6
7ULong arg64, res64;
8
9extern void foo64 ( void );
10asm("\n"
11"foo64:\n"
12"\tpushq %rcx\n"
13
14"\tmovq $0, %rax\n"
15"\tmovq arg64, %rcx\n"
16
17"Lagain64:\n"
18"\taddq $177, %rax\n"
19"\tdecq %rcx\n"
20"\tjrcxz Lout64\n"
21"\tjmp Lagain64\n"
22
23"Lout64:\n"
24"\tmovq %rax, res64\n"
25
26"\tpopq %rcx\n"
27"\tret\n"
28);
29
30
31UInt arg32, res32;
32
33extern void foo32 ( void );
34asm("\n"
35"foo32:\n"
36"\tpushq %rcx\n"
37
38"\tmovq $0, %rax\n"
39"\tmovl arg32, %ecx\n"
40
41"Lagain32:\n"
42"\taddq $177, %rax\n"
43"\tdecl %ecx\n"
44"\tjecxz Lout32\n"
45"\tjmp Lagain32\n"
46
47"Lout32:\n"
48"\tmovl %eax, res32\n"
49
50"\tpopq %rcx\n"
51"\tret\n"
52);
53
54
55
56int main ( void )
57{
58  arg64 = 100;
59  res64 = 0;
60  foo64();
61  printf("%lld\n", res64);
62
63  arg32 = 1234;
64  res32 = 0;
65  foo32();
66  printf("%d\n", res32);
67
68  return 0;
69}
70