;redcode
;name BootProgramForThreadsV1
;author Skybuck Flying
; demonstrate the concept of a boot program for threads.
; each thread will jump to the instruction it should execute
; the jumps will happen in order of thread creation.
; the boot program makes it easy to mix the execution order of the
instructions of the threads for the desired result
; a interesting demonstration program is left as an exercise for the reader
jmp BootBegin
BootBegin
; spawn 7 additional thread for a total of 8 threads
spl 1
spl 1
spl 1
jmp >ThreadCounter
ThreadCounter dat $0, $1
Thread1JumpTo jmp Instruction1
Thread2JumpTo jmp Instruction1
Thread3JumpTo jmp Instruction1
Thread4JumpTo jmp Instruction3
Thread5JumpTo jmp Instruction8
Thread6JumpTo jmp Instruction8
Thread7JumpTo jmp Instruction8
Thread8JumpTo jmp Instruction8
BootEnd
Instruction1
add.ab #1, #0 ; show results for debug
jmp 0 ; first 3 threads on 1
Instruction2
add.ab #1, #0 ; show results for debug
jmp 0
Instruction3
add.ab #1, #0 ; show results for debug
jmp 0
Instruction4
add.ab #1, #0
jmp 0 ; fourth thread on 4
Instruction5
add.ab #1, #0
jmp 0
Instruction6
add.ab #1, #0
jmp 0
Instruction7
add.ab #1, #0
jmp 0
Instruction8
add.ab #1, #0
jmp 0 ; last 4 threads on 8