This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to read from an address, with C?

Hello,

i'm new in progamming with C language, till now i've used assembly, and i don't know how to read a value from a specific location in program memory. 

In assembly i have these intructions:

SPLK #5800h,Var

LACC  Var

TBLR Var2

to read a word at a certain address. How can i write it in C?

 

I use an F2406A and CCS v.3.3.82.13. 

I need this code because i want to scroll some datas from a table, accessing it only with address. Till now we have used assembly for programming, but now to improve speed, and to adequate at safety specifications, IEC 61508, we have decided to write the application in C, with the problem of learning a new language.

thanks

  • Dear Emanuele,

    If my memory serves me correctly TBLR reads from program memory space and the code snippet you supplied reads from location 0x5800 from program memory space. As far as I know there is no direct option to read/write to program memory space in C code. I do remember the application report "Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP", where you can get this done via function call

    Regards, Mitja

  • Emanuele,

    I don't know whether the address location 0x5800 is readable or not. But here is the simple code which can help to read data from a given address.

    Suppose you want to read an integer (16 bits) from the given address location , here is the sample program

    {

    int value;

    int *ptr = 0x5800; /* ptr is pointing to the address location 0x5800 */

    value = *ptr;  /* Reading the integer value from the address pointed by ptr and storing it to the variable "value" */

    printf("The data read = %d \n", value);  /* Printing the value */

    }

    Suppose you want to read an character (8 bits or 1 byte) , here is the sample program

    {

    char value =  0;

    char *ptr = 0x5800; /* ptr is pointing to the address location 0x5800 */

    value = *ptr;  /* Reading 1 byte from the address pointed by ptr and storing it to the variable "value" */

    printf("The data read = %d \n", value);  /* Printing the value */

    }

    Regards,

    Nag

    (If your question is answered, please click the  Verify Answer  button on this post)

  • Yes Mitja, you are right.

    That document was exactly what i was looking for, and in the download page there is clearly written that C24x compiler does not have a command for accessing program memory. So i have used my old asm code, that is the same code provided in the TI functions. 

    I've tried also the code of Nag, but it won't compile.

    Thanks to all for solutions provided!

    Emanuele