JMP

Instruction: Jump to address.

JMP < # > Address

  • Address (s-field) is the register or a 9-bit literal whose value is the address to jump to.

Opcode Table:

–INSTR–  ZCRI  –CON–  –DEST–      –SRC–

Z Result

C Result

Result

Clocks

 010111    000i     1111      ---------    sssssssss

Result = 0

Not Written

4

Concise Truth Table:

In

Out

Destination1

Source

Z

C

Effects

Destination2

Z

C3

$----_----; -

$----_----; -

-

-

wr wz wc

31:9 unchanged, 8:0 = PC+1

0

1

1 Destination is normally ignored for typical JMP usage, however if the WR effect is given, the JMP instruction becomes a JMPRET instruction and Destination's s-field (lowest 9 bits) are overwritten with the return address (PC+1).
2 Destination is not written unless the WR effect is given.
3 The C flag is set (1) unless PC+1 equals 0; very unlikely since it would require the JMP to be executed from the top of cog RAM ($1FF; special purpose register VSCL).

Explanation

JMP sets the Program Counter (PC) to Address causing execution to jump to that location in Cog RAM. JMP is closely related to the CALL, JMPRET, and RET commands; in fact, they are all the same opcode but with different r-field and i-field values and varying assembler-driven and user-driven d-field and s-field values.

Conditional Jumps

Conditional jumps, and conditional execution of any instruction, is achieved by preceding the instruction with a condition in the form: IF_x. See Conditions (IF_x) for more information.

The Here Symbol '$'

The 'Here' Symbol, $, represents the current address. During development and debugging, the Here Symbol '$' is often used in the JMP instruction's Address field (i.e., JMP #$) to cause the cog to endlessly loop in place. It may also be used as a relative jump back or forward a number of instructions, for example:

Toggle    mov    dira, Pin    'Set I/O pin to output
          xor    outa, Pin    'Toggle I/O pin's state
          jmp    #$-1         'Loop back endlessly 

The last instruction, JMP #$-1, causes execution to jump back to the second-to-last instruction (i.e., 'here' minus 1).

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.