Swap - Hitachi SH7750 Programming Manual

High-performance risc engine superh (sh) 32-bit risc mcu/mpu series
Hide thumbs Also See for SH7750:
Table of Contents

Advertisement

10.98

SWAP

Upper-/Lower-Half
Swap
Format
SWAP.B Rm,Rn
SWAP.W Rm,Rn
Description
This instruction swaps the upper and lower parts of the contents of general register Rm, and stores
the result in Rn.
In the case of a byte specification, the 8 bits from bit 15 to bit 8 of Rm are swapped with the 8 bits
from bit 7 to bit 0. The upper 16 bits of Rm are transferred directly to the upper 16 bits of Rn.
In the case of a word specification, the 16 bits from bit 31 to bit 16 of Rm are swapped with the 16
bits from bit 15 to bit 0.
Operation
SWAPB(long m, long n)
{
unsigned long temp0,temp1;
temp0=R[m]&0xFFFF0000;
temp1=(R[m]&0x000000FF)<<8;
R[n]=(R[m]&0x0000FF00)>>8;
R[n]=R[n]|temp1|temp0;
PC+=2;
}
SWAPW(long m, long n)
{
unsigned long temp;
temp=(R[m]>>16)&0x0000FFFF;
R[n]=R[m]<<16;
SWAP register halves
Summary of Operation
Rm → lower-2-byte upper-/
lower-byte swap → Rn
Rm → upper-/lower-word
swap → Rn
/* SWAP.B Rm,Rn */
/* SWAP.W Rm,Rn */
Data Transfer Instruction
Instruction Code
0110nnnnmmmm1000 1
0110nnnnmmmm1001 1
Rev. 2.0, 03/99, page 381 of 396
Execution
States
T Bit

Advertisement

Table of Contents
loading

Table of Contents