Understanding RJMP instruction

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


I would like to understand what is happening in the disassembly of a very simple code.

From the manual I understand that RJMP instruction has  4 hexadecimal numbers, C kkkk kkkk kkkk where k is a 12 signed integer. The instruction does PC = PC + k + 1.

 

For the next C code:

 

int main( void )

{

  int counter = 0;

  while(counter < 5){

    ++(counter);

  }

  return 0;

}

 

The disassembly is:

I understand that in line 000076 CFFA is the C and FFA is the 12 signed number, which translates to a -6. Then I expect PC = 000076 + (-6) + 1 = 000071. But as you can see at the end of line 000076 it says it will jump to 00006C, which it does during the debugging. But I don't understand why.

 

If it helps I am using IAR workbench, and the device is an atmega328P.

This topic has a solution.
Last Edited: Fri. Sep 18, 2020 - 11:07 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Address changes by Words not Bytes

David

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

Note: when the RJMP instruction is executed the PC points to the next instruction, ie. PC = 0x0078

subtract 12 (0x0c) from the PC and you get PC = 0x006C

 

Jim

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Thank you, I didn't think of that.