[fpc-pascal] Does the compiler make prodigious use of use ENTER instruction?
Bernd Oppolzer
bernd.oppolzer at t-online.de
Tue Dec 12 22:04:54 CET 2023
I wrote a comment on the original Microsoft dev blog (for a non-Pascal
community), maybe it's of interest here, too ...
In normal Pascal procedure calls, such a vector of stack frame addresses
is not needed. A standard Pascal runtime knows all the time about the
current stack frame address of – say – the procedure which is currently
active at static level n. This information is called the DISPLAY VECTOR
and there is no need to copy the display vector on procedure calls,
because it is stored at a well-known location inside the runtime. You
only have to replace the stack frame addresses of the current static
level, when you enter or leave a procedure (and maybe set the new
current static level).
What makes things more complicated, are procedure and function
PARAMETERS (in Pascal), that is: procedures that are passed as
parameters to other procedures. In this case, it is indeed necessary to
COPY THE COMPLETE DISPLAY VECTOR, because it is not possible to predict
what static level the procedure (which is passed as a parameter) has. So
maybe the ENTER instruction is meant for such use cases.
Some of the old Pascal compilers didn’t allow procedure parameters (or
implemented them badly) due to these difficulties.
To see, if your (Pascal or Algol) compiler implemented procedure
parameters correctly, you can use the “Man or Boy” test:
https://en.wikipedia.org/wiki/Man_or_boy_test
Am 12.12.2023 um 17:48 schrieb Anthony Walter via fpc-pascal:
> Iwas reading this article today on the Microsoft website about the
> mysterious x86 ENTER instruction. The article states that it's primary
> purpose is to support Pascal and similar compilers to allow for
> preserving local variables on the stack when using with nested functions.
>
> Here is the article:
>
> https://devblogs.microsoft.com/oldnewthing/20231211-00/?p=109126
>
> Do any of the compiler devs know if Pascal programs for the x86
> instruction set are using ENTER and its second argument to the best
> possible effect? I am curious.
>
> _______________________________________________
> fpc-pascal maillist -fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20231212/f9083376/attachment.htm>
More information about the fpc-pascal
mailing list