[fpc-pascal] [OT] inline procedures in TP 7.0
Anton Shepelev
anton.txt at gmail.com
Sun Feb 16 22:28:36 CET 2020
Hello, all
I don't know a better place to ask this, and beg your pardon
for an off-topic post.
The Language Guide for Turbo Pascal 7.0 has this to say
about `inline' statements and proceudres:
When a normal procedure or function is called, the com-
piler generates code that pushes the procedure's or
function's parameters onto the stack and then generates
a CALL instruction to call the procedure or function.
When you call an inline procedure or function, the com-
piler generates code from the inline directive instead
of the CALL. Therefore, an inline procedure or function
is expanded every time you refer to it, just like a
macro in assembly language.
[...]
With inline directives, you can write procedures and
functions that expand into a given sequence of machine
code instructions whenever they are called. These are
comparable to macros in assembly language.
[...]
Registers BP, SP, SS, and DS must be preserved by inline
statements: all other registers can be modified.
But which registers shall be preserved by inline proceudres
and functions? In this example from the manual, the SP
register is not preserved within the statement:
function LongMul(X, Y: Integer): Longint;
inline (
$5A/ {POP AX}
$58/ {POP DX}
$F7/$EA); {IMUL DX}
Does it mean it shall reset SP to a position before the
parameters? What about the other registers -- does Turbo
Pascal take care of them, perhaps enveloping each expansion
of an inline procedure into a POPs and PUSHes?
--
Please, do not forward replies to my e-mail.
More information about the fpc-pascal
mailing list