Copy and paste into main.cpp: #include "mbed.h" extern "C" int asm_func(int number); int number = 42; int main() { printf("Before: %d \n\r", number); number = asm_func(number); printf("\n\rAfter: %d\n\r", number); while(1) {} } Copy and paste into asm_func.s: AREA asm_demo, CODE, READONLY ; Export asm_func function location so that C compiler can find it and link EXPORT asm_func asm_func ; Value is in R0 PUSH {R2} ;Save incoming register value AND R2, R2, #0 ;Set R2 to 0 ADD R2, R0, R0 ;Set R2 TO R0 + R0 SUB R2, R2, #1 ;Decrement R2 MOV R0, R2 ;Put result back in R0 POP {R2} ;Restore incoming register BX LR ;Return ALIGN END