don't optimize my assembler code!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

don't optimize my assembler code!

435 Views
strawbot
Contributor II

I have a function which is trying to figure out where it is in memory and calculate the offset from where it was compiled so that it can bootstrap itself properly. I have added this assembly code to the startup C function with the simple goal of calculating the offset between compiled location and runtime location:

__here__:

   lea    -2(PC), a1    // get running address of label

   lea    __here__, a0  // get compiled address of label

   sub    a0, a1        // get relative offset

The first instruction gets the runtime address. The second instruction gets the compile time address. The third instruction calculates the offset. If the code is run where it is compiled, the offset will be zero. If it is anywhere else, then the offset will not be zero. What happens when I compile the code is that the second instruction gets compiled as a pc-relative instruction so that it is like the first instruction instead of compiling as an absolute addressing mode instruction as I requested! Optimize my C but don't optimize my assembler! How can I get the compiler to compile absolute addressing mode instructions when I ask it to? Optionally, is there another way of figuring out the offset between where my code was compiled for and where it is running? Thanks.

Labels (1)
0 Kudos
1 Reply

281 Views
strawbot
Contributor II

Nothing like answering your own question!

 

As it turns out, the only way to get the code to compile as I wanted it to, was to put it in a separate assembler file and then call the code from the original file. Not satisfying but it works.

0 Kudos