On the Wiki it is suggested to make code register size-independent by avoiding immediate values and instead referencing them by address. This way if the register is 8 bits, it uses the first byte only, without changing the interpretation of the instructions.
Code:
and #$0F ; no, requires that size of accumulator be known
and mask ; works whether accumulator is 8 or 16 bits
...
mask: .word $0F ; that is, .byte $0F,$00
The following seems simpler: tell the assembler that A is 8 bits, then manually add a NOP after any instruction which uses immediate mode. This way, if 8 really is 8 bits, an extra NOP will be encountered, otherwise, the high byte of the immediate value will be $EA. Some code might need a zero for the high byte, but in most cases since it can only assume the low 8 bits of A are valid anyway, the junk in the upper byte wouldn't be a problem; in those cases that it does matter, the above technique might work best.
Code:
.a8 ; tell assembler to use 8-bit immediate values for accumulator
and #$0F
nop
; What the 65816 sees when in 16-bit accumulator mode:
and #$EA0F
The same should apply to X and Y as well, though size-independent use of them would be less common.
EDIT: it might be better to code for the 16-bit case, so the $EA upper byte is obvious:
Code:
.a16
and #$EA0F