comparison run/mini/asm7.d @ 1628:c6ef09dfba4d

add mini test set from ldc project
author Moritz Warning <moritzwarning@web.de>
date Mon, 10 Jan 2011 19:47:18 +0100
parents
children
comparison
equal deleted inserted replaced
1627:e1b954780837 1628:c6ef09dfba4d
1 module tangotests.asm7;
2
3 // test massive label collisions (runtime uses Loverflow too)
4 extern(C) int printf(char*, ...);
5
6 void main()
7 {
8 int a = add(1,2);
9 int s = sub(1,2);
10 assert(a == 3);
11 assert(s == -1);
12 }
13
14 int add(int a, int b)
15 {
16 int res;
17 version (D_InlineAsm_X86)
18 {
19 asm
20 {
21 mov EAX, a;
22 add EAX, b;
23 jo Loverflow;
24 mov res, EAX;
25 }
26 }
27 else version (D_InlineAsm_X86_64)
28 {
29 asm
30 {
31 mov EAX, a;
32 add EAX, b;
33 jo Loverflow;
34 mov res, EAX;
35 }
36 }
37 printf("%d\n",res);
38 return res;
39 Loverflow:
40 assert(0, "add overflow");
41 }
42
43 int sub(int a, int b)
44 {
45 int res;
46 version (D_InlineAsm_X86)
47 {
48 asm
49 {
50 mov EAX, a;
51 sub EAX, b;
52 jo Loverflow;
53 mov res, EAX;
54 }
55 }
56 else version (D_InlineAsm_X86_64)
57 {
58 asm
59 {
60 mov EAX, a;
61 sub EAX, b;
62 jo Loverflow;
63 mov res, EAX;
64 }
65 }
66 printf("%d\n",res);
67 return res;
68 Loverflow:
69 assert(0, "sub overflow");
70 int x;
71 }