>glen herrmannsfeldt wrote:
>In alt.sys.pdp11 Jerome H. Fine <everyone@nospam.com> wrote:

(snip)
  
I made some modifications to MACRO-11 which counts the
number of times an overlay is read into memory in addition
to the number of times the overlay is called - the difference
being the number of times the overlay was called, but was
already memory.  The numbers are displayed at the end
of the listing along with the elapsed time.
    
I used to know how the overlay for OS/360 worked.  I believe
it is only two instructions if the segment is already in
memory.  It uses self-modifying code to write the load and
branch instructions to not call the overlay handler.
(Branch to an arbitrary address takes two instructions,
load the address into a register, and then branch.)
  
I just looked again at the RT-11 overlay handler for low memory
overlays.  The exact instruction count is 15 instructions in
total (including the instruction which CALLs the instruction
which CALLs the overlay handler with the required arguments)
when the subroutine is in an overlay which is already in memory.
15 instructions includes a redundant PUSH and POP of R0
when the overlay is in memory - although it was convenient to
keep them in order to use R0 as the base address of the table
which keeps track of the number of times an overlay is CALLed.

The code is also self modifying, but ONLY the very first time
an overlay segment is CALLed so that all of the memory used
by overlays can be zeroed.

The method adds an extra CALL instruction, but reduces overall
code size when many calls are made to the same subroutine in
an overlay.
I do remember using the RT-11 overlay system with Fortran,
but not how many instructions it took.  I would think it could
use something similar to the self modifying branch, though.
The overlay handler code is identical no matter which language
is used.  The instruction used to CALL the instruction which
CALLs the overlay handler with the correct arguments is
also compatible with FORTRAN conventions as well as
every other language since other than the initial CALL instruction,
everything else is hidden from the user application program.

Jerome Fine