What I need to understand is: how shall I start up a simple internal subroutine such that I can call it? To call the subroutine, I invoke BAL
R14,subroutine - with subroutine being a selected name. To return from a subroutine, I code BR R14.
According to the material, a program begins with
ONE CSECT
SAVE (14,12)
BALR 12,0
USING *,12
LA 2,SAVEAREA
ST 2,8(,13)
ST 13,4(,2)
LR 13,2
…
SAVEAREA DS 18F
A New Instruction - BAL
— The Branch and Link instruc4on or the Branch and Link Register
instruction is used, normally, for subroutine calls
— Their formats are:
BAL R_1,D_2(X_2,B_2)
BALR R_1,R_2
— The address of the next instruc4on is stored in R_1 before branching
Save Areas
A 72-Ââ€byte area
− SAVEAREA + 0 = unused
− SAVEAREA + 4 = Previous save area
− SAVEAREA + 8 = Next save area − SAVEAREA+12 = Return Address − SAVEAREA + 16 = EPA
− SAVEAREA+20 = Register 0
− SAVEAREA+24=Register 1
− …
− SAVEAREA + 68 = Register 12
Leaving a Program
     L   13,4(,13)Â
−  Unchain save areasÂ
−  Point register 13 to the previous save areaÂ
     RETURN  (14,12)Â
−  An IBM macroÂ
−  Restores registers 14 through 12 from the values in the save areaÂ
addressed by register 13Â
−  Branches to the address in register 14
SUMRTN DS 0H
PACK WORK8,0(5,R1)
AP TOTAL,WORK8
BR R15