1
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ I don't understand why you'd need to. You can reference the symbol MyFunction from assembly (maybe as _MyFunction depending on compiler). \$\endgroup\$ – Majenko Oct 29 '14 at 14:29
  • 1
    \$\begingroup\$ Also, you should never ever ever "goto" a function, or "goto" anywhere outside your current function. \$\endgroup\$ – Majenko Oct 29 '14 at 14:31
1
\$\begingroup\$

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.

|improve this answer|||||
\$\endgroup\$
  • \$\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 use asm("goto "___mktstr(0x20)); works. I want to use goto 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 Oct 30 '14 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 Oct 30 '14 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 Oct 31 '14 at 4:56
  • \$\begingroup\$ @jaspher I'm not experienced in assembly. You should ask a new question regarding that. \$\endgroup\$ – m.Alin Oct 31 '14 at 7:14
-1
\$\begingroup\$

use the linker command file to set the address of .text portion of MyFunction

|improve this answer|||||
\$\endgroup\$
  • 2
    \$\begingroup\$ This doesn't seem to answer the question. Please add further explanation. \$\endgroup\$ – Null Oct 30 '14 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.