Ed VanderPloeg wrote: > > At 08:00 AM 3/6/97 PST, you wrote: > >Hi, > > > >I think I'm missing something very basic. I'm using ByteCraft's MPC and > >the target controller is the PIC16C74A. This macro is supposed to take > >2 unsigned 8-bit chars (h: high, l: low), concatenate them, and return > >the unsigned 16 bit result. Instead, it's masking (zeroing) the high > >byte. > > > >#define WORD(h,l) (((unsigned long)(h) << 8) | (unsigned char)(l)) > > > >Thanks, Matt > > > I don't use the MPC compiler, but have you tried: > - extra brackets around the first cast & the "(h)", like this: > #define WORD(h,l) ((((unsigned long)(h)) << 8) | (unsigned char)(l)) > > - using a different cast like (uint16) or (word), to see if the compiler is > only allowing 8 bits for the "long". > > - casting the whole macro to ensure a 16 bit output: > #define WORD(h,l) (unsigned long)(((unsigned long)(h) << 8) | \ > (unsigned char)(l)) > > IMHO, it seems there should be a much more efficient way to create a word > out of two bytes than this. I'm curious as heck what the compiler gives > you for that macro. Maybe it actually sets up a loop and shifts eight > times (gross!). Trouble is, I can't think of any alternatives right now. > Anyone got ideas? > > -Ed V. Ed, As you can see, the compiler stores the high byte, clears the storage location for the low byte, and ORs the low byte into the cleared location. The only inefficiency that I can see is the ORing into a known-clear location (instead of a MOV). BCF STATUS,RP0 Sample = WORD(Phi, Plo); MOVF 39,W BSF STATUS,RP0 MOVWF 46 CLRF 45 BCF STATUS,RP0 MOVF 3A,W BSF STATUS,RP0 IORWF 45 BTW, the extra brackets didn't change the assembled code. I still have to try it in my target system. Matt