473,657 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I save & restore the program counter ?

3 New Member
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 5536
D_C
293 Contributor
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 Recognized Expert Moderator Expert
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
kiarash
3 New Member
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 Recognized Expert Moderator Expert
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 Contributor
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
3499
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 database for this application, but I have desired DB2 backup (by db2 backup db command). Can I do redirected restore (SET TABLESPACE CONTAINERS ....) only when instance is created & cataloged , I am under the impression that redirected restore is...
27
3824
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 failed assertions for assertions that at first thought ought to hold, but that's not important.) At the end is a full program containing the above seemingly
14
5923
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 because of this, so I hope some of you gurus can enlighten me with this :) In what circumstances can the "&" in the source code be involuntary changed to "&" by a browser when or other software, when editing and uploading the file to the web...
1
3034
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 in any phase (any step) and to be able to continue later. My idea was to create several pages as steps (no, wizard control is not suitable for several reasons) and to allow users to save any step to the database, that is, a ViewState of the...
2
2224
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
6344
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 place the values on a new line. ======================================================================= #include <stdio.h> #include <conio.h> int main(void)
14
3436
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 program can save all running data to a file when I want it to stop, and can reload the data and continue to run from where it stops when the computer is free ?
19
3096
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 Nordrassil-Horde Draenor-Alliance Nordrassil-Alliance Nordrassil-Neutral Draenor-Horde
0
1256
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 they click submit I want to save their postback data (i.e., which checkboxes are checked, which radio buttons are pushed and what's typed into the textboxes). Then later I want another user to be able to view one of these forms and elect to...
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.