PIC18 cheatsheet

TBLWT*-

Detailed reference for the TBLWT*- instruction in PIC18 ISA.

Description

Table Write with post‑decrement.

The TBLWT* instruction transfers the contents of WREG to the table memory location currently referenced by the 13‑bit TBLPTR registers, and then decrements TBLPTR by one. The instruction has no operands and takes no d or a options.

  • UseTBLPTR must be loaded with the desired address before the instruction is executed.
  • Result – After the write, WREG remains unchanged, the byte is stored at the original address, and TBLPTR now points to the previous table location.
TBLWT*

Examples

; Set TBLPTR to 0x2000, write value 0x5A from WREG, decrement pointer
MOVLW 0x00
MOVWF TBLPTRL
MOVLW 0x20
MOVWF TBLPTH
MOVLW 0x5A
TBLWT* ; 0x5A written to 0x2000, TBLPTR becomes 0x1FFF
; Write two consecutive values using post‑decrement
MOVLW 0xFF
MOVWF TBLPTRL
MOVLW 0x01
MOVWF TBLPTH
MOVLW 0xAA
TBLWT* ; writes 0xAA to 0x1FFF, TBLPTR=0x1FFE
MOVLW 0xBB
TBLWT* ; writes 0xBB to 0x1FFE, TBLPTR=0x1FFD
; Demonstrate successive writes – TBLPTR decrements again
MOVLW 0x00
MOVWF TBLPTRL
MOVLW 0x20
MOVWF TBLPTH
MOVLW 0x5A
TBLWT* ; writes 0x5A to 0x2000, TBLPTR=0x1FFF
MOVLW 0x6B
TBLWT* ; writes 0x6B to 0x1FFF, TBLPTR=0x1FFE