Extra problem 2 for HW 1

Dependencies:   mbed

Committer:
lzzcd001
Date:
Wed Feb 18 14:48:30 2015 +0000
Revision:
0:9b0b3bdf816e
Extra problem 2 for HW 1

Who changed what in which revision?

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