jmp vs rjmp

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guyzz

I have done a little thinking about jmp vs rjmp (and i haven used search :oops: ).

It seems to me that rjmp is used for PIC (Position Independant Code) , just as back in my good oleee 6809 days.
"LEAX var,pcr" or BRA/LBRA.

At first it seemed unlocical to me that a ROM/FLASH system needed PIC , because i'd expect the linker to resolve the "Externals". But then i thought about libraries and their modules. And internal jumps in those , where nobody knows at what addr they would reside (be linked into).

So i guess my question is :
When do you use jmp ???

Only when jumping to vectors (reset & other stuff with a definite fixed addr) :?: :?:

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RJMP is Relative JUMP. You can jump +-2k words from rjmp position.
Instruction length is 1 word.

JMP is absolut jump. You can jump anywhere into 64k word program memory.
Instruction length is 2 word.

VFX.
http://www.vfx.hu

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RJMP takes less code space than JMP.

The compiler OUGHT to optimize this but might not. That is, if you specify a destination within the 2K range, it ought to automatically choose RJMP (even early 8051 assemblers did this).

The comiler OUGHT to tell you if your RJMP is out of range. So, if code space is tight, use RJMP. Let the compiler tell you about the jumps that are too far for RJMP and edit those to JMP. The result can be that the change in code will cause other RJMPs to go out of range, but the number of iterations should be quite small.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahhh i did notice the +- 2K words offset , but didnt think further.

So if you have 2K+ word machine then you might have to "Negate" the jump , as in a VAX where offset is +-127.

Meaning something like this :

(Label Negative: is more tha 2K words away)
if x >= 128 then goto Negative:
else blah blah ...

Would become (in 6809 , im still lerning avr asm)

The "Logical way"
cmp x,128
bge Negative:
blah blah ...

The "Negated way"
cmp x,128
bl Lxxx
jmp Negative:
Lxxx:
blah blah ....

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
then you might have to "Negate" the jump

Nope. This is not related to the direction - as direction indicator for relative jumps ("rjmp") as usual the MSBit of the distance value is used.

16-bit opcode for rjmp:
1100 + 12 bits for the jump distance. 1 bit used as direction flag, leaves 11 bits = +/- 2K words distance possible.

32-bit opcode for jmp:
1001 010x xxx 110x
16 x "x"
The 22 "x"s are the bits reserved for the absolute jump address (no +/- relative distance here).
With 22 bits you can address anything inside 4M words.

Let's hope for the next generation AVRs making full use of this option ... :)

[Edit] Okay, yes, code-wise your compare-and-negate-direction is correct. But this is a bit overly complicated for simple electronics.
a) decode opcode (1100 is relative jmp, we've hardwired that)
b) next bit "0" -> increment instruction pointer by whatever is in the next 11 bits
c) else (bit = "1") decrement ....

Andreas

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
"Negate" the jump

I wasn't clear here

I meant negate the condition of the jump , in order to jump "around" the
"full range" jmp.

I'd never do the offsetting my selve , i guess the assembler is better at that.

/Bingo