Question

I'm trying to write a program for an arduino that variably calculates an absolute address and then jumps to it (this is part of a larger program with a larger purpose), however I am having a bit of trouble. Currently, I am doing something like the following:

  uint16_t v_pc;
  uint16_t jmpAddress;

  jmpAddress = 0x00cf;
  v_pc = 0x01;


  jmpAddress = calc_address(jmpAddress, v_pc);

  asm("jmp %0" :: "r" (jmpAddress)); 

where calc_address is:

uint16_t calc_address(uint16_t jmpAddress, uint16_t v_pc){
    return jmpAddress += v_pc;
}

However, when I try to link the program (i.e. avr-gcc -mmcu=atmega328p program.o -o program) it gives me the following error:

undefined reference to `r24'
collect2: error: ld returned 1 exit status

Is there maybe a better way I can implement this or could someone describe why this error might be occurring?

Thank you!

Was it helpful?

Solution

JMP doesn't take a register as operand. For indirect jump, you can use IJMP but that uses the Z register implicitly. As such, your inline asm should look more like:

asm("ijmp" :: "z" (jmpAddress)); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top