comparison run/mini/naked_asm5.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 d0efa3ae5522
comparison
equal deleted inserted replaced
1627:e1b954780837 1628:c6ef09dfba4d
1 int foo(int op)(int a, int b)
2 {
3 version(X86)
4 {
5 const OP = (op == '+') ? "add" : "sub";
6 version (Windows)
7 {
8 asm { naked; }
9 mixin("asm{push EBP;mov EBP,ESP;sub ESP,8;mov ECX,[EBP+8];"~OP~" EAX, ECX;add ESP,8;pop EBP;}");
10 asm { ret; }
11 } else
12 {
13 asm { naked; }
14 mixin("asm{"~OP~" EAX, [ESP+4];}");
15 asm { ret 4; }
16 }
17 }
18 else version(X86_64)
19 {
20 const OP = (op == '+') ? "add" : "sub";
21 asm { naked; }
22 mixin("asm{"~OP~" ESI,EDI; mov EAX, ESI;}");
23 asm { ret; }
24 }
25 else static assert(0, "todo");
26 }
27
28 void main()
29 {
30 int i = foo!('+')(2, 4);
31 assert(i == 6);
32 i = foo!('-')(2, 4);
33 assert(i == 2);
34 }