Zoltan Hudak
/
Asm01
Assembly example.
my_asm.s@0:c40fd5b610ee, 2019-03-09 (annotated)
- Committer:
- hudakz
- Date:
- Sat Mar 09 10:56:02 2019 +0000
- Revision:
- 0:c40fd5b610ee
Initial release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:c40fd5b610ee | 1 | AREA asm_func, CODE, READONLY |
hudakz | 0:c40fd5b610ee | 2 | |
hudakz | 0:c40fd5b610ee | 3 | ; Export my_asm function location so that C compiler can find it and link |
hudakz | 0:c40fd5b610ee | 4 | |
hudakz | 0:c40fd5b610ee | 5 | |
hudakz | 0:c40fd5b610ee | 6 | EXPORT my_asm |
hudakz | 0:c40fd5b610ee | 7 | my_asm |
hudakz | 0:c40fd5b610ee | 8 | ; |
hudakz | 0:c40fd5b610ee | 9 | ; ARM Assembly language function to set LED1 bit to a value passed from C |
hudakz | 0:c40fd5b610ee | 10 | ; LED1 gets value (passed from C compiler in R0) |
hudakz | 0:c40fd5b610ee | 11 | ; LED1 is on GPIO port 1 bit 18 |
hudakz | 0:c40fd5b610ee | 12 | ; See Chapter 9 in the LPC1768 User Manual |
hudakz | 0:c40fd5b610ee | 13 | ; for all of the GPIO register info and addresses |
hudakz | 0:c40fd5b610ee | 14 | ; Pinnames.h has the mbed modules pin port and bit connections |
hudakz | 0:c40fd5b610ee | 15 | ; |
hudakz | 0:c40fd5b610ee | 16 | ; Load GPIO Port 1 base address in register R1 |
hudakz | 0:c40fd5b610ee | 17 | LDR R1, =0x2009C020 ; 0x2009C020 = GPIO port 1 base address |
hudakz | 0:c40fd5b610ee | 18 | ; Move bit mask in register R2 for bit 18 only |
hudakz | 0:c40fd5b610ee | 19 | MOV.W R2, #0x040000 ; 0x040000 = 1<<18 all "0"s with a "1" in bit 18 |
hudakz | 0:c40fd5b610ee | 20 | ; value passed from C compiler code is in R0 - compare to a "0" |
hudakz | 0:c40fd5b610ee | 21 | CMP R0, #0 ; value == 0 ? |
hudakz | 0:c40fd5b610ee | 22 | ; (If-Then-Else) on next two instructions using equal cond from the zero flag |
hudakz | 0:c40fd5b610ee | 23 | ITE EQ |
hudakz | 0:c40fd5b610ee | 24 | ; STORE if EQ - clear led 1 port bit using GPIO FIOCLR register and mask |
hudakz | 0:c40fd5b610ee | 25 | STREQ R2, [R1,#0x1C] ; if==0, clear LED1 bit |
hudakz | 0:c40fd5b610ee | 26 | ; STORE if NE - set led 1 port bit using GPIO FIOSET register and mask |
hudakz | 0:c40fd5b610ee | 27 | STRNE R2, [R1,#0x18] ; if==1, set LED1 bit |
hudakz | 0:c40fd5b610ee | 28 | ; Return to C using link register (Branch indirect using LR - a return) |
hudakz | 0:c40fd5b610ee | 29 | BX LR |
hudakz | 0:c40fd5b610ee | 30 | END |
hudakz | 0:c40fd5b610ee | 31 |