summaryrefslogtreecommitdiff
path: root/tests/webtbs/tw8195a.pp
blob: 7f37ffbf1477a34b042863aa855da8c682003448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{ %cpu=i386 }
{ %OPT=-Cg- }

{$APPTYPE CONSOLE}

{$ifdef fpc}
  {$mode delphi}
{$endif}

program AsmTest;

type
  TMyObject = class(TObject)
    Field1 : Integer;
    Field2 : Integer;
    procedure VirtualMethod1; virtual;
    procedure VirtualMethod2; virtual;
  end;

  TMyRecord = record
    EAX : Integer;
    EBX : Integer;
    ECX : Integer;
    EDX : Integer;
  end;

{ TMyObject }

procedure TMyObject.VirtualMethod1;
begin

end;

procedure TMyObject.VirtualMethod2;
begin

end;

function VirtualMethodVMTOFFSET1: Integer;
asm
  mov eax, VMTOFFSET TMyObject.VirtualMethod1;
end;

function VirtualMethodVMTOFFSET2: Integer;
asm
  mov eax, VMTOFFSET TMyObject.VirtualMethod2;
end;

function IUnknownAddRefVMTOFFSET1: Integer;
asm
  mov eax, VMTOFFSET IUnknown._AddRef;
end;

function Field1: Integer;
asm
  mov eax, TMyObject.Field1;
end;

function Field1OFFSET: Integer;
asm
  mov eax, OFFSET TMyObject.Field1;
end;

var
  _Test: Integer;

function Test: Integer;
asm
  mov eax, _Test;
end;

function TestOFFSET: Integer;
asm
  mov eax, OFFSET _Test;
end;

function LabelOFFSET: Integer;
asm
  mov eax, OFFSET @@Exit
 @@Exit:
end;

function TMyObjectTYPE: Integer;
asm
  mov eax, TYPE TMyObject
end;

function TMyRecordTYPE: Integer;
asm
  mov eax, TYPE TMyRecord
end;

function FillMyRecord: TMyRecord;
asm
  mov [eax + TMyRecord.&eax], eax
  mov [eax + TMyRecord.&ebx], ebx
  mov [eax + TMyRecord.&ecx], ecx
  mov [eax + TMyRecord.&edx], edx
end;

var
  MyRecord : TMyRecord;

begin
  _Test := 123;

  WriteLn('VirtualMethodVMTOFFSET1: ', VirtualMethodVMTOFFSET1);
  WriteLn('VirtualMethodVMTOFFSET2: ', VirtualMethodVMTOFFSET2);
  WriteLn('IUnknownAddRefVMTOFFSET1: ', IUnknownAddRefVMTOFFSET1);
  WriteLn('Field1: ', Field1);
  WriteLn('Field1OFFSET: ', Field1OFFSET);
  WriteLn('Test: ', Test);
  WriteLn('TestOFFSET: ', TestOFFSET);
  WriteLn('LabelOFFSET: ', LabelOFFSET);
  WriteLn('TMyObjectTYPE: ', TMyObjectTYPE);
  WriteLn('TMyRecordTYPE: ', TMyRecordTYPE);

  MyRecord.eax := 0;
  MyRecord.ebx := 0;
  MyRecord.ecx := 0;
  MyRecord.edx := 0;

  MyRecord := FillMyRecord;

  WriteLn('MyRecord.eax: ', MyRecord.eax);
  WriteLn('MyRecord.ebx: ', MyRecord.ebx);
  WriteLn('MyRecord.ecx: ', MyRecord.ecx);
  WriteLn('MyRecord.edx: ', MyRecord.edx);
end.