BYTE COERSION

The unary operator (.byte) is the byte coersion operator. It instructs the XCASM compiler to use 8 bit quantities during computation of its operand (i.e the tagged part of the expression).

Consider the following example (where D, G and H are defined as word variables)

The expression:

	D = G + H
would generate
        0006    08 1F           movf    G+1,w
        0007    00 9D           movwf   D+1
        0008    08 1E           movf    G,w
        0009    07 20           addwf   H,w
        000A    00 9C           movwf   D
        000B    18 03           btfsc   STATUS,C
        000C    0A 9D           incf    D+1
        000D    08 21           movf    H+1,w
        000E    07 9D           addwf   D+1
Here you can see that the computation is carried out using 16 bit addition.

However if instead we used:

	D = (.byte)(G + H) 
this would generate
        000F    08 1E           movf    G,w
        0010    07 20           addwf   H,w
        0011    01 9D           clrf    D+1
        0012    00 9C           movwf   D
Here you can see that the computation is carried out using 8 bit addition even though the quantities involved were 16 bits. This is because we told the compiler to do so by using the (.byte) operator.

To be exact, what the (.byte) operator did was to tell the compiler that the sub-expression (G + H) should yield an 8 bit value, and the compiler produced only sufficent code to produce an 8 bit result. Any code necessary to extend the 8 bit result to a 16 bit result was discarded.

Note how using the (.byte) operator is far more efficient than masking out the most significant 8 bits. e.g.

	D = (G + H) & 0xff
would generate:
        0013    08 1F           movf    G+1,w
        0014    00 9D           movwf   D+1
        0015    08 1E           movf    G,w
        0016    07 20           addwf   H,w
        0017    00 9C           movwf   D
        0018    18 03           btfsc   STATUS,C
        0019    0A 9D           incf    D+1
        001A    08 21           movf    H+1,w
        001B    07 9D           addwf   D+1
        001C    01 9D           clrf    D+1