Introducing the Instruction Set Part 3

From Intellivision Wiki
Revision as of 12:54, 9 October 2007 by Mr z (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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:

MnemonicDescriptionCyclesSize
BBranch to label92 words
JJump to label123 words
JDJump to label while disabling interrupts123 words
JEJump to label while enabling interrupts123 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