cancel
Showing results for 
Search instead for 
Did you mean: 

#HIGH assembly operator problem

alfonso2
Associate II
Posted on November 21, 2005 at 16:22

#HIGH assembly operator problem

33 REPLIES 33
alfonso2
Associate II
Posted on November 15, 2005 at 15:11

I have read the manual and i have see that i can use the high, but it's possible that my errors is in the options compiler? there's a option for activating the HIGH macro?

franco
Associate II
Posted on November 16, 2005 at 06:46

Quote:

On 11-11-2005 at 12:23, Anonymous wrote:

the problem remaining....the label HIGH is unknow...

but there's an alternative method for extracting the high byte of a variable of 2 bytes?

Why don't you use this way?;

ld a,buffer_0..............;MSB byte

ld a,{buffer_0+1}.......;LSB byte

You don't have to use any ''high'' function...

fggnrc
Associate II
Posted on November 16, 2005 at 08:46

FL77, your solution yelds a wrong output for liotro78 problem.

He wants the assembly translation of the following C instruction:

pScan = Buffer_0;

where pScan and Buffer_0 are defined as:

char * pScan;

volatile char Buffer_0[512];

As I posted before, the C translation of your hint is:

pScan = (char *)((Buffer[0] << 8) + Buffer[1]);

If the HIGH operator doesn't work, liotro78 may leave the original C instruction. Of course, this will result in an intermixed C and asm blocks, but it will work...

Bye

EtaPhi

alfonso2
Associate II
Posted on November 16, 2005 at 16:24

Dear Etaphi,

I have found a possible similar instruction of #HIGH(Buffer_0):

((&Buffer_0 & 0xff00) >> 8);

what do you think?

fggnrc
Associate II
Posted on November 17, 2005 at 03:46

Liotro78,

addresses are unsigned, so the HIGH operator can be defined as:

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

Bye

EtaPhi

wolfgang2399
Associate II
Posted on November 17, 2005 at 04:56

Did you still compile the C-code

pScan = Buffer_0;

-or-

pScan = &Buffer_0;

-or-

pScan = &Buffer_0[0];

(which all will give the same result in C)?

What is the translated assembler-code???

WoRo

alfonso2
Associate II
Posted on November 17, 2005 at 06:15

thanks woro,

your instruction is exactly because the name of an array is the pointer at the first element of the array.

but i need in general of the HIGH operator also in other part of assembly code that use this operator.

[ This message was edited by: liotro78 on 17-11-2005 10:46 ]

alfonso2
Associate II
Posted on November 17, 2005 at 06:28

Excuse me Eta_phi,

but if Buffer_0 is a unsigned short variable (2 bytes), why i cannot recovery the address of the high byte with the (&Buffer_0 & 0xff00)>>8?

example, if Buffer_0 address is $1050 with (&Buffer_0 & 0xff00) the result is $1000 and with >>8 the result is $0010 and when later i do LD A,Buffer_0,the register A is loaded with the high address 10?

but if i define HIGH in your way, i can use it in assembly code directly?

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

asm

{

LD A, #Buffer_0

LD pScan:1, A

LD A, #HIGH(Buffer_0)

LD pScan, A

}

is correctly?

fggnrc
Associate II
Posted on November 17, 2005 at 07:09

There is an efficiency reason.

Your definition of HIGH requires an AND operation that is not needed when there are unsigned values.

The C bit shift operator may be translated in a series of SRL (unsigned quantities) or SRA (signed quantities).

The former clears the most significant bit, while the latter preserves it.

In both situations, care must be used because the C compiler applies integer promotion (i.e. 8 bit values are converted into 16 bit ones) and casts the result to a 8 bit quantity. Therefore the result may be not what you expect.

You can not use my C definition of HIGH, because it is something that the C compiler understands, not the assembler...

EtaPhi

BTW: my version of HIGH may be inefficient on ST7 cores.

The C compiler have to be ''smart'' to translate 8 bit shifts in a byte offset. On machines with barrell shifter (e.g. x86), the C compiler does not have to be so smart, since there is no penalty.

When the C compiler is ''dumb'', one can use the union trick:

union {

int word;

struct {

unsigned char high;

unsigned char low;

} bytes;

}

in order to access the higher and lower byte of a word.

However, this is a story of a remote past...

alfonso2
Associate II
Posted on November 17, 2005 at 07:50

But why the HIGH operator don't work well?

i have reading the help of AST7 and CST7 and this opearator appears in it.

I have an expired license of 30 days, this can be a possible reasons of this problem?

And finally you don't know the basicaly assembly instructions that i can overlap at HIGH operator?

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

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