IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

XCTL,LINK,LOAD,BALR (BASR) and CALL.


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
GAFUR

New User


Joined: 19 May 2005
Posts: 31

PostPosted: Thu Feb 14, 2008 6:18 pm
Reply with quote

Hello freinds,


I have a basic question about assembler. Can you provide me a detailed explanation about differences between the ways to call a sub program (XCTL,LINK,LOAD,BALR and CALL). I just wanted know which is dynamic and which is static. Please explain how they will manage storage and how they will return control to calling program. what are scenarios we will use each of the these instruction?


Thanks.
Abdul
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Feb 15, 2008 1:42 am
Reply with quote

Batch Assembler and native CICS offer the XCTL, LOAD and LINK macros/commands.

XCTL does NOT return control to the program which issued it, regardless whether this is Assembler or CICS.

The LOAD macro/command brings an external module into memory and returns the LP (Load Point) address.

The LINK macro/command issues (under the covers) a BALR/BASR and returns control to the NSI (Next Sequential Instruction).

BALR/BASR are used in Assembler and are also used in CICS (after expansion).

A static call (CALL Macro) is when a VCON address (module is merged with the caller) is loaded into R15, followed by a BALR/BASR 14,15.

A dynamic call is when a LOAD is first performed, then the LP address is loaded into R15, followed by a BALR/BASR 14,15.

In both a static and/or dynamic call, R1 must be loaded beforehand with the parmlist address.

The remaining explanations/issues should be left as an exercise/follow-up for the requestor.

HTH....

Regards,

Bill
Back to top
View user's profile Send private message
sandhyarenu

New User


Joined: 04 Jan 2007
Posts: 16
Location: India

PostPosted: Mon Jun 16, 2008 11:08 am
Reply with quote

HI,

How do we call a subroutine from a main program in Assembler. Let's say the task is to call pgm b from pgm A . I assume the command that achieves this is BALR R1,R2 in pgm A . What I don't understand is what should be the content of R1 & R2. Also, where do I give the pgm name of the one to be called (in my case B). How does the control pass from A to B. Shouldn't I be using a CALL command anywhere ? I am lost between CALL and BALR. Kindly help.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Jun 16, 2008 12:23 pm
Reply with quote

Hi sandhyarenu !

First, in accordance with the terms of IBM, it's allways BALR R14,R15 or
BASM R14,R15. Where content of R15 is the entrypoint of the loaded subprogramm. R1 is allways used for the adress of the parameters that are passed to the subprogramm. R14 will automatically filled with the needed adress to return back to the calling programm.

Example, Pgm-A (MDL00900) calls other Pgm-B (MDL00910):

In MDL00900:

LOAD EP=MDL00910 ...load EntryPointLocation MDL00910
ST R0,MDL00910_ENTPOINT ...store that Adress

L R01,MDL00910_CALLPARM ...Adress of PARM-LIST
L R15,MDL00910_ENTPOINT ...EPL MDL00910

BASSM R14,R15 ...pass control to other PGM

...next instruction , check Return-Code-Field

SPACE
MDL00910_CALLPARM DC 01F'0' ...PARM-ADR PGM MDL00910
MDL00910_ENTPOINT DC 01A(0) ...ADRESSE PGM MDL00910

MDL00900_PARAMETER DSECT
SPACE
MDL00900§PANF DS 0F
SPACE
MDL00900_PGMFUC DC CL04' ' ...PGM-FUNKTION PIC X(04)
MDL00900_PGMMOD DC CL04' ' ...PGM-CALLMODE PIC X(04)
MDL00900_PGMCMD DC CL04' ' ...PGM-PGCOMAND PIC X(04)
MDL00900_PGMRTC DC CL04' ' ...PGM-RETUCODE PIC X(04)
SPACE
MDL00900§PEND DS 0F


In MDL00910:

MDL00910 CSECT
ENTRY MDL00910
MDL00910_BEGIN DS 0H
STM R14,R12,12(R13) ...STORE REGS IN CALLERS SAVE
LR R9,R15 ...LOAD R9 ADRESS CALLERS R15
USING MDL00910_BEGIN,R9 ...AND USE IT AS BASE-REGISTER
SPACE
LA R15,MDL00910_SAVEAREA ...LOAD OWN PGM-SAVEAREA
ST R15,8(R13) ...STORE IN CALLERS SAVE-AREA
ST R13,4(R15) ...STORE IN OWN SAV-EAREA
LR R13,R15 ...POINT R13 TO OWN SAVE-AREA
SPACE
B MDL00910_START
MDL00910_START DS 0H
SR R2,R2 ...DELETE REGISTER-2
L R2,0(R1) ...LOAD PARM-ADRESS
USING MDL00900_PARAMETER,R2 ...APPROPRIATE DSECT PARM-AREA
.....
.....
MDL00910_STOPP DS 0H
SPACE
B MDL00910_ENDE
MDL00910_ENDE DS 0H PROGRAMM-ENDE
L R13,MDL00910_SAVEAREA+4 ...LOAD CALLERS SAVE-AREA
LM R14,R12,12(R13) ...RELOAD ALL THE REGISTERS
SR R15,R15 ...CLEAR REGISTER-15
BR R14 ...GET OUT OF HERE


SPACE
MDL00900_PARAMETER DSECT
SPACE
MDL00900§PANF DS 0F
SPACE
MDL00900_PGMFUC DC CL04' ' ...PGM-FUNKTION PIC X(04)
MDL00900_PGMMOD DC CL04' ' ...PGM-CALLMODE PIC X(04)
MDL00900_PGMCMD DC CL04' ' ...PGM-PGCOMAND PIC X(04)
MDL00900_PGMRTC DC CL04' ' ...PGM-RETUCODE PIC X(04)
SPACE
MDL00910§PEND DS 0F
SPACE


Regards, UmeySan
Back to top
View user's profile Send private message
sandhyarenu

New User


Joined: 04 Jan 2007
Posts: 16
Location: India

PostPosted: Tue Jun 17, 2008 11:03 am
Reply with quote

Thanks very much, UmeySan for this detailed explanation. But isn't BASSM used for connecting assembler programs with different address modes ? My program uses BALR, (Code below) but it keeps hitting the compilation error 'No active USING for operand =A(PARMS)'. PARMS in our code is a DSECT containing the declaration of the variables which are passed to the called pgm.

STM R14,R12,12(R13) SAVE REGISTERS
BALR R12,0
USING *,R12

ST R13,SAVEAREA+4

LA R13,SAVEAREA POINT TO MY SAVEAREA
LA R1,=A(PARMS)
USING PARMS,R13
L R15,ASUB
BALR R14,R15

Any thoughts ? Thnkx again !!!
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1205
Location: Dublin, Ireland

PostPosted: Tue Jun 17, 2008 1:26 pm
Reply with quote

The reason you are getting " NO ACTIVE USING" message is that your USING statement must precede the statement. Coding it after, as you have, means that the Assembler can't resolve the address.

However,

Quote:
LA R1,=A(PARMS)


This looks incorrect. You are trying to load the address of an address. This should read either of:

Code:
     LA   R1,PARMS

or
Code:
     L     R1,=A(PARMS)


The effect of your code is to pass your SAVEAREA as a parameter to the called program. Is this what you want?? It looks unusual to me.

Regards,
Garry.
Back to top
View user's profile Send private message
GAFUR

New User


Joined: 19 May 2005
Posts: 31

PostPosted: Tue Jun 17, 2008 1:29 pm
Reply with quote

sandhyarenu,

You are using the address constant =A(PARMS).

Adress contants support for DC.

The LA instruction is not in proper way, use LA 1, PARMS.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Jun 17, 2008 1:56 pm
Reply with quote

Hi sandhyarenu !

No active using :
LA R1,=A(PARMS)
USING PARMS,R13

Coding it after or before does not matter.

The fact that matters here, is that you are using two different registers, you deal with R1 for the adress and r13 for the desect.

LA R11,=A(DesectName)
Using R11,DesectName

Regards, UmeySan
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Jun 17, 2008 2:12 pm
Reply with quote

Hi sandhyarenu !

BALR & BASSM:

Your statemant at this point is correct.

I allways use BASSM, cause very often i have to change mode before/after call to handle adress-mode.

But what you could also do:

LOAD EPLOC=Sub_Programm
ST R0,Entry_Point_Of_Subprogramm



LA R6,Parameter_List
LA R13,Save_Area_Adress

L R15,Entry_Point_Adress_Of_Subprogramm
CALL (R15),((R6))

LTR R15,R15 ...check ReturnCode


Regards, UmeySan
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Jun 17, 2008 2:17 pm
Reply with quote

Hi sandhyarenu !

Sorry, i forgot one important fact about calling other programms:

Please do the Load EntryPoint only once in your routine. You could check the fullword before Load to achieve this. So you don't have multiple copies in the storage.

For example:

IF (MDL00900§EPLA,Z,MDL00900§EPLA,OC)
THEN C='MODUL IS NOT YET LOADED'

LOAD EP=MDL00900
ST R0,MDL00900§EPLA

EIF

Regards, UmeySan
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1205
Location: Dublin, Ireland

PostPosted: Tue Jun 17, 2008 2:18 pm
Reply with quote

Quote:
Coding it after or before does not matter.


This statement is incorrect. A Using statement must precede any instruction referencing a DSECT as otherwise the Assembler can't resolve the address.

What you should do is to load R1 with the address of the parameters you wish to pass, which probably isn't the address of your savearea.

Quote:
LA R11,=A(DesectName)
Using R11,DesectName
is also incorrect since the Assembler doesn't know what DsectName means until after seeing the USING statement.

The location of your parameters is either a constant within your program or an address you acquired (e.g via Storage Obtain). R1 should be loaded with this address.


Code:
          L     R1=A(PARMAREA)
          USING PARMS,R1
          .
          .
          .
          .
PARMAREA  DC   D
          .
          .   
PARMS   DSECT
PARM1   DS  F
PARM2   DS  F

Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Jun 17, 2008 3:12 pm
Reply with quote

@ Garry Carroll !

...Ok, a little malformed example. A Using statement must precede any instruction referencing to a DSECT-Field, that woud be correct !

What i only meant was, that it's not important if you first code the LA and then the USING or do it the other way round.

LA R11,... / Using R11,... or Using r11,... / LA R11,...

The only thing for NO ACTIVE USING was the use of two different registers.


For example:

USING IHADCB,R11 ...DSECT OF DCB-SYSTEM-CONTROLBLOCK
L R11,=A(INPUT_DCB) ...Adress of DCB for Input-Dataset

IF DCBOFLGS,Z,DCBOFOPN,TM
THEN C='DSN is not yet open'
OPEN ((R11),INPUT)
LH R7,DCBLRECL ...Get LRECL
EIF


ore other way round:

USING MDL00900_PARAMETER,R2 ...appropriate Dsect
L R2,0(R1) ...use adress provided in reg-1
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Jun 17, 2008 3:15 pm
Reply with quote

And btw:

in the example of sandhyarenu, that fucking USING instruction has no practical effect.

LA R1,=A(PARMS)
L R15,ASUB
BALR R14,R15

That's all he needs.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Jun 17, 2008 3:22 pm
Reply with quote

Ok ok, I just coppied that shitty LA R1,=A(PARMS) instruction.
Sorry, i'm getting old.
Back to top
View user's profile Send private message
sandhyarenu

New User


Joined: 04 Jan 2007
Posts: 16
Location: India

PostPosted: Tue Jun 17, 2008 4:07 pm
Reply with quote

Actually, Garry's tip worked. I changed the position of USING and reworded LA statement and it went fine icon_smile.gif). Thank you ALL for the great help.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1205
Location: Dublin, Ireland

PostPosted: Tue Jun 17, 2008 4:13 pm
Reply with quote

Glad to have been of help.

Garry.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts IEW2315E 1369 Link error All Other Mainframe Topics 3
No new posts Call an hlasm from REXX in batch and ... CLIST & REXX 4
No new posts Unload and Load ISPF Table TSO/ISPF 4
No new posts Load new table with Old unload - DB2 DB2 6
No new posts How to load to DB2 with column level ... DB2 6
Search our Forums:

Back to Top