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.

Table 3-7. 16-Bit Literal Coding
Literal ValueWord/long-word Mode

kk kkkk kkkk

Byte Mode

kkkk kkkk

00000 0000 0000 00000000 0000
10000 0000 0000 00010000 0001
20000 0000 0000 00100000 0010
1270000 0000 0111 11110111 1111
1280000 0000 1000 00001000 0000
2550000 0000 1111 11111111 1111
2560000 0001 0000 0000N/A
5120000 0010 0000 0000N/A
10230000 0011 1111 1111N/A
655351111 1111 1111 1111 N/A
Note: Using a literal value greater than 127 in Byte mode is functionally identical to using the equivalent negative two’s complement value, since the MSb of the byte is set. When operating in Byte mode, the assembler will accept either a positive or negative literal value (i.e., #-10).

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