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?"

    You don't. Most of the library routines deal with generic pointers. Again, read about generic pointers. They are 3-byte pointers encoded to specify the memory space they point to. Your dump routine could to likewise, taking a generic pointer and then "converting" it to a mspace-specific pointer for speed when necessary.

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

    You don't. Most of the library routines deal with generic pointers. Again, read about generic pointers. They are 3-byte pointers encoded to specify the memory space they point to. Your dump routine could to likewise, taking a generic pointer and then "converting" it to a mspace-specific pointer for speed when necessary.

Children
No data