8051 pointer weirdness.

Help
secross
2010-01-04
2013-03-12
  • secross
    secross
    2010-01-04

    Hello, I have come up against a weird problem that makes the pointer
    die off in my code.
    I am running the code on a paulmon rev 3 dev board and also
    another 8052 wirewrapped with 32k of ram, they both output the same results.

    sdcc -v
    SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Nov 19 2009) (UNIX)

    first i fill all ram with 0x55 then run this:

    sdcc -code-loc 0x2000 ptr_dies.c ; cat ptr_dies.ihx > /dev/ttyS1

    code:`enter code here`

    #include<8052.h>

    #define RAM_START 0x2500
    #define RAM_END 0x3FFF

    void main(void)
    {
    unsigned int a=0;
    xdata unsigned char *abs_ptr = (xdata unsigned char *) RAM_START; // Initialize pointer to RAM_START
    for(a = RAM_START; a <= RAM_END; a++)
    {
    if( a = a + 1024 ){} // pointer works for 7 bytes then quits
    *abs_ptr = 0x00 ;
    *abs_ptr++ ;
    }

     
  • Peter Hull
    Peter Hull
    2010-01-14

    I'm not sure what the code is intended to do but it seems to be 'correct' in the sense that it should indeed loop around seven times then quit (a takes the values 2500, 2901, 2d02, 3103, 3504, 3905, 3d06, then the next one is > RAM_END)
    I don't understand the purpose of

    if( a = a + 1024 ){}
    

    which is a complicated way to write a+=1024;
    and also

    *abs_ptr = 0x00 ;
    *abs_ptr++ ;
    

    which is the same as *abs_ptr = 1;

    Sorry if I didn't understand something.

    Peter