HP Forums
HP71B/75: How to use SUB, ENDSUB, CALL - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: HP71B/75: How to use SUB, ENDSUB, CALL (/thread-6822.html)



HP71B/75: How to use SUB, ENDSUB, CALL - Eddie W. Shore - 09-10-2016 12:16 AM

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.


RE: HP71B/75: How to use SUB, ENDSUB, CALL - Namir - 09-10-2016 01:40 AM

(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.


RE: HP71B/75: How to use SUB, ENDSUB, CALL - Garth Wilson - 09-10-2016 03:43 AM

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.


RE: HP71B/75: How to use SUB, ENDSUB, CALL - Namir - 09-10-2016 01:26 PM

(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


RE: HP71B/75: How to use SUB, ENDSUB, CALL - Eddie W. Shore - 09-11-2016 01:51 AM

(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


RE: HP71B/75: How to use SUB, ENDSUB, CALL - Joe Horn - 09-11-2016 09:21 AM

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.


RE: HP71B/75: How to use SUB, ENDSUB, CALL - Namir - 09-11-2016 12:11 PM

Very cool file Joe!!


RE: HP71B/75: How to use SUB, ENDSUB, CALL - Eddie W. Shore - 09-13-2016 01:20 PM

Thank you Joe!