2005-11-21 07:22 AM
2005-11-15 06:11 AM
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?
2005-11-15 09:46 PM
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...2005-11-15 11:46 PM
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 EtaPhi2005-11-16 07:24 AM
Dear Etaphi,
I have found a possible similar instruction of #HIGH(Buffer_0): ((&Buffer_0 & 0xff00) >> 8); what do you think?2005-11-16 06:46 PM
Liotro78,
addresses are unsigned, so the HIGH operator can be defined as: #define HIGH(x) ((x) >> 8) Bye EtaPhi2005-11-16 07:56 PM
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??? WoRo2005-11-16 09:15 PM
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 ]2005-11-16 09:28 PM
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?2005-11-16 10:09 PM
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...2005-11-16 10:50 PM
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 ]