Difference between revisions of "Branch"
Line 12: | Line 12: | ||
The opcode format breaks down as follows. | The opcode format breaks down as follows. | ||
− | Format - Decle #1 Format - | + | Format - Decle #1 Format - Word #2 (Unknown if all 16 bits are significant) |
0000:0010:00de:nccc aaaa:aaaa:aaaa:aaaa<br/> | 0000:0010:00de:nccc aaaa:aaaa:aaaa:aaaa<br/> | ||
where:<br/> | where:<br/> |
Revision as of 23:50, 11 January 2005
Instruction Name | Branch |
Mnemonics | B/BC/BOV/BPL BEQ/BLT/BLE/BUSC NOPP/BNC/BNOV/BMI BNEQ/BGE/BGT/BESC BEXT |
CP1610 Clock Cycles | 7 or 9 |
Interruptible | Yes |
Opcode Range | $0200-$023F |
The Branch family of instructions is similar to the Jump family of instructions in that Branch instructions are also represented as any of several different possible mnemonics, depending on the flags indicated in the opcode. The number of clock cycles used also depends on whether the branch is taken or not. If the condition is tests true, and the branch occurs, then the opcode will use 9 CP1610 clock cycles. If the condition tests false, then the branch is ignored and the opcode will use 7 CP1610 clock cycles. Note that the Unconditional Branch (B) always branches so it always uses 9 cycles, and the No Operation Branch (NOPP) never branches, so it always uses 7 cycles
The opcode format breaks down as follows.
Format - Decle #1 Format - Word #2 (Unknown if all 16 bits are significant) 0000:0010:00de:nccc aaaa:aaaa:aaaa:aaaa
where:
d indicates the direction of the branch such that: d == 0 indicates to branch in the forward direction d == 1 indicates to branch in the reverse direction
e indicates to branch on an external condition such that if e == 0, then: nccc == 0000 branch unconditionally (B) nccc == 0001 branch if Carry Flag is set (BC) nccc == 0010 branch if Overflow Flag is set (BOV) nccc == 0011 branch if Sign Flag is clear (BPL) nccc == 0100 branch if Zero Flag is set (BEQ) nccc == 0101 branch if Sign Flag != Overflow Flag (BLT) nccc == 0110 branch if either Zero Flag is set or if Sign Flag != Overflow Flag (BLE) nccc == 0111 branch if Sign Flag != Carry Flag (BUSC) nccc == 1000 do not branch unconditionally (NOPP) nccc == 1001 do not branch if Carry Flag is set (BNC) nccc == 1010 do not branch if Overflow Flag is set (BNOV) nccc == 1011 do not branch if Sign Flag is clear (BMI) nccc == 1100 do not branch if Zero Flag is set (BNEQ) nccc == 1101 do not branch if Sign Flag != Overflow Flag (BGE) nccc == 1110 do not branch if either Zero Flag is set or if Sign Flag != Overflow Flag (BGT) nccc == 1111 do not branch if Sign Flag != Carry Flag (BESC) otherwise if e == 1, then: nccc branch if this value matches the pins EBCA0-EBCA3 (BEXT)
aaaaaaaaaaaaaaaa indicates the amount of offset
Notice that the n parameter from above essentially just negates the internal conditions represented by ccc.
The branch destination is calculated from the address of the opcode immediately following the two-decle Branch instruction such that if the branch instruction is location at $1800 and the offset indicated by aaaaaaaaaaaaaaaa is $0007, then the destination in the forward direction would be $1809. It's a little trickier in the reverse direction because the CP1610 seems to add one to the offset if the branch is in the reverse direction, possibly because it is using ones complement arithmetic to calculate the offset. Either way, if the branch is in the reverse direction, then our example would result in a branch to location $17FA ($1800+2-7-1).
The Branch opcode family is often represented as many different mnemonics, to make life a little easier for the programmer. The mnemonic used to represent this opcode depends on the combination of the e, n, and ccc parameters mentioned above, according to the following chart.
Mnemonics To Parameters
Mnemonic | e | n | ccc |
---|---|---|---|
B | 0 | 0 | 000 |
BC | 0 | 0 | 001 |
BOV | 0 | 0 | 010 |
BPL | 0 | 0 | 011 |
BEQ or BZ | 0 | 0 | 100 |
BLT | 0 | 0 | 101 |
BLE | 0 | 0 | 110 |
BUSC | 0 | 0 | 111 |
NOPP | 0 | 1 | 000 |
BNC | 0 | 1 | 001 |
BNOV | 0 | 1 | 010 |
BMI | 0 | 1 | 011 |
BNEQ or BZ | 0 | 1 | 100 |
BGE | 0 | 1 | 101 |
BGT | 0 | 1 | 110 |
BESC | 0 | 1 | 111 |
BEXT | 1 | any value |