Using assembler routines in both JS and C++?

I understand how to call an assember routine from Javascript because there is a shim in a TS file that accompanies the assembler, such as the following, where one can also rename the function from myAssemberCode() to widget() for example.

namespace myextension {
    //% shim=myAssemberCode
    export function widget(args...) {

That’s straightforward. Assembly code can be used for time-critical Microbit pin output, for example.

But if my extension has a .cpp file rather than a .ts - or perhaps it even has both - I can’t see how to let C++ call the routine. What do I do, please?

You use the same shim annotation to call a C/C++ function. It may look like NAMESPACE::NAME if you use a namespace.

Thank you. I’ll try again in a minute. I thought I had already tried that with a //% shim=… in the cpp file but it didn’t work. It’s possible I might have made a typo in the shim that I simply failed to see. I’ve found previously that a consequence of things such as throwStickForMyDog() that you can miss the fact you’ve got a lowercase “f” by mistake despite staring at it for ten minutes.

Blimey, this just isn’t working and I have no idea why not.

Is it possible @peli you could help me on this, please? Nothing works and I haven’t the foggiest idea what I should be doing.

How do I call an assembly function in C++ code? It appears that the shims do not achieve this. I’ve tried every conceivable combination.

I’ve got this extension with a TS file, a CPP file and an ASM file. There is one namespace for the extension. I’ve put the relevant functions right at the top of the namespace declarations in the TS and CPP files for clarity. I have a byte-send and a buffer-send function in the ASM file.

The important code is lines 68 and 69 of the nokialcd.ts file. One is commented out, the other not. Both should do exactly the same thing: they call an assembler function. One is via TS, the other supposedly via a C wrapper. But the C version doesn’t work.

I cannot see how I can get the assembler function to be called within the C code. How do you do this, please?

The shim notation only work for linking TypeScript to C++ functions. They do not have any effect for C++ / ASM interaction.

We do not pass ASM files to the ARM compiler so you will need inline the assembly source into your C++ source file.

Aaah, I see. Are there some directives to precede and/or follow the block of assembler code when it’s in the CPP file?

Such as things explained here? :-

I’m not familiar with the details of inline asm in C++. You’ll have to console the ARM/GCC docs.

It’s rather disappointing that it’s not easy just to link to the assembler function in C as it is with TS. The documentaion for inline assembler makes it look rather restrictive.