2005-11-21 07:22 AM
2005-11-16 10:58 PM
Hi liotro78,
again: what is the resulting asm-code, when you compile the C-code? WoRo2005-11-16 11:05 PM
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 ]2005-11-16 11:11 PM
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 ]2005-11-16 11:42 PM
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 EtaPhi2005-11-17 12:00 AM
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 ]2005-11-17 12:09 AM
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... EtaPhi2005-11-17 12:22 AM
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 ]2005-11-17 01:00 AM
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. EtaPhi2005-11-17 01:05 AM
Ops, I made a mistake in my explanation!
The offset 6 and 7 are related to the 4th item... EtaPhi2005-11-17 01:45 AM
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