3.7 Using 16-Bit Literal Operands
Several instructions that support Byte and Word mode have 16-bit operands. For byte instructions, a 16-bit literal is too large to use. Therefore, when 16-bit literals are used in Byte mode, the range of the operand must be reduced to eight bits or the assembler will generate an error. Likewise, the literal is zero-extended to 32-bits for long-word instructions. Likewise, the literal is zero-extended to 32-bits for long-word instructions. Table 3-7 shows that the range of a 16-bit literal is 0:65535 in Word/long-word mode and 0:255 in Byte mode.
Instructions that employ 16-bit literals in Byte and Word/Long-Word mode are
ADD
, ADDC
, AND
,
IOR
, RETLW
, SUB
,
SUBB
and XOR
. Using 16-Bit Literals for Byte Operands shows how positive
and negative literals are used in Byte mode for the ADD
instruction.
Literal Value | Word/long-word Mode
| Byte Mode
|
---|---|---|
0 | 0000 0000 0000 0000 | 0000 0000 |
1 | 0000 0000 0000 0001 | 0000 0001 |
2 | 0000 0000 0000 0010 | 0000 0010 |
127 | 0000 0000 0111 1111 | 0111 1111 |
128 | 0000 0000 1000 0000 | 1000 0000 |
255 | 0000 0000 1111 1111 | 1111 1111 |
256 | 0000 0001 0000 0000 | N/A |
512 | 0000 0010 0000 0000 | N/A |
1023 | 0000 0011 1111 1111 | N/A |
65535 | 1111 1111 1111 1111 | N/A |
Using 16-Bit Literals for Byte Operands
ADD.B #0x80, W0 ; add 128 (or -128) to W0
ADD.B #0x380, W0 ; ERROR... Illegal syntax for byte mode
ADD.B #0xFF, W0 ; add 255 (or -1) to W0
ADD.B #0x3FF, W0 ; ERROR... Illegal syntax for byte mode
ADD.B #0xF, W0 ; add 15 to W0
ADD.B #0x7F, W0 ; add 127 to W0
ADD.B #0x100, W0 ; ERROR... Illegal syntax for byte mode