PlatformIO Community

Cpp + assembly compiling issue

Hey guys, I am facing an issue that I couldn’t turn arround, I would like to ask your help.
I am trying to add an assembly code mixed to my Cpp code, but the issue “arm-none-eabi-as: unrecognized option `-x’” always happen. what could I do to fix this? I am following the mbed page https://developer.mbed.org/cookbook/Assembly-Language#debugging-assembly-language and simplifying the code example.

 AREA asm_func, CODE, READONLY
@ Export my_asm function location so that C compiler can find it and link
EXPORT my_asm

my_asm:

CMP R0, #0
ITE EQ
MOVEQ R0, #1
MOVNE R0, #0
BX      LR
END

This is my assembly code. But I guess this is not the problem.

Hi @rodrigopex
Are you sure this example is written according to GNU assembler syntax? Looks like it’s written for KEIL.
Here is GNU ARM Assembler Quick Reference.

Hi @valeros,
Maybe that is a different assembly but the main issue in this case seems to be the compilation command that is using an unrecognized flag/option.

Thank you.
Best regards,
Rodrigo Peixoto

I’ve just compiled a simple project with .S file without any error.
-x option is needed by the arm-none-eabi-gcc to build assembly files, so the arm-none-eabi-as shouldn’t be called directly.
Could you please share your project to reproduce this issue?

I had the same issue. Problem was in the file extension “s” (originally I copied filename “demo_asm.s” from somewhere) instead of “S”.
This is my “demo_asm.S” which can be built sucessfully

@ File demo_asm.s
.syntax unified
.cpu cortex-m4

.section .text
    .global norm_sq_asm
    norm_sq_asm:
        @ Input array address: R0
        @ Number of elements: R1
        MOVS R2, R0 @ move the address in R0 to R2
        MOVS R0, #0 @ initialize the result
        sum_loop:
            LDRSH R3, [R2], #0x2 @ load int16_t value pointed to by R2 into R3, then increment
            MLA R0, R3, R3, R0 @ sq & accum in one step (faster)
            SUBS R1, #1 @ R1 = R1 - 1, decrement the count
            BNE sum_loop @ branch if value not zero
        BX LR @ return R0