Skip to main content
Visitor II
November 21, 2005
Question

#HIGH assembly operator problem

  • November 21, 2005
  • 33 replies
  • 4808 views
Posted on November 21, 2005 at 16:22

#HIGH assembly operator problem

    This topic has been closed for replies.

    33 replies

    alfonso2Author
    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 08:05

    woro in this case the result is similary, but i need of the HIGH operator also in different asm codes for extracting the HIGH byte address of a variable.

    ex.

    unsigned short SMC_LOOKUP_TABLE[1024];

    asm{

    .....

    ....

    ADD A,#HIGH(SMC_LOOKUP_TABLE)

    }

    [ This message was edited by: liotro78 on 17-11-2005 12:38 ]

    alfonso2Author
    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 08:11

    excuse me woro but in lst file there is the c instruction pScan=&Buffer_0 and there isn't the asm translation....

    why?

    [ This message was edited by: liotro78 on 17-11-2005 12:54 ]

    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 08:42

    liotro78, I think that there is a workaround for the HIGH operator problem.

    As far I can see, in your C program you can find the higher part of an address. You can also see C variables and symbols from the assembly.

    Why do you not define a dummy variable, as:

    const unsigned char Buffer_0H = HIGH(Buffer_0);

    and use its value instead of the HIGH operator?

    You can also tell the C compiler to put Buffer_0H in ROM, so no precious RAM byte is lost...

    Regards

    EtaPhi

    alfonso2Author
    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 09:00

    ok EtaPhi

    but i need of the address of high byte of buffer_0 and not of its value..

    then if i do this code is correctly?

    #define HIGH(x) ((x) >> 8)

    const unsigned char Buffer_0H = HIGH(Buffer_0);

    asm

    {

    LD A, #Buffer_0

    LD pScan:1, A

    LD A, #Buffer_0H //is similar to #HIGH(Buffer_0)????

    LD pScan, A

    }

    [ This message was edited by: liotro78 on 17-11-2005 13:36 ]

    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 09:09

    What you wrote is not correct.

    You must change

    LD A,#Buffer_0H

    with

    LD A,Buffer_0H

    because you need the content of Buffer_0H, not its lower address...

    EtaPhi

    alfonso2Author
    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 09:22

    But Buffer_0H content is an address?

    Then if Buffer_0 is of this kind

    volatile unsigned short Buffer_0[1024];

    this code is always correct?

    I need of a general definition of HIGH operator, that is good for all types of variable char,short etc...

    Your HIGH define is good also if buffer_0 is an unsigned short array?

    [ This message was edited by: liotro78 on 17-11-2005 14:09 ]

    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 10:00

    Yes, Buffer_0H contains the HIGH BYTE of Buffer_0 address (you set it in the initialization).

    This workaround is also OK if Buffer_0 size changes or if it is moved somewhere else.

    If you need the HIGH BYTE of another buffer (e.g. SMC_LOOKUP_TABLE), all you need is to define a new constant.

    There is no limitation in the base-type of the buffer if you compute the right offsets, I mean: if you want to access the 3rd item of SMC_LOOKUP_TABLE whose items are 2 byte wide, you must add 6 to the address of SMC_LOOKUP_TABLE to access the high byte and you must add 7 to access the low byte.

    EtaPhi

    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 10:05

    Ops, I made a mistake in my explanation!

    The offset 6 and 7 are related to the 4th item...

    EtaPhi

    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 10:45

    Hi liotro78,

    mysterious!!!! My Metrowerks compiler (previous version) creates the expected list file

    ....

    108: #pragma DATA_SEG NEAR RAM2

    109: char Buffer_0[];

    110: #pragma DATA_SEG SHORT BSCT

    111: char* pScan;

    112:

    113: #pragma DATA_SEG DEFAULT

    114:

    115: void test(void)

    116: {

    117: pScan = Buffer_0;

    0000 a600 LD A,#Buffer_0

    0002 b701 LD pScan:1,A

    0004 a601 LD A,#HIGH(Buffer_0)

    0006 b700 LD pScan,A

    118: };

    0008 81 RET

    ....

    I know, that's no great help. Sorry, I don't have any further idea.

    Regards

    WoRo

    alfonso2Author
    Visitor II
    November 17, 2005
    Posted on November 17, 2005 at 11:49

    Etaphy your codes generate two errors.

    But Buffer_0H must be a pointer variable....and the shift is good with 16bit variable?, buffer_0 is declared in 16bits memory address.

    Woro my compiler is 2.0 version and the HIGH operator don't work, but why in my list file don't appears the translation in assembly language of the C instruction pScan=Buffer_0??????

    What's the option of the compiler exactly? i have used the -lasm option for creating .lst file, but the C instructions is not translate?there is an option for activate this translation?

    [ This message was edited by: liotro78 on 17-11-2005 16:21 ]