【问题标题】:Need information about using Inline Assembly for WinCE, ARM9需要有关使用 Inline Assembly for WinCE、ARM9 的信息
【发布时间】:2011-11-17 16:24:27
【问题描述】:

我不擅长内联汇编,但打算在嵌入式项目中将其用于优化目的。由于我不太了解有关它的信息,因此我需要一些帮助。

我有 Win CE 6.0,带有 ARM9,使用 MS Visual Studio 2005(使用 MFC)。

基本上,我想让内存访问更快,并做一些按位运算。

如果我能获得任何在线链接,或者一些使用寄存器、变量名、指针(一些与内存传输和按位运算相关的东西)等的示例,对我来说真的很有帮助适合我的特定环境.

在 ctacke 回答后编辑:

如果有任何链接或小示例可以处理 .s 文件,特别是从 .s 编写和导出函数,以及将它们与我的 MFC 应用程序结合的步骤,这对我真的很有帮助。任何小例子都可以。

谢谢。

亲切的问候, 阿夫塔布

【问题讨论】:

    标签: mfc embedded windows-ce inline-assembly arm9


    【解决方案1】:

    Visual Studio(所有版本)附带的 ARM 编译器不支持内联 ASM - 只有 x86 编译器支持内联 ASM。要将 ASM 用于 ARM(或 SH 或 MIPS),您必须创建一个单独的代码文件(通常是 .s 文件),从 ASM 导出函数并调用它们。

    编辑

    这是一个简单的例子 (taken from here):

    AREA asm_func, CODE, READONLY
    ; Export my_asm function location so that C compiler can find it and link
    EXPORT my_asm
    
    my_asm
    ;
    ; ARM Assembly language function to set LED1 bit to a value passed from C   
    ; LED1 gets value (passed from C compiler in R0)
    ; LED1 is on GPIO port 1 bit 18
    ; See Chapter 9 in the LPC1768 User Manual
    ; for all of the GPIO register info and addresses
    ; Pinnames.h has the mbed modules pin port and bit connections
    ;
    
    ; Load GPIO Port 1 base address in register R1 
    LDR     R1, =0x2009C020 ; 0x2009C020 = GPIO port 1 base address
    
    ; Move bit mask in register R2 for bit 18 only
    MOV.W   R2, #0x040000   ; 0x040000 = 1<<18 all "0"s with a "1" in bit 18
    
    ; value passed from C compiler code is in R0 - compare to a "0" 
    CMP     R0, #0          ; value == 0 ?
    
    ; (If-Then-Else) on next two instructions using equal cond from the zero flag
    ITE EQ
    
    ; STORE if EQ - clear led 1 port bit using GPIO FIOCLR register and mask
    STREQ   R2, [R1,#0x1C]  ; if==0, clear LED1 bit
    
    ; STORE if NE - set led 1 port bit using GPIO FIOSET register and mask
    STRNE   R2, [R1,#0x18]  ; if==1, set LED1 bit
    
    ; Return to C using link register (Branch indirect using LR - a return)
    BX      LR
    END
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多