Assemble Code for KL25

cancel
Showing results for 
Search instead for 
Did you mean: 

Assemble Code for KL25

433 Views
paulliu
Contributor I

Hello,

Can anybody tell me how to write the Assemble Code for below C Code? It seems ARM Cortex M0+ don't have the Boolean Operator for Memory, it only can support the core register R0~R15.

My C Code is as below (IAR EWARM v6.5):

    GPIOE_PSOR |= (1 << 20);
    GPIOE_PSOR |= (1 << 21);
    GPIOE_PCOR |= (1 << 20);
    TPM0_C3SC |= TPM_CnSC_CHF_MASK;

Labels (1)
0 Kudos
2 Replies

169 Views
mikethomas
Contributor II

Hello Paul,

My suggestion is to compile your code above, then look at compiler generated assembly listing.

I have spent many hours studying the ARM and ARM thumb instruction set, and have realized that you cant just load registers with immediate data, and perform logical operations as you would with a CISC processor. ARM is a RISC processor. Sometimes it takes two or more ARM instructions to do simple operations. Also, I have found that the tools for compiling and assembling ARM instruction do some magic in that they encode what appears to be simple instructions, into complex operations. For example, a MOV  r0,# instruction can be converted to a LDR instruction if the immediate data can not fit into the operand. With the LDR instructions, the immediate value is converted to a constant in memory, and loaded. Also, I have seen some compilers convert a MOV r0,# to a MOV R0,# followed by and ADD R0,# to load the desired operand.

One thing that puzzled me for some time is that the ARM instruction set shows that the immediate data in a  MOV rN,#data can only be 8 bit data, but when I look at dissassembled  code from a compiler I see things like :

mov    r3, #28672 . How can this be? Its because although the operand is only 8 bits, there can be a 4 bit shift value which rotates the 8 bit value right by the desired amount. For this case its 7 rotated right 4 times. Any value that cannot be loaded with this method is pieced together either with  MOV's and ADD's or LDR

Hope this helps

Mike

0 Kudos

169 Views
dieterteuchert
Contributor IV

The OP needs to try and understand the difference between = and |= operators and how the PSOR and PCOR registers work. Those registers perform the desired logical operations when used with the = operator! I find it annoying to see this error in many posts on this forum. The code is wrong because it generates useless codewords and machine cycles - and in some cases unexpected side effects. The Kinetis has many of those registers with built-in logical functions and they need to be used properly.

0 Kudos