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?

m.Alin
10.9k20 gold badges66 silver badges90 bronze badges
asked Oct 29, 2014 at 14:20
\$\endgroup\$
2
  • \$\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\$ Commented Oct 29, 2014 at 14:29
  • 1
    \$\begingroup\$ Also, you should never ever ever "goto" a function, or "goto" anywhere outside your current function. \$\endgroup\$ Commented Oct 29, 2014 at 14:31

2 Answers 2

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.

answered Oct 29, 2014 at 14:50
\$\endgroup\$
4
  • \$\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\$ Commented 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\$ Commented 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\$ Commented Oct 31, 2014 at 4:56
  • \$\begingroup\$ @jaspher I'm not experienced in assembly. You should ask a new question regarding that. \$\endgroup\$ Commented Oct 31, 2014 at 7:14
-1
\$\begingroup\$

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

answered Oct 30, 2014 at 0:28
\$\endgroup\$
1
  • 2
    \$\begingroup\$ This doesn't seem to answer the question. Please add further explanation. \$\endgroup\$ Commented Oct 30, 2014 at 0:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.