I want to put a function in an specific address of memory like PIC C Compiler (#org
).
I'm using MPLAB X, HI-TECH compiler and PIC18F4550.
In PIC C compiler:
#org 0x1000, 0x2000
void MyFunction()
{
}
//In other part of code I'll use: asm("goto 0x1000");
How to do this in MPLAB X with the HI-TECH compiler?
2 Answers 2
IIRC, you can set a function to an absolute address by using the "@" qualifier:
void MyFunction() @ 0x2A0
{
...
}
So the function MyFunction
will be placed at address 0x2A0 in Program Memory.
-
\$\begingroup\$ Thanks @m.Alin, I worked. I'd like to ask you how to use
int address = 0x20; **asm("goto "___mktstr(addr));**
but If I useasm("goto "___mktstr(0x20));
works. I want to usegoto
to go a specific address using addr variable, perhaps there is another option like goto_address(addr) in pic CCS compiler. Thank you. \$\endgroup\$788498– 7884982014年10月30日 06:34:35 +00:00Commented Oct 30, 2014 at 6:34 -
\$\begingroup\$ The ___mktstr(x) macro stringifies its argument.
___mktstr(0x20)
will return the string "0x20", but___mktstr(addr)
will return the string "addr". \$\endgroup\$m.Alin– m.Alin2014年10月30日 07:22:48 +00:00Commented Oct 30, 2014 at 7:22 -
\$\begingroup\$ Thanks, but I still couldn't find a way to GO to a variable address. It looks like asm() argument must be char constant. Is there another solution to jump to an address using goto? \$\endgroup\$788498– 7884982014年10月31日 04:56:05 +00:00Commented Oct 31, 2014 at 4:56
-
\$\begingroup\$ @jaspher I'm not experienced in assembly. You should ask a new question regarding that. \$\endgroup\$m.Alin– m.Alin2014年10月31日 07:14:54 +00:00Commented Oct 31, 2014 at 7:14
use the linker command file to set the address of .text portion of MyFunction
-
2\$\begingroup\$ This doesn't seem to answer the question. Please add further explanation. \$\endgroup\$2014年10月30日 00:47:25 +00:00Commented Oct 30, 2014 at 0:47
MyFunction
from assembly (maybe as_MyFunction
depending on compiler). \$\endgroup\$