Out of line (embedded) assembler

Asked by Siddarth Gore

The Keil ARM compiler has a embedded assembler feature where if you want to write a function in assembly code you can do that in the c file itself.

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472c/Chddbeib.html

This is slightly different than using inline assembly. My question is how do I port a function like below to the gnu toolchain?

__asm return-type function-name(parameter-list)
{
  // ARM/Thumb/Thumb-2 assembler code
  instruction{;comment is optional}
  ...
  instruction
}

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Grieger (t-grieger) said :
#1

Hi,

to embed assembler in C functions one has to use the asm("") keyword. As an example a function to set the basepri register:

void __set_BASEPRI(uint_32 basePri)
{
    asm("msr basepri, r0");
}

Please note that the string "basepri" in the asm instruction refers to a register in the processor, the variable "basePri" is saved in the register r0.

It should be possible to concatenate several lines of assembler code in one asm("") instruction but I haven't tried it. I'm using one asm("") instruction for every asm line.

Best regards,
Thomas

Revision history for this message
Joey Ye (jinyun-ye) said :
#2

Siddarth,

GNU style of inline asm only accepts instruction by instruction. There is no support for the "asm function".

I'd suggest some script to convert the "asm function" into GNU style.

Thanks,
Joey

Can you help with this problem?

Provide an answer of your own, or ask Siddarth Gore for more information if necessary.

To post a message you must log in.