Post Reply 
WP 34S - How do I use aGTO with stack registers?
12-13-2017, 11:46 AM
Post: #1
WP 34S - How do I use aGTO with stack registers?
Hi,

I played a bit with the "alpha GOTO" (aGTO) command which is a very powerful command for branching.

The description on p. 186 of my printed manual (V3.3) reads:
aGTO _s_
Interprets _s_ as a character code. Takes the first 3 characters of the converted code (or all if there are less than 3) as an alpha label and positions the program pointer to it.

I had some problems with applying this function correctly.

1) Direct addressing
If I have 101 or 101.234 in R00 and "aGTO 00", the program counter is set to LBL 'e' (char code 101d).
This works as I expected.
However, if I have 101234 in R00 and "aGTO 00" I get "No such Label".
Obviously the register must contain less than 4 digits and the command does not just "take the first 3 characters", as per description.

2) Indirect addressing
If I have 101 in R00 and 0 in R01 "aGTO->01" the program counter is set to LBL 'e'.
This works as I expected.

3) Indirect addressing via a stack register
If I have 101 in R00 and 0 in RX "aGTO->.X" the program counter is set to LBL 'e'.
This works as I expected.

3) Direct addressing via a stack register
If I have 101 in RX and "aGTO .X", I would expect the same outcome, but I receive "No such Label".
Am I doing something wrong here?

Proposed alternative description:

aGOTO _s_
Interprets the content of _s_ as a character code.
Converts the integer part of the register content (must have 3 or less digits) to a character and positions the program pointer at the corresponding global label.
... some comments on the usage of stack registers if needed ...

Martin
Find all posts by this user
Quote this message in a reply
12-13-2017, 11:31 PM
Post: #2
RE: WP 34S - How do I use aGTO with stack registers?
You should use the alphaSTO command to put characters into registers. I don't believe we defined the mapping from characters to registers.

The encoding isn't decimal, it is base 256. Even entering characters in base 256 is not a guarantee anything will work. In real mode, it is pretty much guaranteed that it won't due to the formatting of numbers. In integer mode there is a chance.


Pauli
Find all posts by this user
Quote this message in a reply
01-04-2018, 04:19 PM (This post was last modified: 01-04-2018 04:20 PM by Martin Hepperle.)
Post: #3
RE: WP 34S - How do I use aGTO with stack registers?
Pauli,

thank you for the clarification - much appreciated. I have to look for some example applications of aGOTO.

Martin
Find all posts by this user
Quote this message in a reply
01-04-2018, 09:07 PM (This post was last modified: 01-04-2018 09:26 PM by Dieter.)
Post: #4
RE: WP 34S - How do I use aGTO with stack registers?
(01-04-2018 04:19 PM)Martin Hepperle Wrote:  I have to look for some example applications of aGOTO.

Maybe this helps a bit in understanding αGTO:

Are you familiar with the HP41? Here you have a GTO IND command that allows branching both to a numeric label as well as to an alpha label. This is possible because the data registers and the stack can hold both numeric and alpha contents. If the content of R00 is 23 a GTO IND 00 will jump to label 23. If R00 holds "ABC" the program branches to label "ABC".

The 34s is different in this regard. The data registers and the stack cannot store an alpha string. So if you want to branch indirectly to label "ABC" you cannot store "ABC" in R00 and do a GTO–>00. On the 34s, GTO–> allows branching to numeric labels, but not to alpha labels.

But there is a workaround. You can tell the 34s to interpret a number in a data/stack register as an alpha string. This conversion between a string and its numeric equivalent can be done with the αSTO command. Type "ABC" in alpha mode and do an αSTO X (simply press f STO) and you'll see the corresponding code in X. This code is 4276803.

If you now program an αGTO X this is essentially the same as a GTO IND X on the HP41 with "ABC" in the X-register. The essential difference is that the HP41 has the alpha string in X while on the 34s it's the alpha code of that string. By using αGTO X instead of GTO–>X you tell the 34s not to jump to label 4276803 (which does not exist anyway) but to branch to the alpha equivalent "ABC".

As Pauli noted, the code is base 256. So for label "ABC" which has the character codes 65, 66 and 67 this means the alpha code is 65·256² + 66·256 + 67 = 4276803.

So the whole thing is not very complicated. αGTO simply is a GTO IND or GTO–> for alpha labels. It tells the calculator not to jump to the label with that number but to the label with that alpha code. In other words: if 65 is stored in R00, a GTO–>00 will jump to label 65 while αGTO 00 will jump to label "A".

Now it should be clear why αGTO with a code of 101234 will not work: the latter is 001 139 114 in base 256. OK, "114" is an "r", but the other two...? At least you can be quite sure not to have a label with that name on your 34s. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
01-04-2018, 10:43 PM
Post: #5
RE: WP 34S - How do I use aGTO with stack registers?
In real mode, the conversion is *much* more complicated than just base 256.


Pauli
Find all posts by this user
Quote this message in a reply
01-04-2018, 10:53 PM
Post: #6
RE: WP 34S - How do I use aGTO with stack registers?
(01-04-2018 09:07 PM)Dieter Wrote:  Maybe this helps a bit in understanding αGTO...

Thanks for the extended explanation Dieter, I never understood how this works.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
01-05-2018, 09:15 AM
Post: #7
RE: WP 34S - How do I use aGTO with stack registers?
Dieter,

thank you very much for your excellent explanation.
I had not seen the necessity for using aSTO to encode the label name.
I had thought I need to put an ASCII code (101='e') into the register and per description the first 3 characters of this integer number would define the label to jump to. That's why I also tested with 101234. And as it worked with 101 and the single letter 'e' (I was not looking at multi-character labels) I thought I was on the right track.

Only the last case (my second '3)' which should have been a '4)') did not work for me:
Quote:3) Direct addressing via a stack register
If I have 101 in RX and "aGTO .X", I would expect the same outcome, but I receive "No such Label".
I don't have my WP34s here at hand to try now.

Martin
Find all posts by this user
Quote this message in a reply
01-05-2018, 09:40 PM (This post was last modified: 01-05-2018 09:49 PM by Dieter.)
Post: #8
RE: WP 34S - How do I use aGTO with stack registers?
(01-05-2018 09:15 AM)Martin Hepperle Wrote:  Only the last case (my second '3)' which should have been a '4)') did not work for me:
Quote:3) Direct addressing via a stack register
If I have 101 in RX and "aGTO .X", I would expect the same outcome, but I receive "No such Label".
I don't have my WP34s here at hand to try now.

Well, over here it works. At least on the emulator. ;-)
I placed a LBL"e" somewhere in the code, positioned the program somewhere else, and then 101 aGTO X jumped right to that label again.

Please also note there is a difference between LBL A and LBL"A". And there is no need to press "." for the stack registers. Simply press aGTO Z or aGTO T. OK, "X" is on the key with the decimal point. The official stack prefix is ENTER which displays an "s".

Dieter
Find all posts by this user
Quote this message in a reply
01-06-2018, 08:50 PM
Post: #9
RE: WP 34S - How do I use aGTO with stack registers?
(12-13-2017 11:31 PM)Paul Dale Wrote:  The encoding isn't decimal, it is base 256. Even entering characters in base 256 is not a guarantee anything will work. In real mode, it is pretty much guaranteed that it won't due to the formatting of numbers. In integer mode there is a chance.

Hm – I tried several examples on the emulator (3.3 3840) and aGTO worked every time. In real mode, after entering a manually calculated code. You say that most probably this should not work. So what am I doing wrong ?-)

(01-04-2018 10:43 PM)Paul Dale Wrote:  In real mode, the conversion is *much* more complicated than just base 256.

Could you say a bit more about this?

Dieter
Find all posts by this user
Quote this message in a reply
01-07-2018, 06:45 AM
Post: #10
RE: WP 34S - How do I use aGTO with stack registers?
I think I might have been mistaken, it is too many years since I wrote the alpha code.

Six character strings are stored fine in reals in base 256. In integer mode the maximum length depends on the word size and can be as high as eight.


Pauli
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: