How can I jump relative to the PC using the gnu assembler for AVR?

后端 未结 2 919
后悔当初
后悔当初 2021-01-15 00:41

I have a binary file that I\'ve disassembled using avr-objcopy. The interrupt vector table looks like:

00000000 :
    ; VECTOR TABLE
   0:   13 c0           rjmp         


        
相关标签:
2条回答
  • 2021-01-15 00:53

    I found the answer!

    I was assembling but not linking. So the assembler was filling in all relative jumps/calls/branches with .+0.

    To fix this I needed to create a custom linker script I called linker.x which contains the following:

    SECTIONS
    {
      . = 0x0;
      .text : { *(.text) }
    }
    

    This tells the linker to start the .text section at address 0.

    Then I could link the code using:

    $ avr-ld -mavr4 -Tlinker.x a.out -o output.o
    

    After linking using the above command all of the .+0's were filled in with their correct values!

    The reason for this, is because until the linking stage, as/gcc don't know what else is going to be included in the binary file. It is the linker that takes all the individual object files and combines them into one. So if the linker stage is never run, there is no way to fill in the relative jumps with absolute jumps.

    AVR's assembler does the both assembling and linking. But the gnu assembler is more generic and so you need to link separately.

    0 讨论(0)
  • 2021-01-15 00:57

    I'm assuming that rjmp PC+2 doesnt work in avr-as ? That's how I'd do it in AVR Studio...

    0 讨论(0)
提交回复
热议问题