MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Subroutine in assmebler language

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Fri May 23, 2008 1:43 pm    Post subject: Subroutine in assmebler language Reply with quote

I am new to assembler language. In REXX, I pass parameters to a function and get the return values. Example:

Code:

parse value MyFunc(Q1_Inp1, Q1_Inp2, Q1_Inp3) with,
  Q1_Out1 Q1_Out2 Q1_Out3 Q1_Out4
.....            
.....      
parse value MyFunc(Q2_Inp1, Q2_Inp2, Q2_Inp3) with,
  Q2_Out1 Q2_Out2 Q2_Out3 Q2_Out4
.....            
.....
Exit

MyFunc: Procedure
  parse arg Inp1, Inp2, Inp3
  .....         
  .....
Return Out1 Out2 Out3


I know how to branch to the subroutine using BAL. How do I pass input/output parameters (either character or packed decimal) between the subroutine and main program in assembler language?
Back to top
View user's profile Send private message
Bill Dennis
Advanced


Joined: 03 Dec 2002
Posts: 579
Topics: 1
Location: Iowa, USA

PostPosted: Fri May 23, 2008 3:00 pm    Post subject: Reply with quote

You should follow the standard linkage conventions. Before the BAL, set up your parameter list, store the address of the list into a fullword and load the address of that fullword into Register 1.

The first halfword in the parameter list is typically the length of the parameter list.

You might let the subroutine update the parameter list you send it or you can repeat the process prior to returning and the main programs can find the return parm from Reg 1.
_________________
Regards,
Bill Dennis

Disclaimer: My comments on this foorum are my own and do not represent the opinions or suggestions of any other person or business entity.
Back to top
View user's profile Send private message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Tue May 27, 2008 9:08 am    Post subject: Reply with quote

Bill,
I read similiar instructions in an old assembler programming book. Unfortunally, it doesn't provide sample codes. I will be helpful if there are some sample codes to look at.

The book mentioned contruct an address list and load the address list to a register (e.g. register 1) priot to calling the subroutine:
Code:

ADDRLST1 DC   A(Q1_Inp1)
              A(Q1_Inp2)
              A(Q1_Inp3)
              A(Q1_Out1)
              A(Q1_Out2)
              A(Q1_Out3)
              A(Q1_Out4)
         LA   1,ADDRLST1
         BAL  5,MYFUNC

Here are some of the questions:
Code:

1. If I call the subroutine 3 times with different parameter list, do I need to set up 3 address lists (i.e. ADDRLST2 for Q2_XXX, ADDRLST3 for Q3_XXX)

2. Once inside the subroutine, how do I assgin the value from the address list (1st one to Inp1, 2nd to Inp2..6th to Out3 etc.)?  I want to be able to reference the variables by names in the subroutine, i.e.  Inp1, Inp2...Out3. 
Back to top
View user's profile Send private message
Bill Dennis
Advanced


Joined: 03 Dec 2002
Posts: 579
Topics: 1
Location: Iowa, USA

PostPosted: Tue May 27, 2008 12:37 pm    Post subject: Reply with quote

Three separate parm lists would be the least complicated. Just point R1 at the proper list prior to the call.

Are the areas (Q1_INP1 ,Q1_INP2, etc) contiguous in storage? I mean could you only pass one address being the start of the area?

In the subroutine, store the parm list pointer in R1 into another register/fullword, load the desired address from the list into a register and set up a USING on that reg to a dsect describing that area.
_________________
Regards,
Bill Dennis

Disclaimer: My comments on this foorum are my own and do not represent the opinions or suggestions of any other person or business entity.
Back to top
View user's profile Send private message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Wed May 28, 2008 8:22 am    Post subject: Reply with quote

Bill,

No, input parameters (Q1_INP1, Q1_INP2 etc.) are not contiguous in storage, but the output parameters (Q1_OUT1, Q1_OUT2 etc.) are contiguous. I am not familiar with DSECT and will try to look it up.
Back to top
View user's profile Send private message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Wed May 28, 2008 8:23 am    Post subject: Reply with quote

Bill,

No, input parameters (Q1_INP1, Q1_INP2 etc.) are not contiguous in storage, but the output parameters (Q1_OUT1, Q1_OUT2 etc.) are contiguous. I am not familiar with DSECT and will try to look it up.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group