Hi Ruben,
In CodeWarrior, when you call a function that includes parameters, these are stored in the first CPU registers in calling order. For example, if you call the following function:
TheFunction (Parameter1, Parameter2);
Those parameters are stored in the following way:
R0 = Parameter 1
R1 = Parameter 2
Now, the load (LDR) and store (STR) instructions of ARM require an address in order to load/store a value into a memory location. Knowing this, you can implement a function that sends the data to reverse in a first parameter and the memory address of the variable where it will be stored in a second parameter. Then execute the respective ASM instructions to reverse and store the data.
The following code implements both, REV and REV16 instructions using __asm(). You will notice that we are taking the data to reverse from R0 since the first parameter is the data. Then we are storing the information on the address pointed by R1 (second parameter). In both cases, we are using 0x11223344 so you can see how byte reversing (REV) and half-word reversing (REV16) works in ARM. give it a try and let us know if it worked.
Saludos
Santiago Lopez
void inline Reverse8 (uint32_t u32Source, uint32_t* pu32Destination);
void inline Reverse16 (uint32_t u32Source, uint32_t* pu32Destination);
int main(void)
{
uint32_t A,B;
uint32_t C,D;
A = 0x11223344;
B = 0x00000000;
Reverse8(A, &B);
C = 0x11223344;
D = 0x00000000;
Reverse16(C, &D);
__asm("BKPT");
return 0;
}
void inline Reverse16 (uint32_t u32Source, uint32_t* pu32Destination)
{
__asm("REV16 R3, R0"); //Reverse Half-Word order
__asm("STR R3, [R1]"); //Store value on destination address
}
void inline Reverse8(uint32_t u32Source, uint32_t* pu32Destination)
{
__asm("REV R3, R0"); //Reverse Byte order
__asm("STR R3, [R1]"); //Store value on destination address
}