Jump Too Far

One very annoying error to encounter is the “jump too far”, what does it mean and how is it avoided ?

Error Description

This error is an artifact of the Cortex-M Thumb-1 Instruction Set Architecture which limits the Program Counter jumping further than 1024 locations from the current Program Counter Value and is limited to the Cortex-M0 architecture.

Solution

Split the code giving the error into another Word.

Example

This code snippet produced the “Jump too Far” (JTF) error. Thanks to Lief Koepsel for supplying it.

...
." Error in input (ASCII): " .  ok.
  false   ok.
 then  ok.
   then  ok.
       cr ." Tests: 0=> new pin 1=> High 2=> Low  3=> Blink once "  ok.
    begin  ok.
     ctotest  ok.
    until   ok.
   until  Jump too far  <----- JTF ERROR!!!
   ...

Stopping the error

This stopped the error, but isn’t the best solution because there is a better way which allows the full message.

...
." Error in input (ASCII): " .  ok.
  false   ok.
 then  ok.
   then  ok.
       cr ." Tests: "  ok.
    begin  ok.
     ctotest  ok.
    until   ok.
    ...

Solution

Split the “Tests” message off into a new Word like so

: tests-message cr ." Tests: 0=> new pin 1=> High 2=> Low  3=> Blink once " ;

...
." Error in input (ASCII): " .  ok.
  false   ok.
 then  ok.
   then  ok.
       tests-message
    begin  ok.
     ctotest  ok.
    until   ok.
   ...

Comment

A Forth program consists of lots of small Words, whereas a C program consists of a smaller number of larger words (subroutines).

Long Forth Words are usually the cause of the JTF error, and this is something I was guilty of when I started Forth. Everyone does it at first, especially if they have a C programming background.

Penality ?

Is there a penalty for extra Words ?

Nothing substantial. A switch to and from a Word (subroutine) is literally one call instruction and one return instruction.

The increase in testability, readability and maintainability makes the minor extra memory use worthwhile. In the above example the “tests-message” can be tested by itself right away (because Forth is interactive), the Word that calls “tests-message” doesn’t have to be run to test the message.

Furthermore all the ‘messages’ could be put in a separate “messages.fs” file for easy testing, maintenance and to keep the clutter down in the main Words. Having all the messages in the one file means you don’t have to Grep all the source to find them when a change is needed.

Messages need to be neat, aesthetic and to get the point across with capitals, exclamation marks and so on.

Easy message testing results in neater, more professional looking programs.