Re: Re: Assembler Clarification
Rick Fochtman <[email protected]>
| Newsgroups | gmane.comp.emulators.turnkey-mvs |
|---|---|
| Message-ID | <[email protected]> |
-------------------------------<snip>-----------------------------------
Where you store the registers is called a save area. These are forward
and backward linked like a stack. For Open System Services, a hardware
stack was added in OS/390.
Upon Entry,
> R0 can be used as a binary number, but is evaluated as 0 as an address
> value.
> R1 points to a list of addresses to the parameters, the high order bit
> is set to 1 for the last 24/31 bit address.
> R2 is used by some instructions and an alternative cannot be coded..
> R2-12 can be used as base registers.
> R13 points to the previous save area, which you use to store the
> registers.
> R14 points to the return address, where you branch when you are done.
> R15 points to the entry address, the first instruction in your program.
> R2 is used by some instructions.
> R2-12 can be used as base registers.
> R15 is used as a base address until you get your own going.
>
------------------------------<unsnip>--------------------------------
If you're an "Artful Dodger" like me, you can use R13, the save area
pointer, as a base register as well. Note the following code snippets:
MYNAME CSECT
B 12(,15)
BRANCH AROUND ...
DC AL1(7),CL7,'MYNAME' CSECT ID FOR DUMP
PROCESSOR
STM 14,12,12(13) SAVE
ENTRY REGISTERS
BAL 2,92(,15) SCOOT
AROUND NEW SAVE AREA
USING *,13
DECLARE THE BASE REGISTER
DS 18F
NEW SAVE AREA
XC 0(72,2),0(2) CLEAR
NEW SAVE AREA
ST 2,8(,13)
STORE DOWNWARD POINTER
ST 13,4(,2)
STORE UPWARD POINTER
LR 13,2
LOAD SA POINTER/BASE REG
.....
..... (whatever your program or
subroutine needs to do)
.....
* EXIT CODE
L 13,4(,13)
LOAD BACK S.A. POINTER
L 14,12(,13)
LOAD RETURN ADDRESS
LM 2,12,28(13)
RESTORE SIGNIFICANT REGS
LA 15,0
SET RETURN CODE ZERO
BR 14
RETURN TO CALLER(USUALLY MVS INITIATOR)
Note that this code is NOT reentrant. It's offered here strictly for
illustrative purposes. Reuse as you see fit.
Note also that all registers except the Save Area pointer are saved;
preserving 14,15,0 and 1 are highly useful in debugging, for tracing
back parameter information and call paths.
This is one example of entry/exit linkage for an assembler program or a
subroutine called by another assembler program or a high-level language
routine. It works fine for FORTRAN, COBOL and Assembler programs, but
PL/1 linkage is far more complex due to the various data formats used
within and between PL/1 programs. I don't propose to got into that in
detail.
Rick