【发布时间】:2011-06-24 11:25:32
【问题描述】:
我在使用 Delphi 的内联汇编时遇到了一些奇怪的行为,正如这个非常简短的程序所示:
program test;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TAsdf = class
public
int: Integer;
end;
TBlah = class
public
asdf: TAsdf;
constructor Create(a: TAsdf);
procedure Test;
end;
constructor TBlah.Create(a: TAsdf);
begin
asdf := a;
end;
procedure TBlah.Test;
begin
asm
mov eax, [asdf]
end;
end;
var
asdf: TAsdf;
blah: TBlah;
begin
asdf := TAsdf.Create;
blah := TBlah.Create(asdf);
blah.Test;
readln;
end.
这只是为了举例(moving [asdf] 到 eax 并没有多大作用,但它适用于示例)。如果您查看该程序的程序集,您会发现
mov eax, [asdf]
变成了
mov eax, ds:[4]
(由 OllyDbg 表示)显然会崩溃。但是,如果您这样做:
var
temp: TAsdf;
begin
temp := asdf;
asm
int 3;
mov eax, [temp];
end;
它变为 移动 eax,[ebp-4] 哪个有效。为什么是这样?我通常使用 C++ 并且习惯于使用这样的实例变量,可能是我使用错误的实例变量。
编辑:是的,就是这样。将mov eax, [asdf] 更改为mov eax, [Self.asdf] 可以解决此问题。对此感到抱歉。
【问题讨论】:
标签: delphi assembly instance-variables basm