how can i obtain the current values of registers like accumulator,B,stack pointer,PSW,DPTR,etc in C?? i am currently working on a trainer/development kit for 8051..One of the commands to be executed is R<CR> Once this command is executed,the values of all the registers like A,B,SP,PSW,DPH,DPL,R0,R1,R7 should be displayed on screen...how do i retrieve these register values in C?
"(almost certainly) will impact..."
ok. take a typically statement of "x=REGISTER_Y;", for the 40+ registers on a typical 8051, tell us how many of them will CERTAINLY be impacted by that read statement and how many of them will NOT CERTAINLY be impacted by that read statement.
since these registers are in the memory,cant i just keep a pointer to these locations and read the values from those locations??
The specific registers you mentioned were:
"A,B,SP,PSW,DPH,DPL,R0,R1,R7"
They are not all together in one single, contiguous block of memory; They aren'y even in the same 8051 address spaces.
- so you can't have just 1 pointer.
It sounds like what you're actually trying to do is to make a Debug Monitor?
Rather than re-invent the wheel, why not use one of the existing open-source solutions?
eg, www.pjrc.com/.../paulmon2.html
Or, at least, study it to see how this stuff is done...
well i meant a separate pointer for each register,but i guess since these SFRs are directly accessible, something like x=ACC should work..but this doesn't work for PC..how can i retrieve values of PCH and PCL?
But, again, why re-invent the wheel?
Why not, at least, look at existing solution to see how they do this?
But accessing PC - what PC? Your program will get the PC value of the code that retrieves the PC, since that is where the processor will always be when you try to read out PC.
That was one reason why I said you should consider handling all this in an ISR. Then the ISR code can check what return address the ISR will use - that is the PC of the program that was running when the ISR picked up the serial character.
but this doesn't work for PC..how can i retrieve values of PCH and PCL?
because PC is one of those registers that ARE impacted by the current code being executed.
the likely solution is to push the PC, execute your code to pop the PC, and make adjustments to it there.
something like x=ACC should work.
Simply by expressing that belief, you've just demonstrated how haven't got one bit closer to understanding what the real problem is than when you started this thread.
No, that will not "work", for any meaningful interpretation of that word. Sure, you'll get what was in the accumulator as you executed that instruction --- but that will rather certainly not be what you actually wanted to get.
You're on the wrong path, and people have been telling you that --- yet instead of turning back or at least slowing down, you're accelerating. Do you really think that's a sensible use of anyone's time?
cant i just keep a pointer to these locations and read the values from those locations
No, you can't. And if you had anywhere near the skills it takes to have a remote chance at doing what you're trying to do, you wouldn't need to be told this very basic fact about the '51 architecture.
"Do you really think that's a sensible use of anyone's time?"
hi, smartie, rather than wasting everyone's time on how this will not work, why don't you put down on a piece of paper an approach that will work?
be constructive and show us how smart you really are.
It's already done and known as a Debug Monitor.
Most commercial paid-for and open-source are available.
hi, smartie, rather than commenting on peoples replies be constructive and show us how smart you really are.
"Most" ??
I have no idea why I wrote that!
this appear out of synch in the thread it is a reoply to RE: pedantrt failure Ashley Madison "Do you really think that's a sensible use of anyone's time?"
hi, smartie, rather than commenting on peoples replies be constructive and show us how smart you really are
sorry Andy, if you thought it directed at you
Erik
"hi, smartie ..."
"be constructive and show us ..."
New clues, thank you!
If it walks like a duck and quacks like a duck, it could be a "qili" / "millwood" manifesting itself by a different name. It has been the case that if you totally ignore it, it will go away (well, on most occasions it's forced to leave by cognizant forum admin folk banning it into obscurity), but in one case I know of, ignoring the malfeasant was equally successful, although it did take some time for legitimate posters (and the malfeasant) to catch on.