Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi assembler constant 'eof'

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.

This prints out 14.

Where does that constant eof and it's value value $0E or 14 come from?


EDIT: this is the compilation result

...
call @InitExe
// mov example, eof
mov [example], $0000000e
// writeln(example)
mov eax, [$004040a4]
mov edx, [example]
call @Write0Long
call @WriteLn
call @_IOTest
// readln;
...
like image 753
Egon Avatar asked Jan 02 '12 16:01

Egon


1 Answers

Eof is in fact a function defined in the System unit.

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;

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.

like image 135
David Heffernan Avatar answered Oct 24 '22 09:10

David Heffernan