Can someone explain me this syntax? It comes from the Hi Tech C include file
/* STATUS bits */
static volatile bit IRP @ (unsigned)&STATUS*8+7;
static volatile bit RP1 @ (unsigned)&STATUS*8+6;
static volatile bit RP0 @ (unsigned)&STATUS*8+5;
static volatile bit TO @ (unsigned)&STATUS*8+4;
static volatile bit PD @ (unsigned)&STATUS*8+3;
static volatile bit ZERO @ (unsigned)&STATUS*8+2;
static volatile bit DC @ (unsigned)&STATUS*8+1;
static volatile bit CARRY @ (unsigned)&STATUS*8+0;
I presume these are peripherail hardware registers. The
bittype and@are non-standard.@places them at absolute addresses given bySTATUS.bittells the compiler that the addresses are actually single bits, so it possibly has to use appropriate instructions (bit-operations).According to @LPs' comment (and after some thought), this looks like PIC-MCU (you did not state the CPU used). The
bittype tells the compiler the addresses of the objects (ZERO, etc.) address single bits in the "RAM" (STATUSis actually a CPU register memory-mapped) address space. The bit-number is packed into the lower 3 bits (bit 0..7) and the byte-address is in the upper bits.The right side of the
@calculats this bit-address: (8 bits/byte, hence the multiplication) and bit-number (lower 3 bits, hence the addition. Alternatively one could use bit-operators (identical result):I'm very sure,
@andbitare explained in the compiler documentation.Note that the bit-type is actually violating the C standard, as this mandates the smallest addressable type to be
charwith at least 8 bits andsizeof(char) == 1.