Assembly example.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Sat Mar 09 10:56:02 2019 +0000
Commit message:
Initial release.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
my_asm.s Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c40fd5b610ee main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Mar 09 10:56:02 2019 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+// This program will blink LED1 and LED4
+// using assembly language for LED1 and
+// API functions for LED4
+// declare external assembly language function (in a *.s file)
+extern "C" int my_asm(int value);
+// declare LED outputs – let C set them up as output bits
+DigitalOut myled1(LED1);
+DigitalOut myled4(LED4);
+ 
+int main() {
+
+    int value = 0;
+
+
+    // loop forever
+    while(1) {
+      //call assembly language function to control LED1
+      my_asm(value);
+      //API function to control LED4
+      myled4 = value;
+      // flip value and wait
+      value = ~ value;
+      wait(0.2);
+    }
+}
+ 
+ 
diff -r 000000000000 -r c40fd5b610ee mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Mar 09 10:56:02 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r c40fd5b610ee my_asm.s
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/my_asm.s	Sat Mar 09 10:56:02 2019 +0000
@@ -0,0 +1,31 @@
+    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
+ 
\ No newline at end of file