James Newton says:Despite the fact that it is not documented here, any operation (add or sub, jmp PC+W, jmp W, mov, etc...) that modifies PC, other than JMP addr, will set bit 8 of the PC to zero. So you can only do relative or computed jumps into the first half page of each page. Just like calls.
SX Users Manual Rev. 3.1
42
© 2000 Scenix Semiconductor, Inc. All rights reserved.
www.scenix.com
Chapter 2 Architecture
Another way to achieve the same effect faster and with fewer instructions is to use the page
instruction to set the PA2:PA0 bits in the STATUS register:
page $600
;set page to 600h (PA2:PA0 = 011 binary)
jmp
$1E0
;jump to program memory address 7E0h
The page instruction sets the values of the PA2:PA0 bits without affecting other bits in the STATUS
register. It does this in just one clock cycle. You specify a 12-bit value in the instruction and the
assembler encodes the three high-order bits of the value into the instruction (and ignores the lower-
order bits). When you execute the instruction, it sets the PA2:PA0 bits in the STATUS register
accordingly.
Note that is necessary to set the PA2:PA0 bits prior to the jmp instruction only if they do not already
contain the desired page number. You can set them just once and then use any number of jmp
instructions as long as you stay within the same 512-word page in the program memory.
A JMP addr9 instruction takes two clock cycles in the compatible clocking mode (SX18/20/28AC
and SX18/20/28AC75 devices only) or three clock cycles in the turbo clocking mode. (For
information on clocking modes, see Section 4.2).
2.6.3
Jump Indirect and Jump Relative
Instead of using the JMP addr9 to specify an absolute jump destination, you can cause a jump by
modifying the PC register (file register address 02h), which holds the lower eight bits of the program
counter.
For example, to perform an indirect jump, you can move a new value from W to PC, as in the following
example:
mov
W,$0B
;load W with 8-bit jump address from file reg.
mov
$02,W
;load PC with new address (lower 8 bits only)
To perform an indirect relative jump (a jump of a certain number of memory locations forward or
backward from the next instruction), you can add W to PC or subtract W from PC, as in the following
example:
mov
W,#$04 ;load W with the immediate value 04h
add
$02,W
;increase PC by 4 (jump forward 5 instructions)
You can use an indirect jump to implement a multiple-branch conditional jump (for example, to jump
to one of four different routines based on a calculation result).
If you perform a jump by modifying the PC register, you can only jump to a location within the same
256-word segment in the program memory. This is because you can only modify the lower eight bits
of the program counter. To jump across a 256-word boundary, use the PAGE addr12 and JMP
addr9 instructions.
A jump performed by modifying the PC register with a mov or add instruction takes four clock
cycles in the compatible clocking mode (SX18/28/28AC and SX18/20/28AC75 devices only) or
three clock cycles in the turbo clocking mode.