BRANCH Command

benbaker7

Active member
Hi Folks. In working through the branch command p42, Pt 2, I seem to have a problem with the example. Bearing in mind that this is only an example, there seems to be no way that btn0 can ever light due to incrementing b1 as the first line in main. Only way I could solve the problem was to add 'Inc b1' between 'high bx' and 'GOTO main' in each btn label. I tested both the example and my 'solution' on the simulator (14M2) - only my solution worked as expected. Have I missed something, or is the example simply that - an example.
Thanks
Ben Baker
 

AllyCat

Senior Member
Hi,
.... only my solution worked as expected.
It depends what you expect :) , but you are correct that the example as written will never set B.0 (nor clear B.4) because of the structure and location of the INC in the program.

Note that the BRANCH .... command is very similar to the ON .... GOTO command which I find more intuitive and easier to use. In particular, the "fall through" is more obvious if an out-of-range value is used. Thus, the command ON b0 GOTO somewhere is perfectly valid, equivalent to IF b0 = 0 THEN GOTO somewhere , but a little faster. ;)

I don't know if it's "expected", but the following does work as intended : :)
Code:
reset1: let b1 = -1
low B.0
low B.1
low B.2
low B.3
main: inc b1
if b1 > 3 then reset1
branch b1,(btn0,btn1,btn2)
btn3: high B.3
goto main
btn0: high B.0
goto main
btn1: high B.1
goto main
btn2: high B.2
goto main
Cheers, Alan.
 

Aries

New Member
See also this thread from last year ...
 

benbaker7

Active member
To those who took the trouble to reply, thank you.
It does seem that the writer of the manual wanted to illustrate that location 0 is skipped in this case, with the first (led) activation being led 1.
It would have been nice if he had just said so! Perhaps he thought (I) was clever enough to read his mind. Guess I'm just a dummy.
Ben Baker
 
Top