IBM 1130 - Programming - Subprograms

Subprograms

The 1130 had no support for a stack. Most subprograms were called with the instruction BSI (Branch and Store IAR). This deposited the value of IAR (the return address) at the destination address and transferred control to the next word. Subprograms returned to wherever they were called on that occasion using an indirect branch through that first word of the subprogram.

So a subprogram named SIMPL might be organized as follows:

SIMPL: DC *-* This is the entry point, filled with a zero initially. (whatever the routine does) B I SIMPL Return by an Indirect branch, to the address found in location SIMPL. END SIMPL Instructs the assembler that the source for routine SIMPLE is complete.

The subprogram would be called as follows:

BSI L SIMPL Call SIMPL. L (Long) is needed if SIMPL is more than -128 or +127 words away.

The pseudo-operation CALL would typically be used.

As shown, a subprogram's entry point was DC *-*. This code resulted in a zero word, and the only point of writing it this way was as a visually distinctive note that a meaningful value (the return address) will be placed there at run time. The entry point need not be the first word of the subprogram. Indeed, the preceding word could be the start of a two-word direct branch instruction whose address field would be at SIMPL. Then, returns could be effected by one-word branches there: B SIMPL-1

When SIMPL is called, the BSI instruction replaces *-* with the address just past the BSI instruction. After SIMPL does whatever it is written to do, B I SIMPL branches not to SIMPL, but indirect through it, typically returning to just past the BSI instruction that called it.

Without extra arrangements to protect the return address, recursion would be impossible: If SIMPL called itself, or called a subprogram that called it, its original return address would be overwritten. Re-entrancy was problematic for the same reason: An interrupt service routine must refrain from calling any subprogram that might have been the code that was interrupted.

The caller of SIMPL might pass it parameters, which might be values or addresses of values. Parameters might be coded in-line (immediately following the BSI instruction) or might be placed in index registers XR1 and XR2. If parameters were placed in-line, SIMPL would modify its own return address so its final indirect branch returned beyond the parameters.

Integer functions of a single integer would expect the parameter in the accumulator and would return their result there. Floating-point functions employed the floating-point accumulator (a two word area set aside by the floating-point library, three words for extended precision), and so on.

The convention of coding 0 as the initial value at the entry point meant that if a programming error led to SIMPL returning before the first time it was ever called, execution would jump to memory location 0. As mentioned above, it was customary to have location 0 contain a branch to location 0. The 1130 would be stuck at location 0, and the IAR lights on the console would be entirely dark, making it clear the program had failed.

Read more about this topic:  IBM 1130, Programming