ARM assembly language to control LEDs

Dependencies:   mbed

Fork of ECE_4180_Lab1_P1_Arm by Zack Braun

Committer:
jboettcher
Date:
Sun Nov 06 22:36:01 2016 +0000
Revision:
1:1d27be3b634d
Parent:
0:94cb0da877bc
complete;

Who changed what in which revision?

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