Difference between revisions of "Introducing the Instruction Set Part 3"

From Intellivision Wiki
Jump to: navigation, search
m (Introducing the Instruction Set Part 4 moved to Introducing the Instruction Set Part 4 Temp)
(No difference)

Revision as of 22:54, 9 October 2007

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.

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:

MnemonicDescription Cycles Size
B Branch to label 92 words
J Jump to label 123 words
JD Jump to label while disabling interrupts 123 words
JE Jump to label while enabling interrupts 123 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.

Conditional Branches

Signed Comparisons

Unsigned Comparisons

Sign/Zero Comparisons

If-Then and If-Then-Else

Looping

Function Calls

Simple Call/Return

Nested Call/Return

Passing Arguments via Return Address

Indirect Branches and Jump Tables

"It was a 'Jump to Conclusions' mat. You see, it would be this mat that you would put on the floor... and would have different conclusions written on it that you could jump to." -- Tom Smykowski, Office Space

Indirect Branching: "Jump Vectors"

Simple Jump Tables

Adding to the Program Counter

Wrapping Up

At this point, you may wish to view the parts of this tutorial:

Or, you can return to the Programming Tutorials index.