HP Forums

Full Version: HP71B/75: How to use SUB, ENDSUB, CALL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Question for the HP 71B/75 experts:

How do I use SUB, END SUB, and CALL? Is it really any different from using GOSUB and RETURN using line numbers? Thanks.
(09-10-2016 12:16 AM)Eddie W. Shore Wrote: [ -> ]Question for the HP 71B/75 experts:

How do I use SUB, END SUB, and CALL? Is it really any different from using GOSUB and RETURN using line numbers? Thanks.

Yes, the CALL sub is different. General syntax:

SUB <subname>(<list of parameters>)
<statements>
END SUB

CALL <subname>(<list of arguments>)

The data type (and scalar/array designations) of the argument list must match that of the parameter list.

Parameters that are arrays are passed by reference. Reference manual not clear about non-array parameters. Enclosing an argument in () makes it passed by value. Arrays must include () (such as A()). Two or more dimensional arrays must include commas to indicate the number of dimensions So , A(,) indicates that it is a matrix.

I encourage you to consult the HP-71B and HP75C/D documentation.
A nice thing about SUBprograms is that they have local environments, so they don't step on identically named variables, etc. from other programs or subprograms that might be pending. A subprogram can even call itself recursively, up to 63 levels deep IIRC, and each level will have its own environment. The subprogram does not have to be in the same program file; and if there might be two or more subprograms with the same name, you can specify where to look to find the right one. The CALL can also be indirect, with the subprogram's name being in a string. It's really quite powerful. The list in input and output parameters can be quite long. This is all 71 stuff. I don't know if the 75 differs.
(09-10-2016 12:16 AM)Eddie W. Shore Wrote: [ -> ]Question for the HP 71B/75 experts:

How do I use SUB, END SUB, and CALL? Is it really any different from using GOSUB and RETURN using line numbers? Thanks.

We can talk about SUBs at HHC2016.

Namir
(09-10-2016 01:26 PM)Namir Wrote: [ -> ]
(09-10-2016 12:16 AM)Eddie W. Shore Wrote: [ -> ]Question for the HP 71B/75 experts:

How do I use SUB, END SUB, and CALL? Is it really any different from using GOSUB and RETURN using line numbers? Thanks.

We can talk about SUBs at HHC2016.

Namir

Looking forward to it,

Eddie
If you do a PDF search for "subprogram" in The Titan File Collection, you'll find many simple examples, as well as explanations of why these short programs are best as SUBprograms rather than regular programs.
Very cool file Joe!!
Thank you Joe!
Reference URL's