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?
"how do i retrieve these register values in C?"
the approach will depend on what kind of registers you are trying to read.
something like x=DPH; should work, for registers that are not impacted by the statement itself - look at the disassembly for sure.
for registers whose value will be impacted by the statement (PC for example), you may have to do manual adjustments.
Because the 'C' (almost certainly) will impact the register values, you should consider whether doing this in 'C' is really a good idea...
"Because the 'C' (almost certainly) will impact the register values,"
it depends on the particular registers to be read. they are not always impacted.
"Because the 'C' (almost certainly) will impact the register values, "
the right sentence is:
Because the 'C' (almost certainly) can impact the register values. C doesn't always impact the register values.
The tough part is to have a program debug itself.
So it wouldn't really be meaningful to have a main loop that detects a 'R' and then dumps the registers - it would not dump the register values when you are inside any of your algorithms, but instead dump the register values while dumping the register values.
One thing to consider is to have an ISR that picks up characters from the serial port, and is using a different register bank. It could dump a number of registers from the main register bank. For stack pointer, it would know how much data that has been pushed on the stack.
But in the end, dumping of register values is only meaningful if reasonably well hidden from the main program.
View all questions in Keil forum