Hello,

I use arm-none-eabi-gcc-linaro-6.3.2017.02p3 to write a code for
Cortex-M0 SoC, which uses only Thumb instruction.

I found that arm-none-eabi-gcc with -mcpu=cortex-m0 option links
ARM-instruction library when a compiled code has division/remainder
operation.

Here is a code for testing.

----
int main(int argc, char *argv[])
{
        *((volatile int *)0x0a00) =
                *((volatile int *)0x0a04) / *((volatile int *)0x0a08);
        
        *((volatile int *)0x0b00) =
                *((volatile int *)0x0b04) % *((volatile int *)0x0b08);

        return 0;
}
----

Simply compile with "arm-none-eabi-gcc -mcpu=cortex-m0 test.c" and
disassmble. 

----
00008378 <__aeabi_idivmod>:
    8378:       e3510000        cmp     r1, #0, 0
    837c:       0afffff7        beq     8360 <.divsi3_skip_div0_test+0x110>
    8380:       e92d4003        push    {r0, r1, lr}
    8384:       ebffffb1        bl      8250 <.divsi3_skip_div0_test>
    8388:       e8bd4006        pop     {r1, r2, lr}
    838c:       e0030092        mul     r3, r2, r0
    8390:       e0411003        sub     r1, r1, r3
    8394:       e12fff1e        bx      lr

00008398 <__aeabi_idiv0>:
    8398:       4770            bx      lr
    839a:       46c0            nop                     ; (mov r8, r8)

0000839c <atexit>:
    839c:       b510            push    {r4, lr}
    839e:       0001            movs    r1, r0
    83a0:       2300            movs    r3, #0
    83a2:       2200            movs    r2, #0
    83a4:       2000            movs    r0, #0
    83a6:       f000 fbdb       bl      8b60 <__register_exitproc>
    83aa:       bc10            pop     {r4}
    83ac:       bc02            pop     {r1}
    83ae:       4708            bx      r1
----

I found that _mainCRTStartup, __aeabi_idiv, .divsi3_skip_div0_test and
__aeabi_idivmod is ARM, others are Thumb.

I want to use division/remainder function (no startup required),
is there any remedy?

Regards,
-- 
SASANO Takayoshi (JG1UAA) <u...@mx5.nisiq.net>

Reply via email to