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

Memory dump

I just wrote a simple memory dump routine declared as follows:

void hexdump(U16 start_address, U16 count, bit code_memory);

The idea is to use <code_memory> to select between dumping from XRAM (=0) or code memory (=1).

Inside the routine two pointers are declared:

U8 xdata *xram_pointer;
U8 code *code_pointer;

And initialized (could be done in one shot):

xram_pointer = (U8 xdata *) start_address;
code_pointer = (U8 code *) start_address;

With this in place the output look decides which pointer to use based on <code_memory>, builds the strings using sprintf, and outputs with printf one line at a time.

A couple of questions:

1- "U16 start_address" is this the best way to declare this argument?

2- Is there a way to do this using a single pointer (or "start_address") within the function?

Maybe, define a void pointer and then cast it into either XRAM or code?

Thanks.

Parents
  • How do you propose to let a function like printf know whether to go to xdata or code space?

    That's exactly what's generic about generic pointers: they contain an extra byte to signal this difference. You may want to think of a generic pointer as a data type like

    struct generic_pointer {
        U8  memory_class;
        union {
          void code  *c;
          void xdata *x;
          void data  *d;
          void idata *i;
        } ptr;
    };
    which was versatile enough that it was implemented as an intrinsic data type supported by the compiler and linker.

    printf(" %s", generic_pointer);

    won't work,


    Says who?

    The "address" to your function should almost certainly be a generic pointer. That's always better than abusing an int as a pointer, and particularly better than using arguments to specify one thing.

    And BTW: worrying about efficiency while in the same sentence proposing to use printf() to print a string seems considerably self-contradictive to me. ;->

Reply
  • How do you propose to let a function like printf know whether to go to xdata or code space?

    That's exactly what's generic about generic pointers: they contain an extra byte to signal this difference. You may want to think of a generic pointer as a data type like

    struct generic_pointer {
        U8  memory_class;
        union {
          void code  *c;
          void xdata *x;
          void data  *d;
          void idata *i;
        } ptr;
    };
    which was versatile enough that it was implemented as an intrinsic data type supported by the compiler and linker.

    printf(" %s", generic_pointer);

    won't work,


    Says who?

    The "address" to your function should almost certainly be a generic pointer. That's always better than abusing an int as a pointer, and particularly better than using arguments to specify one thing.

    And BTW: worrying about efficiency while in the same sentence proposing to use printf() to print a string seems considerably self-contradictive to me. ;->

Children
No data