Jump to content
dgille

Using An Address Of A Label

Recommended Posts

Hello,

I need to redirect a program to another address after leaving an interrupt service routine. My plan is to adjust the stack pointer and write the correct address to the top of stack and then allow the return from interrupt instruction to execute.

I have not found a way to take the address of a label in BoostC. The web suggests the following ...

http://stackoverflow.com/questions/1777990...ress-of-a-label

int main (void)

{

int i=1;

void* the_label_pointer;

 

the_label:

 

the_label_pointer = &the_label;

 

if( i-- )

goto *the_label_pointer;

 

return 0;

}

 

BoostC does not allow the above syntax.

BoostC Optimizing C Compiler Version 6.96 (for PIC18 architecture)

 

To make matters worse, the "Hardware Stack" dialog box does not report anything but 00's and no TOS movement. If I add the following code to my program and trace it, the watch variable values do not match the values in the "File Registers" dialog box.

 

Are there ways to take the address of a label ?

What is the best way to work with the stack ?

How can I get the "Hardware Stack" dialog box working and matching the results from the "File Registers" dialog box and my own watched variables ?

 

I'm using a PIC 18F1330 with MPLAB 8.50 and ICD 3

 

Thanks in advance for you kind assistance,

D

non_viewable_stack_and_non_matching_vars_18F1330.zip

Share this post


Link to post
Share on other sites

C language does not support label addresses. Some compilers like GCC use non standard language extensions to support this feature but BoostC does not. You are the first person who asked about it.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Yes I understand that GCC uses "&&" and is non-standard.

The example I included was from a supposedly "normal" C compiler.

 

Can I get some guidance on the following:

I need to redirect a program to another address after leaving an interrupt service routine. My plan is to adjust the stack pointer and write the correct address to the top of stack and then allow the return from interrupt instruction to execute.

 

- How should write the source code so that I can take the address of a point (somewhere else in the code) to put it on the top of the stack ?

 

Thanks,

D

Share this post


Link to post
Share on other sites

The best approach would be to re-think the algorithm of the code so that it won't need and rely on such non standard tricks. If different algorithm is not an option place the code you want to execute at interrupt end into a function with fixed address and use this address to return to.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...