This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Printing out what's at a specific address

Need to be clearer. I cannot interfere with the customers' routines. Therefore, I can't 'break' in and print out register contents.
So how do I say, "OK, Printf: print out what's at this address. " I tried passing R1 to PrintF. Unless I call is an unsigned integer, it doesn't help. And then it thinks it's a VARIABLE named R1, not the specific register.
I tried @R1. Nothing there either.
Is there a special symbol that says, "Look, this is an internal register. I want you to print the contents of it: e.g., #R1, *R1, %R1.
Thanks, I need specifics.

Parents
  • "So how do I say, "OK, Printf: print out what's at this address. "

    Create a pointer to that address and dereference it.

    "Look, this is an internal register. I want you to print the contents of it:"

    You're unlikely to learn anything useful from using printf() to output the contents of the 8051 registers. What are you trying to achieve?

Reply
  • "So how do I say, "OK, Printf: print out what's at this address. "

    Create a pointer to that address and dereference it.

    "Look, this is an internal register. I want you to print the contents of it:"

    You're unlikely to learn anything useful from using printf() to output the contents of the 8051 registers. What are you trying to achieve?

Children
  • Ahhh, I think you have it. Could you give me an example of "Creating a pointer and dereferencing it"? I'm afraid the verb 'dereference' isn't in my vocabulary.
    Thanks.

  • I cannot interfere with the customers' routines. ... So how do I say, "OK, Printf: print out what's at this address. " I tried passing R1 to PrintF.
    If you can not "interfere with routines" the value of r1 will be totally meaningless.

    Erik

  • I suspect that what he means when he says to make a pointer and dereference it is that you should do something like:

    unsigned char data *regptr;
    regptr = 0x01;
    printf("R1: %x\n",*regptr);

    In this case, when you throw the * in front of the pointer in the call to printf, you are "dereferencing" it which basically is a fancy way of saying "tell the compiler to get whatever is AT that address instead of just the actual address itself."

    I must admit, however, that I have the same concern as the others on this board--namely, that this exercise will not yield the results you expect unless you provide some more motivation for what you're doing. You say you can't break execution to look at value, but you're willing to use a printf. A call to printf is going to insert possibly hundreds of instructions in the execution stream wherever you call it and that will CERTAINLY dramatically interfere with your customer's code.

    Your questions also reveal a general lack of familiarity with both the 8051 AND C programming in general which is going to make this a difficult problem indeed unless you throw these guys a bone so they can help you out more effectively.

  • Not true that the 'registers' contents will be totally meaningless' by the time I get to Printf. I've already single stepped through the disassembly code, and the only Register whose contents change in MY Printf, is Reg. 7.
    I am checking out a routine which uses registers to move external data around, and want to verify for the customer that the registers are doing what I claim they are doing.
    I've only been throwing code for 35 years, from the days of the UNIVAC 1004 with 80 bytes (not KByte, not MBytes) and the PDP-11 with DEC's wonderful Macro-11 assembly code, so the oneupsmanship/ganging-up remarks don't mean much. But it would seem that Keil employees, if such you are, would be more civil. If you're just ordinary engineers, I understand. Civility isn't a pre-requisite for such professions, unfortunately. So cut and slice away!!! I've got what I needed. Great way to encourage use of this 'forum'.

  • Once again we have a thread "it is no business of yours what I am doing, just answer my question".

    Ever so often, someone believe that "switching to micros' is nothing (as indicated by the previous experience the poster list) and "just answer" is impossible since the question is asked from the perspective of a non-micro.

    The techniques and approaches in the micro world are very different from the techniques used in e.g. the VAX or PC world.

    For that very reason the questions "why do you want to do this" are by no means an offense but rateher a means of honing in on what the "real" problem is.

    And - once again someone got offended by our attempts to help - so be it.

    Erik

  • None of the users who have been "ganging-up" on you are Keil employees. Just wanted to point that out, since I wouldn't want to malign their reputation in this whole discourse.

    Also, while I appreciate that you've been "throwing code" for quite some time, it's clear that said code thrown was not written in C. People need to ask legitimate questions about what you're doing when you talk about using printf() without yet telling us whether something's connected to a serial port and if so, what. Otherwise, printf might not do anything at all, even if my pointer example was the code you were looking for.

  • "I've only been throwing code for 35 years"

    and yet you still don't know what "dereference" means in the context of a pointer?!