Post Reply 
Help me with HP50g -DOSUBS !
03-21-2014, 09:21 AM
Post: #1
Help me with HP50g -DOSUBS !
I started programming in RPN with the HP33E (1974) and continued up to the HP41C.
When I bought the new HP50G I encountered a lot of problems to understand the UserRPN: manuals are not exhaustive !
But the worst came with the command DOSUBS: I really cannot understand how it works: Is there any gentle soul who can write a @comment after every line of the “explanatory example” programs of the RPN Programming manual (!) ?


Example 1:
{ A B C D E }
« - »
DOSUBS
returns { 'A-B' 'B-C' 'C-D' 'D-E' }.

Example 2:
{ A B C }
2
« DUP * * »
DOSUBS
returns { 'A*(B*B)' 'B*(C*C)' }.

Example 3: Entering:
{ 1 2 3 4 5 }
« → a b
« CASE 'NSUB==1' THEN a END
'NSUB==ENDSUB' THEN b END
'a+b' EVAL END » »
DOSUBS
returns { 1 5 7 5 }
Find all posts by this user
Quote this message in a reply
03-21-2014, 12:05 PM (This post was last modified: 03-21-2014 12:05 PM by Dalil.)
Post: #2
RE: Help me with HP50g -DOSUBS !
Hello,


Code:
{ A B C D E }    @ list of element on which the command will be applied
« - »                  @ Command to apply
DOSUBS

What happens is: the command requires 2 arguments (number1 - number2), so for each iteration, the DOSUBS push 2 items onto the stack. What happens at the stack level is, step by step is:

Code:
1st iteration before operation:         |1st iteration after operation:
Stack level:item                        |Stack level:item
2:A                                     |2:
1:B                                     |1:A-B

2nd iteration before operation:         |2nd iteration after operation:
Stack level:item                        |Stack level:item
3:A-B                                   |3:
2:B                                     |2:A-B
1:C                                     |1:B-C


3rd iteration before operation:         |3rd iteration after operation:
Stack level:item                        |Stack level:item
4:A-B                                   |4:
3:B-C                                   |3:A-B
2:C                                     |2:B-C
1:D                                     |1:C-D


4th iteration before operation:         |4th iteration after operation:
Stack level:item                        |Stack level:item
5:A-B                                   |5:
4:B-C                                   |4:A-B
3:C-D                                   |3:B-C
2:D                                     |2:C-D
1:E                                     |1:D-E

at this point all items in the list have been used, the resulting list is constructed and output, i.e. the output is
Code:
{'A-B' 'B-C' 'C-D' 'D-E'}


Code:
Example 2:
{ A B C }          @ list of element on which the command will be applied  
2                  @ number of elements to push on the stack at each iterations
« DUP * * »        @ commands to perform at each iteration
DOSUBS

Something similar to the previous example happens at the stack level.



Code:
Example 3: Entering:
{ 1 2 3 4 5 }                 @ list of element on which the command will be applied 
« -> a b                      @ The function takes 2 arguments, so 2 items will be pushed onto the stack at each iteration
« CASE 'NSUB==1' THEN a END   @ similarly to the first example
'NSUB==ENDSUB' THEN b END     @ and this function will be executed
'a+b' EVAL END » »
DOSUBS
returns { 1 5 7 5 }
Find all posts by this user
Quote this message in a reply
03-21-2014, 05:21 PM
Post: #3
RE: Help me with HP50g -DOSUBS !
nowhere is written that DOSUBS puts the arguments it needs on the stack !
Now I can go on !
Grazie mille (Thanks a lot !)

Carlo
Find all posts by this user
Quote this message in a reply
03-21-2014, 06:32 PM
Post: #4
RE: Help me with HP50g -DOSUBS !
(03-21-2014 05:21 PM)carlovan Wrote:  nowhere is written that DOSUBS puts the arguments it needs on the stack !

You should get yourself an HP-48G/GX manual instead:

http://h10032.www1.hp.com/ctg/Manual/c00442262.pdf

(See page 17-5)

Gerson.
Find all posts by this user
Quote this message in a reply
03-23-2014, 10:19 AM
Post: #5
RE: Help me with HP50g -DOSUBS !
Your help has been useful!

Those who write the HP manuals must be convinced that people who read them is becoming more and more clever, so progressively are shrinking the explanations !

In the next manual, the explanation of the DOSUBS command will be: "guess how it works" !
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)