Need simple example - Calling c subroutine like printf from HLASM program

227 views
Skip to first unread message

McKown, John

unread,
Oct 14, 2011, 9:33:18 AM10/14/11
to ASSEMBL...@listserv.uga.edu
I know that I've seen somebody do this before. But I cannot remember how they did it. Does anybody have a code snippet that shows how to call a C subroutine like sprintf() or strncmp() from HLASM? Also the compile & link JCL would be appreciated. I've tried reading the LE manuals and the C manuals, but I'm just not finding it.

--
John McKown
Systems Engineer IV
IT

Administrative Services Group

HealthMarkets(r)

9151 Boulevard 26 * N. Richland Hills * TX 76010
(817) 255-3225 phone *
john....@healthmarkets.com * www.HealthMarkets.com

Confidentiality Notice: This e-mail message may contain confidential or proprietary information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. HealthMarkets(r) is the brand name for products underwritten and issued by the insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance Company(r), Mid-West National Life Insurance Company of TennesseeSM and The MEGA Life and Health Insurance Company.SM

Gord Tomlin

unread,
Oct 14, 2011, 10:28:26 AM10/14/11
to ASSEMBL...@listserv.uga.edu
You want to make sure you are not creating and destroying a LE
environment for every call, or it will get expensive.

If your calling Assembler program is Language Environment-conforming,
have a look in "z/OS V1R12.0 Language Environment Writing ILC
Applications", section "14.5 Assembler Main Calling HLL Subroutines for
Better Performance"
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/CEEA4180/14.5?SHELF=cee2bkc0&DT=20100628162151

If your calling Assembler program is not LE-conforming, go to "z/OS
V1R13.0 Language Environment Programming Guide", "5.3 Chapter 30. Using
preinitialization services" to read about the use of CEEPIPI
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/CEEA21C0/5.3?SHELF=cee2bkc0&DT=20110618162445


--

Regards, Gord Tomlin
Action Software International
(a division of Mazda Computer Corporation)
Tel: (905) 470-7113, Fax: (905) 470-6507

On 2011-10-14 09:33, McKown, John wrote:
> I know that I've seen somebody do this before. But I cannot remember how they did it. Does anybody have a code snippet that shows how to call a C subroutine like sprintf() or strncmp() from HLASM? Also the compile& link JCL would be appreciated. I've tried reading the LE manuals and the C manuals, but I'm just not finding it.

Lloyd Fuller

unread,
Oct 14, 2011, 11:37:47 AM10/14/11
to ASSEMBL...@listserv.uga.edu
You also want to be careful about the parameters. Some C routines expect values
on the stack (i.e., in-line in the parameter list) and others expect pointers to
the values with most using a mix. That is typically my problem calling or
getting called from C: getting that sequence straight.

Lloyd

Paul Gilmartin

unread,
Oct 14, 2011, 12:11:53 PM10/14/11
to ASSEMBL...@listserv.uga.edu
On Oct 14, 2011, at 09:37, Lloyd Fuller wrote:

> You also want to be careful about the parameters. Some C routines expect values
> on the stack (i.e., in-line in the parameter list) and others expect pointers to
> the values with most using a mix. That is typically my problem calling or
> getting called from C: getting that sequence straight.
>

My understanding is that the C standard calls for all parameters
to be passed by value. My experience is that IBM's C usually
passes parameters by reference except that if a parameter is a
pointer it gets passed by value. Go figger.

-- gil

Farley, Peter x23353

unread,
Oct 14, 2011, 12:30:45 PM10/14/11
to ASSEMBL...@listserv.uga.edu
John, if you are playing with C subroutines and you don't need anything fancy from the C library, try out the METALC option of the C compiler. It generates HLASM code that you then assemble into a load module, so you get to see real assembler calling the METALC equivalents of the C library functions.

Most of the more complex METALC functions are loaded in (I think) LPA/ELPA or somewhere resident anyway and are accessed via a z/OS-resident vector list, so they (usually) don't get linked in. Some functions are implemented with generated inline code (like memcpy).

Plus using the OPT, ARCH and TUNE compiler parameters allows you to take advantage of the C compiler's optimization code, including some pretty cool AGI (address generation interlock) avoidance.

Only a subset of C library functions are supported by METALC, but they are generally the most useful ones.

HTH

Peter

> -----Original Message-----
> From: IBM Mainframe Assembler List [mailto:ASSEMBLER-
> LI...@LISTSERV.UGA.EDU] On Behalf Of McKown, John
> Sent: Friday, October 14, 2011 9:33 AM
> To: ASSEMBL...@LISTSERV.UGA.EDU
> Subject: Need simple example - Calling c subroutine like printf from HLASM
> program
>

> I know that I've seen somebody do this before. But I cannot remember how
> they did it. Does anybody have a code snippet that shows how to call a C
> subroutine like sprintf() or strncmp() from HLASM? Also the compile & link
> JCL would be appreciated. I've tried reading the LE manuals and the C
> manuals, but I'm just not finding it.
--


This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

McKown, John

unread,
Oct 14, 2011, 12:36:53 PM10/14/11
to ASSEMBL...@listserv.uga.edu
Can't - the C compiler isn't licensed.

John McKown

Systems Engineer IV

IT

Administrative Services Group

HealthMarkets(r)

9151 Boulevard 26 * N. Richland Hills * TX 76010

(817) 255-3225 phone *

john....@healthmarkets.com * www.HealthMarkets.com

Confidentiality Notice: This e-mail message may contain confidential or proprietary information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. HealthMarkets(r) is the brand name for products underwritten and issued by the insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance Company(r), Mid-West National Life Insurance Company of TennesseeSM and The MEGA Life and Health Insurance Company.SM

Lloyd Fuller

unread,
Oct 14, 2011, 1:52:50 PM10/14/11
to ASSEMBL...@listserv.uga.edu
Maybe it is just our C cross-platform code, but I have found that some
parameters are by value and some by pointer in most routines. I have not tried
to call printf, etc, as John asked about.

For example, passing a input buffer with its length is typically pointer,
value. Passing an output buffer is typically pointer, pointer so that the
actual output size can be returned to the caller.

We are not as worried about the standard as that the code compiles cleanly and
executes the same way on all of the supported platforms.

Lloyd

----- Original Message ----
From: Paul Gilmartin <PaulGB...@aim.com>
To: ASSEMBL...@LISTSERV.UGA.EDU
Sent: Fri, October 14, 2011 12:11:53 PM
Subject: Re: Need simple example - Calling c subroutine like printf from
HLASM program

Steve Comstock

unread,
Oct 14, 2011, 6:27:09 PM10/14/11
to ASSEMBL...@listserv.uga.edu
On 10/14/2011 7:33 AM, McKown, John wrote:
> I know that I've seen somebody do this before. But I cannot remember how they did it. Does anybody have a code snippet that shows how to call a C subroutine like sprintf() or strncmp() from HLASM? Also the compile& link JCL would be appreciated. I've tried reading the LE manuals and the C manuals, but I'm just not finding it.

>
> --
> John McKown
> Systems Engineer IV
> IT
>
> Administrative Services Group
>
> HealthMarkets(r)
>
> 9151 Boulevard 26 * N. Richland Hills * TX 76010
> (817) 255-3225 phone *
> john....@healthmarkets.com * www.HealthMarkets.com
>
> Confidentiality Notice: This e-mail message may contain confidential or proprietary information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. HealthMarkets(r) is the brand name for products underwritten and issued by the insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance Company(r), Mid-West National Life Insurance Company of TennesseeSM and The MEGA Life and Health Insurance Company.SM
>

out_pat dc c'%s',x'1500'
l_prompt dc c'Press <Enter> to call dpdse using link.',x'00'


ddisplay ds 0h
call printf,(out_pat,l_prompt),vl,mf=(e,plist)

- snippet from various courses.


--

Kind regards,

-Steve Comstock
The Trainer's Friend, Inc.

303-393-8716
http://www.trainersfriend.com

* Special promotion: 15% off on all DB2 training classes
scheduled by September 1, taught by year end 2011

* Check out our entire DB2 curriculum at:
http://www.trainersfriend.com/DB2_and_VSAM_courses/DB2curric.htm

Reply all
Reply to author
Forward
0 new messages