Even I'm confused about the errors. when remove the clobber list "r0", "r1", "r2", "r3", I get undefined reference to r1, r3 and r2. Here is the generated assembly code 1: when the asm is called directly ... this seems to work ldr r2, =8 /* number of register */ ldr r1, =#-536813312 /* load the nvic_iser* register */ read_nvic_iser: sub r2, r2, #1 ldr r0, [r1] add r1, r1, #4 /* go to the next register */ cmp r0, #0 beq read_nvic_iser_ok ldr r3, =#-1163018018 str r3, [r4] /* update status flag */ read_nvic_iser_ok: cmp r2, #0 bne read_nvic_iser ldr r3, =#1611514078 str r3, [r4] /* update status flag */ 2: when the asm gets called through another function ... this is having the compilation error ... .thumb_func .type check_reset_value, %function check_reset_value: @ args = 0, pretend = 0, frame = 16 @ frame_needed = 1, uses_anonymous_args = 0 @ link register save eliminated. push {r4, r5, r6, r7, r8} sub sp, sp, #20 add r7, sp, #0 str r0, [r7, #12] str r1, [r7, #8] str r2, [r7, #4] ldr r6, [r7, #12] ldr ip, [r7, #8] movw r4, #49374 movt r4, 47789 movw r5, #49374 movt r5, 24589 ldr r8, [r7, #4] @ 24 "nvic_reg_read.c" 1 ldr r2, =8 /* number of register */ ldr r1, =r6 /* load the nvic_iser* register */ <------ read_reg: sub r2, r2, #1 ldr r0, [r1] add r1, r1, #4 /* go to the next register */ cmp r0, ip beq read_reg_ok ldr r3, =r4 <---------- str r3, [r8] /* update status flag */ read_reg_ok: cmp r2, #0 bne read_reg ldr r3, =r5 <-------------- str r3, [r8] /* update status flag */ the lines marked with the arrows are where the errors occur. On Mon, Jun 10, 2013 at 3:51 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > On Mon, Jun 10, 2013 at 2:41 PM, Kalai Rajah N <kalairajah@xxxxxxxxx> wrote: > >> I'm trying to do a simple register read through ARM inline assembly. >> If I embed the asm in the function directly, it works ... > > ... > >> I see the following errors: >> /tmp/ccYu7aUS.ltrans0.ltrans.o: In function `read_reg_ok': >> ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x60): undefined >> reference to `r6' >> ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x64): undefined >> reference to `r4' >> ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x68): undefined >> reference to `r5' >> collect2: error: ld returned 1 exit status >> >> What am I doing wrong? > > > Your test case has no mention of r4, r5, or r6. It always helps to > show a complete standalone test case. > > The error messages indicate some confusion: there are references to > symbols using the names of registers. But I don't know where those > are coming from. > > Ian