Need information about using Inline Assembly for WinCE, ARM9

969 views Asked by At

I am not very good in inline assembly, but planning to use it for optimization purpose in an Embedded project. As I don't know much of the information about it, I am in need of some help.

I am having Win CE 6.0, with ARM9, using MS Visual Studio 2005 (using MFC).

Basically, I want to make memory access faster, and do some bitwise operations.

It would be really helpful for me if I can get any online link, or some examples of using registers, variable names, pointers (some memory transfer and bitwise operations related stuff) etc for my particular environment.

EDIT after ctacke's answer:

It would be really helpful for me if there is any link or small examples to work out with .s files, specifically writing and exporting functions from .s, and steps involving in combining them with my MFC application. Any small example would do it.

Thank You.

Kind Regards, Aftab

1

There are 1 answers

0
ctacke On BEST ANSWER

The ARM compilers that ship with Visual Studio (all versions) do not support inline ASM - only the x86 compilers support inline ASM. To use ASM for ARM (or SH or MIPS as well) you have to create a separate code file (typically a .s file), export functions from your ASM and call those.

EDIT

Here's a simple example (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