1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdio.h>
6
7 #include "assembler.h"
8
main(int argc,char ** argv)9 int main(int argc, char** argv) {
10 char buf[1024];
11
12 CodeBuffer cb(buf);
13
14 // Branching tests first so the offsets are not always adjusting in the
15 // output diassembler when we add new tests.
16
17 cb.spin();
18
19 cb.call(EAX);
20 cb.call(Operand(EAX));
21 cb.call(Operand(EDX, 15));
22
23 cb.fs(); cb.mov(EAX, Operand(3));
24 cb.fs(); cb.mov(EDX, Operand(0x04));
25
26 cb.lea(EAX, Operand(EAX));
27 cb.lea(EAX, Operand(0x12345678));
28 cb.lea(EAX, Operand(EBX, 0x12345678));
29 cb.lea(EAX, Operand(EBX, ECX, SCALE_TIMES_2, 0x12345678));
30 cb.lea(EAX, Operand(ECX, SCALE_TIMES_2, 0x12345678));
31 cb.lea(EAX, Operand(EAX, SCALE_TIMES_2, 0));
32 cb.lea(EAX, Operand(EBX, SCALE_TIMES_2, 0));
33 cb.lea(EBP, Operand(EBP, SCALE_TIMES_2, 1));
34
35 cb.lodsb();
36 cb.lodsd();
37
38 cb.mov(EAX, ECX);
39 cb.mov(ESI, ESP);
40 cb.mov(EAX, Operand(ESP, 0x20));
41 cb.mov(EAX, Operand(EBP, 8));
42 cb.mov_imm(ESP, 1);
43 cb.mov_imm(EAX, 0x12345678);
44
45 cb.pop(EBX);
46 cb.pop(Operand(EBX));
47 cb.pop(Operand(EBX, 0));
48 cb.pop(Operand(EBX, 12));
49
50 cb.push(EBX);
51 cb.push(Operand(EBX));
52 cb.push(Operand(EBX, 0));
53 cb.push(Operand(EDI, -4));
54 cb.push(Operand(EDI, -8));
55 cb.push_imm(0x12);
56 cb.push_imm(0x1234);
57 cb.push(Operand(EBX, 12));
58 cb.push(Operand(ESP, 0x1234));
59
60 cb.ret();
61 cb.ret(0);
62 cb.ret(12);
63
64 cb.stosb();
65 cb.stosd();
66
67 cb.sysenter();
68
69 cb.which_cpu();
70 cb.which_thread();
71
72 cb.xchg(EAX, EAX);
73 cb.xchg(EBX, EAX);
74 cb.xchg(EAX, EBX);
75 cb.xchg(ECX, ESP);
76 cb.xchg(ECX, Operand(ESP));
77 cb.xchg(ECX, Operand(ESP, 5));
78 cb.xchg(ECX, Operand(EDX, 4));
79
80 fwrite(buf, 1, cb.size(), stdout);
81
82 return 0;
83 }
84