From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9043 invoked by alias); 10 Jun 2013 21:41:50 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 9034 invoked by uid 89); 10 Jun 2013 21:41:50 -0000 X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,SPF_PASS autolearn=ham version=3.3.1 Received: from mail-la0-f53.google.com (HELO mail-la0-f53.google.com) (209.85.215.53) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 10 Jun 2013 21:41:49 +0000 Received: by mail-la0-f53.google.com with SMTP id fs12so4751699lab.12 for ; Mon, 10 Jun 2013 14:41:47 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.201.105 with SMTP id jz9mr7386731lbc.27.1370900507222; Mon, 10 Jun 2013 14:41:47 -0700 (PDT) Received: by 10.114.79.233 with HTTP; Mon, 10 Jun 2013 14:41:47 -0700 (PDT) Date: Mon, 10 Jun 2013 21:41:00 -0000 Message-ID: Subject: Thumb inline assembly From: Kalai Rajah N To: "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset=ISO-8859-1 X-SW-Source: 2013-06/txt/msg00057.txt.bz2 Hi, I'm trying to do a simple register read through ARM inline assembly. If I embed the asm in the function directly, it works ... eg: #define BAD 0xBAADBAAD #define GOOD 0x600D600D #define RESET 0x00000000 #define NVIC_ISER0 0xE000E100 volatile int nvic_iser_status = 0xFFFFFFFF; function () { ... asm volatile( "ldr r2, =8 /* number of register */ \n\t" "ldr r1, =%0 /* load the nvic_iser* register */ \n\t" "read_nvic_iser:\n\t" "sub r2, r2, #1\n\t" "ldr r0, [r1]\n\t" "add r1, r1, #4 /* go to the next register */ \n\t" "cmp r0, %1\n\t" "beq read_nvic_iser_ok\n\t" "ldr r3, =%2\n\t" "str r3, [%4] /* update status flag */\n\t" "read_nvic_iser_ok:\n\t" "cmp r2, #0\n\t" "bne read_nvic_iser\n\t" "ldr r3, =%3\n\t" "str r3, [%4] /* update status flag */\n\t" : : "i" (NVIC_ISER0), "i" (RESET), "i" (BAD), "i" (GOOD), "r" (&nvic_iser_status) : "r0", "r1", "r2", "r3" ); .. } But, if I want to call the asm through another function, I get errors .. eg: function (){ ... reg_read(NVIC_ISER0, RESET, nvic_iser_status) .. } reg_read(int addr, int reset, int status){ asm volatile( "ldr r2, =8 /* number of register */ \n\t" "ldr r1, =%0 /* load the nvic_iser* register */ \n\t" "read_reg:\n\t" "sub r2, r2, #1\n\t" "ldr r0, [r1]\n\t" "add r1, r1, #4 /* go to the next register */ \n\t" "cmp r0, %1\n\t" "beq read_reg_ok\n\t" "ldr r3, =%2\n\t" "str r3, [%4] /* update status flag */\n\t" "read_reg_ok:\n\t" "cmp r2, #0\n\t" "bne read_reg\n\t" "ldr r3, =%3\n\t" "str r3, [%4] /* update status flag */\n\t" : : "r" (addr), "r" (reset), "r" (BAD), "r" (GOOD), "r" (status) : "r0", "r1", "r2", "r3" //: ); } 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? thanks, Kalai