The program below includes an example of 'branching.' Branching in a program means that either some instructions or some other instructions are executed depending on a value (usually a bit) in memory (or, in most processors, in a register). Branch bits are often called flags. In the program below, the rightmost bit in latch A (at address 0000000000000001) is a flag and determines whether instr_4 or instr_5 is executed. Instr_4 copies the 'all 1's pattern' (1111111111111111) in latch C to latch B. Instr_5 copies the '1,0 pattern' (1010101010101010) from latch D to latch B. If latch A has value 1, then instr_5 is executed. If A has value 0, then instr_4 is executed. In the program below, A has value 1 so instr_5 is executed and B gets the '1,0 pattern.'Instr_3 does nothing but go to the next instruction because it copies no bits. Instr_3 has 0000000001000000 in latch (address) 0000000000001111, so, normally, instr_4, at address 0000000000010000, would be executed next. However, instr_2 copies the rightmost bit (1) from A into the fifth-from-rightmost bit of latch 0000000000001111 so that latch 0000000000001111 contains 0000000001010000 and instr_5, at address 0000000000010100, is executed after instr_3. The instructions are then executed in the following order: instr_2, instr_3, instr_5, instr_6. Notice that instr_4 is skipped.
Branching Program
label address data comment start 0000000000000000 0000000000100000 start 0000000000001000 A 0000000000000001 0000000000000001 flag(1 or 0)right bit B 0000000000000010 0000000000000000 value to change C 0000000000000011 1111111111111111 all 1's pattern D 0000000000000100 1010101010101010 1,0 pattern instr_2 0000000000001000 0000000000000001 from A 0000000000001001 0000000000001111 to next of instr_3 0000000000001010 0000000000010000 change this bit 0000000000001011 0000000000110100 to instr_3, rot.4 instr_3 0000000000001100 0000000000000000 doesn't matter 0000000000001101 0000000000000000 doesn't matter 0000000000001110 0000000000000000 copy NO bits 0000000000001111 0000000001000000 to instr_4 OR instr_5 instr_4 0000000000010000 0000000000000011 from C pattern 0000000000010001 0000000000000010 to B 0000000000010010 1111111111111111 copy all bits 0000000000010011 0000000001100000 to instr_6, no rot. instr_5 0000000000010100 0000000000000100 from D pattern 0000000000010101 0000000000000010 to B 0000000000010110 1111111111111111 copy all bits 0000000000010111 0000000001100000 to instr_6, no rot. instr_6 0000000000011000 0000000000000000 doesn't matter 0000000000011001 0000000000000000 doesn't matter 0000000000011010 0000000000000000 copy NO bits 0000000000011011 0000000001100000 go to this instructionThe result of running the program above is shown below. Notice that B now holds 1010101010101010 and that address 0000000000001111 now holds 0000000001010000 instead of 0000000001000000. Italics show to where and from where values have been copied.
After Branching Program Has Run
label address data comment start 0000000000000000 0000000001100000 start 0000000000001000 A 0000000000000001 0000000000000001 flag(1 or 0)right bit B 0000000000000010 1010101010101010 value to change C 0000000000000011 1111111111111111 all 1's pattern D 0000000000000100 1010101010101010 1,0 pattern instr_2 0000000000001000 0000000000000001 from A 0000000000001001 0000000000001111 to next of instr_3 0000000000001010 0000000000010000 change this bit 0000000000001011 0000000000110100 to instr_3, rot.4 instr_3 0000000000001100 0000000000000000 doesn't matter 0000000000001101 0000000000000000 doesn't matter 0000000000001110 0000000000000000 copy NO bits 0000000000001111 0000000001010000 to instr_4 OR instr_5 instr_4 0000000000010000 0000000000000011 from C pattern 0000000000010001 0000000000000010 to B 0000000000010010 1111111111111111 copy all bits 0000000000010011 0000000001100000 to instr_6, no rot. instr_5 0000000000010100 0000000000000100 from D pattern 0000000000010101 0000000000000010 to B 0000000000010110 1111111111111111 copy all bits 0000000000010111 0000000001100000 to instr_6, no rot. instr_6 0000000000011000 0000000000000000 doesn't matter 0000000000011001 0000000000000000 doesn't matter 0000000000011010 0000000000000000 copy NO bits 0000000000011011 0000000001100000 go to this instruction
Page 36
Page 35 . . . Page 1 . . . Page 37