Knowledge Base

Although J is automatically applied to all memory reference and I/O instructions inside a MultiTrack task (unless you use NoJ:), there may be occasions when the automatic behaviour is not what you need. The BranchJ instructions gives you an open ended way of forcing exactly what you need to happen.

BranchJ works in a similar way to the other Branch instructions (Branch, BranchM, BranchR). It gives you an “n-way branch” depending on the value of J.

Example:

In this (really exciting! : -) version of our on/off light switch, the order of the outputs is reversed relative to the inputs, i.e. input 0 controls output 3, 1 controls 2, 2 controls 3 and 3 controls 0.

(Click here for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help (.chm) files)

        LaunchTask      Toggle,0
LaunchTask Toggle,1
LaunchTask Toggle,2
LaunchTask Toggle,3
RunTasksForever
Toggle:
WaitOnK 0
GoSub Reverse
iOn 0
WaitOnK 0
GoSub Reverse
iOff 0
GoTo Toggle

Reverse:
LoadI 3
BranchJ
Target J0
Target J1
Target J2
Target J3

J3:
DecI
J2:
DecI
J1:
DecI
J0:
Return
Exercise 1:

Analyze how the program works.

Exercise 2:

What happens if you change the iOn and iOff instructions with IasJ:On and IasJ:Off respectively?

Exercise 3:

Rewrite the Reverse subroutine for the following mapping, not using a chain of DecI instructions. Do use the BranchJ instruction.:

InputOutput
01
16
27
30