Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
16-bit MCU and DSC Programmer’s Reference Manual
DS70157F-page 426 © 2005-2011 Microchip Technology Inc.
SWAP
Byte or Nibble Swap Wn
Implemented in: PIC24F PIC24H PIC24E dsPIC30F dsPIC33F dsPIC33E
X X X X X X
Syntax: {label:} SWAP{.B} Wn
Operands: Wn ∈ [W0 ... W15]
Operation: For byte operation:
(Wn)<7:4> ↔ (Wn)<3:0>
For word operation:
(Wn)<15:8> ↔ (Wn)<7:0>
Status Affected: None
Encoding: 1111 1101 1B00 0000 0000 ssss
Description: Swap the contents of the working register Wn. In Word mode, the two
bytes of Wn are swapped. In Byte mode, the two nibbles of the Least
Significant Byte of Wn are swapped, and the Most Significant Byte of
Wn is unchanged. Register direct addressing must be used for Wn.
The ‘B’ bit selects byte or word operation (‘0’ for word, ‘1’ for byte).
The ‘s’ bits select the address of the working register.
Note: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
Words: 1
Cycles: 1
Example 1:
SWAP.B W0 ; Nibble swap (W0)
Before
Instruction
After
Instruction
W0 AB87 W0 AB78
SR 0000 SR 0000
Example 2:
SWAP W0 ; Byte swap (W0)
Before
Instruction
After
Instruction
W0 8095 W0 9580
SR 0000 SR 0000
Protego_Release_01_05-Related-OEM-Documentation-PIC24FJ64GA004-Programmers_Reference_Manual.pdf