jim hamblen
/
C_to_asm
An example calling assembly from C. Assembly source is in a *.s file
main.cpp@0:ef242c5b2981, 2010-09-29 (annotated)
- Committer:
- 4180_1
- Date:
- Wed Sep 29 02:44:55 2010 +0000
- Revision:
- 0:ef242c5b2981
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:ef242c5b2981 | 1 | #include "mbed.h" |
4180_1 | 0:ef242c5b2981 | 2 | // This progam will blink LED1 and LED4 |
4180_1 | 0:ef242c5b2981 | 3 | // using assembly language for LED1 and |
4180_1 | 0:ef242c5b2981 | 4 | // API functions for LED4 |
4180_1 | 0:ef242c5b2981 | 5 | // declare external assembly language function (in a *.s file) |
4180_1 | 0:ef242c5b2981 | 6 | extern "C" int my_asm(int value); |
4180_1 | 0:ef242c5b2981 | 7 | // declare LED outputs |
4180_1 | 0:ef242c5b2981 | 8 | DigitalOut myled1(LED1); |
4180_1 | 0:ef242c5b2981 | 9 | DigitalOut myled4(LED4); |
4180_1 | 0:ef242c5b2981 | 10 | |
4180_1 | 0:ef242c5b2981 | 11 | int main() { |
4180_1 | 0:ef242c5b2981 | 12 | int value = 0; |
4180_1 | 0:ef242c5b2981 | 13 | // loop forever |
4180_1 | 0:ef242c5b2981 | 14 | while(1) { |
4180_1 | 0:ef242c5b2981 | 15 | //call assembly language function to control LED1 |
4180_1 | 0:ef242c5b2981 | 16 | my_asm(value); |
4180_1 | 0:ef242c5b2981 | 17 | //API function to control LED4 |
4180_1 | 0:ef242c5b2981 | 18 | myled4 = value; |
4180_1 | 0:ef242c5b2981 | 19 | // flip value and wait |
4180_1 | 0:ef242c5b2981 | 20 | value = ~ value; |
4180_1 | 0:ef242c5b2981 | 21 | wait(0.2); |
4180_1 | 0:ef242c5b2981 | 22 | } |
4180_1 | 0:ef242c5b2981 | 23 | } |