Prior Page     Next Page     This Chapter    Prior Chapter    Next Chapter





Test and Jump Operations

The test instruction is one of the most difficult to understand because so much is packed into one small instruction. This is reflected in the comparative complexity of its definition. But still, it is a very simple operation

First let's examine the unconditional tests. A jump occurs if any bit in the ccm field of the instruction is matched by a bit in the CCr. Remember every operation that sets the CCr will set a single bit and reset all the others. So there is always one bit true in the CCr. If the ccm field of the instruction is 0xf, then any bit in the CCr will cause a jump; but one bit in the CCr must be on, so a ccm field of 0xf in the instruction creates an unconditional jump instruction. On the other hand if the ccm field of the instruction is 0x0, the no bit in the CCr can cause a jump, so the jump can never happen.

Conditional jumps use the ccm values between 0x0 and 0xf. If the ccm field of the instruction is 0x4 and last instruction was a add instruction that produced an negative number as a result then the CCr field will also be 0x4, thus a jump will occur. In fact it will only occur if the CCr field is 0x4, since there is never more than one bit set in the CCr. Thus a ccm of 0x4 is a conditional jump: jump if the last result was negative.

Likewise a ccm of 0xb causes a conditional jump: jump if the last result was non-zero. Note the jump occurs if the add produced any of the following: an overflow (CCr value of 8), a positive (CCr value of 2), or a zero (CCr value of 1). The total of the values of the conditions we want to check is 11 so the ccm should be made 0xb. Using the same logic a ccm of 0x3 is another conditional jump: jump if the last result was zero or positive.

Using this idea one can produce a conditional jump on any combination of conditions.

When a jump takes place, two things are done, First the Next register is copied into the Jump register, Jr (or if you prefer R15), the last general purpose register. Don't put data in R15 if you don't want it destroyed by the next TST instruction that branches.

The Next register contains the address of the next instruction to be executed, so it reflects the address after the jump instruction. It is this address that will be put into the Jr. It is where the program just `came-from', or where the CPU used to be executing. This is handy if you ever want the program to go back there.

Second, the Nr is replaced by the effective address computed for the jump instruction. This means that the next time the CPU goes to look for an instruction it will start executing at this address.

One more useful effect of the TST instruction is that with a ccm of 0, it stores Nr into ir[15] and doesn't jump. Normally when the TST instruction fails to jump ir[15] is unchanged. But a TST with a ccm of 0 stores the Nr in Jr (ir[15]) anyway.

The JSJ instruction, Jump save Jr, allows unconditional jumps without setting the Jr register. This is useful for returning from procedures, when one is using a register to return and you don't want the program to modify R15.








Prior Page     Next Page     This Chapter    Prior Chapter    Next Chapter


Copyright © 1995 R. Uzgalis. All rights reserved.
Contact: buz@cs.aukuni.ac.nz