Delphi汇编程序常量'eof' [英] Delphi assembler constant 'eof'
问题描述
在asm块上下文中似乎有一个未记录的常量 eof
.使用Delphi 7对此进行了测试.
There seems to be an undocumented constant eof
in asm block context. This was tested using Delphi 7.
program TestEof;
{$APPTYPE CONSOLE}
var
example : Integer;
begin
asm
mov example, eof
end;
writeln(example);
readln;
end.
这会打印出 14
.
该常量 eof
从何而来?它的值 $ 0E
或 14
来自何处?
Where does that constant eof
and it's value value $0E
or 14
come from?
这是编译结果
...
call @InitExe
// mov example, eof
mov [example], $0000000e
// writeln(example)
mov eax, [$004040a4]
mov edx, [example]
call @Write0Long
call @WriteLn
call @_IOTest
// readln;
...
推荐答案
Eof
is in fact a function defined in the System
unit.
在我手头的Delphi 6和XE2的Delphi实现中, Eof
被实现为
In the implementations of Delphi that I have at hand, Delphi 6 and XE2, Eof
is implemented as an intrinsic routine that results in a call to one of the following functions, as appropriate:
function _EofFile(var f: TFileRec): Boolean;
function _EofText(var t: TTextRec): Boolean;
我不知道为什么您的汇编代码变成了 mov [...],$ 0000000e
.您在注释中指出, System
单元本身利用了 asm
代码中的 eof
,例如,在 TextOpen
.XE2中的相同代码现在是纯Pascal,并且搜索值 $ 1A
而不是 $ 0E
.这似乎是一个实现细节.如果您想了解为什么会这样,那么我认为您需要对 System
单元中的代码进行反向工程,或者看看Embarcadero的工程师是否会向您解释实现.
I have no idea why your assembler code is turned into mov [...],$0000000e
. You point out in a comment that the System
unit itself makes use of eof
in asm
code, for example in TextOpen
. The same code in XE2 is now pure Pascal and searches for a value of $1A
instead of $0E
. This would very much appear to be an implementation detail. If you want to understand why this is so then I think you will need to reverse engineer the code in the System
unit, or see if the engineers at Embarcadero will explain the implementation to you.
这篇关于Delphi汇编程序常量'eof'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!