An example calling assembly from C. Assembly source is in a *.s file

Dependencies:   mbed

Committer:
4180_1
Date:
Wed Sep 29 02:44:55 2010 +0000
Revision:
0:ef242c5b2981

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:ef242c5b2981 1 AREA asm_func, CODE, READONLY
4180_1 0:ef242c5b2981 2 ; Export my_asm function location so that C compiler can find it and link
4180_1 0:ef242c5b2981 3 EXPORT my_asm
4180_1 0:ef242c5b2981 4 my_asm
4180_1 0:ef242c5b2981 5 ; ARM Assembly language function to set LED1 bit to a value passed from C
4180_1 0:ef242c5b2981 6 ; LED1 gets value (passed from C compiler in R0)
4180_1 0:ef242c5b2981 7 ; LED1 is on GPIO port 1 bit 18
4180_1 0:ef242c5b2981 8 ; See Chapter 9 in the LPC1768 User Manual
4180_1 0:ef242c5b2981 9 ; for all of the GPIO register info and addresses
4180_1 0:ef242c5b2981 10 ; Pinnames.h has the mbed modules pin port and bit connections
4180_1 0:ef242c5b2981 11 ;
4180_1 0:ef242c5b2981 12 ; Load GPIO Port 1 base address in register R1
4180_1 0:ef242c5b2981 13 LDR R1, =0x2009C020 ; 0x2009C020 = GPIO port 1 base address
4180_1 0:ef242c5b2981 14 ; Move bit mask in register R0 for bit 18 only
4180_1 0:ef242c5b2981 15 MOV.W R2, #0x040000 ; 0x040000 = 1<<18 all "0"s with a "1" in bit 18
4180_1 0:ef242c5b2981 16 ; value passed from C compiler code is in R0 - compare to a "0"
4180_1 0:ef242c5b2981 17 CMP R0, #0 ; value == 0 ?
4180_1 0:ef242c5b2981 18 ; (If-Then-Else) on next two instructions using equal cond flag
4180_1 0:ef242c5b2981 19 ITE EQ
4180_1 0:ef242c5b2981 20 ; STORE if EQ - clear led 1 port bit using GPIO FIOCLR register and mask
4180_1 0:ef242c5b2981 21 STREQ R2, [R1,#0x1C] ; if==0, clear LED1 bit
4180_1 0:ef242c5b2981 22 ; STORE if NE - set led 1 port bit using GPIO FIOSET register and mask
4180_1 0:ef242c5b2981 23 STRNE R2, [R1,#0x18] ; if==1, set LED1 bit
4180_1 0:ef242c5b2981 24 ; Return to C using link register (Branch and change instruction set)
4180_1 0:ef242c5b2981 25 BX LR
4180_1 0:ef242c5b2981 26 END