Introducing the Instruction Set Part 3
This segment of the tutorial introduces branches, particularly conditional branches and function calls. This is Part 4 of a series. If you haven't yes, you may wish to review at least Part 1 and Part 2, and possibly Part 3 as well.
Contents
Unconditional Branches and Jumps
Unconditional branches are branches that are always taken. Jump instructions do essentially the same thing. The following table lists the instructions:
Mnemonic | Description | Cycles | Size |
---|---|---|---|
B | Branch to label | 9 | 2 words |
J | Jump to label | 12 | 3 words |
JD | Jump to label while disabling interrupts | 12 | 3 words |
JE | Jump to label while enabling interrupts | 12 | 3 words |
As you can see, the primary difference between branches and jumps is that branches are smaller and faster. Branches encode their "target address," the address being jumped to, as a relative displacement to the current address. Jumps, on the other hand, store the actual address of the target. In most cases, especially in a 16-bit ROM, there are few reasons to use a J instruction, although the combination instructions, JD and JE can be useful.
There is also a pseudo-instruction, JR, that allows "jumping to a location held in a register." It is really a pseudonym for "MOVR Rx, R7". Because it is a MOVR instruction, it will modify the Sign Flag and Zero Flag, which may be confusing if you're not expecting it.