0
*Error: value xxx is out of range, valid values are between -128 and 127.

I've been having this error in all my code.

The instruction jr cc, label explains this:

Note that the relative jump has a limited range of [-128, 127] from the address of the first byte of the instruction following the JR instruction.

I tried putting the instruction nop after jr but still got this error.

Maybe it is that I don't understand well how this works. If someone could explain me more (or give examples) it would be great. Thanks

thor
  • 21,418
  • 31
  • 87
  • 173
Albert
  • 1
  • 1
    Your jump target is too far. Reverse the conditional jump and use that to skip over a longer range unconditional jump. – Jester Mar 28 '16 at 14:43
  • 1
    I take it this is a Z80-compatible architecture? If so try `JP` instead of `JR` for an unlimited branch range, at the expense of an extra byte. – doynax Mar 28 '16 at 17:20

1 Answers1

0

Out of range problem can be solved by changing the relative jump (jr) to an absolute jump (jp).

Jump relative (JR) instructions allow easier code relocation because the jump is relative to the current program counter. For example, RAM functions are usually written in assembly and are relocated to RAM from flash. A jump (JP) instruction would not work in this case because the jump would be to a flash location and not the intended RAM location. Using JR instead of JP will jump to the intended RAM location.

Ihdina
  • 950
  • 6
  • 21