473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I save & restore the program counter ?

In a called function,I want to save the "program counter" , when program reached to a specified location ,& then return from the function .
In the next calling of this function , I want to restore "pc+1" to continue the process.

How can I do this?
Sep 19 '06 #1
5 5518
D_C
293 100+
Can you give an example of precisely what you want? It's not so clear to me. Besides, I'm not sure one can gain access to the program counter.

C++ files may also be relative. That is suppose you have a function that prints the memory location of an instruction, then returns. If you run the program a second time, you may not get the same value.
Sep 19 '06 #2
Banfa
9,065 Expert Mod 8TB
To get access to processor registers you normally need to drop into assembly code.

However the C/C++ standards do not define this, only some C/C++ compilers support it and all in propriatory ways.

For instance in MSVC I think (IIRC) that the sytanx is

Expand|Select|Wrap|Line Numbers
  1. void fn(void
  2. {
  3.     // Some C code here
  4.  
  5.     asm 
  6.     {
  7.         // we've dropped into assembler, assembly code here
  8.     }
  9.  
  10.     // More C code here
  11. }
  12.  
However you'd better be really sure you know what you are doing it you are going to mess directly with the pc.
Sep 20 '06 #3
Thanks for your reply,

I use IAR 4.4 for arm.
In this program I have a timer interrupt. I have a specified routine to be done in this sub routine.But every part should be done in one time,then the program should wait until next interrupt service routine call to continue.

I tried function pointer arrays & also switch-case routines.But these routines are not practical for me as they are very time consuming.

If I can save PC, in the next interrupt call I can continue the routine very quickly.
Isn't so?
Sep 20 '06 #4
Banfa
9,065 Expert Mod 8TB
If I can save PC, in the next interrupt call I can continue the routine very quickly.
Isn't so?
For the ARM platform I would definately expect you to have a way to write assembler instructions but it may require an assembler file (i.e. write 2 functions 1 to read the pc 1 to write it). You will need to check your toolset documentation.

What you propose to do may work, on the other hand it may cause everything to fall over in a big heap.
Sep 20 '06 #5
D_C
293 100+
In assembly, yes, this is do-able. Anytime an interrupt is called, it automatically pushes the registers and PC onto the stack. In order to pop the same information off of the stack, you should have an assembly command that "Returns from interrupt".

From the limited assembly programming I have done, RETI was the return from interrupt command, that I don't think I ever needed.
Sep 20 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Vikrant | last post by:
Friends, Due an application (old) install program problem, Under AIX I could only create DB2 instance, I could also catalog it. Its complex application and I am not expert in creating full...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as & to be valid. I don't have Firefox my self and don't wont to install it only...
1
by: Irene | last post by:
Hello all! I'm creating a web site in ASP.NET (VB.NET). One of the requirements was to allow users to create orders going through several steps. A must have is to have an option to save the work...
2
by: Aenima1891 | last post by:
write a program that replaces strings of blanks by the minimum number of blanks to space to the next tab stop. #include <stdio.h> #define TABSIZE 8 int main() { int counter, c;
17
by: Jonathan Pritchard | last post by:
I know this is a simple problem, but I've just included this in the title because it explains what my program tries to do. The following does not work, it for someone reason does not want to...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
19
by: pkirk25 | last post by:
I wonder if anyone has time to write a small example program based on this data or to critique my own effort? A file called Realm List.html contains the following data: Bladefist-Horde...
0
by: 1388-2/HB | last post by:
I have a page with a significant number of dynamically created radio buttons, checkboxes and textboxes. When a user is presented with this form and subsequently fills a bunch of stuff out, when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.