We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have one question about accessing high byte of 2-byte idata variable.
Case 1: for xdata variable we can use below to access the higher byte:
#define ADDR *((_2BYTE xdata *) 0x0800) #define ADDRH *((_1BYTE xdata *) 0x0800) #define ADDRL *((_1BYTE xdata *) 0x0801)
If ADDRH is enough to make decision then we can just use ADDRH, instead of ADDR(2-byte)... This save code space...
Case 2: if ADDR is declared as "idata" then is there any way achieving the same goal like Case 1 ?
All we want to do is "save code base"...
Thanks in advance...
In that case, you can reduce the code size by just performing an 8-bit test instead of a 16-bit test. An 8-bit processor doing a 16-bit test normally means that the code first checks one byte (high or low depending on compiler choice) and then decides if it needs to test the other byte - but the code is always generated for supporting testing of two bytes.
Your knowledge that the high byte is 0xff when and only when there is an error condition means that you know that there is never a need to check the low byte, and hence no need to generate any code for any such test.
Note that on a 16-bit or 32-bit processor, it may not change the code size or execution speed if you perform a one-byte test or a 16-bit test. It is only for processors that must perform a 16-bit test as two separate 8-bit comparisons - or that must load the 16-bit reference value as two 8-bit reads - that you may be reasonably sure you can get a gain from modifying the code to just look at the high byte.