Microsoft MakeCode

Assembler in extensions - subroutine question

Recently I wrote an assembler routine which I successfully incorporated into an extension alongside both Typescript and C++, using a .asm file, a .ts file and a .cpp file.

For fun I thought I would attempt a couple of other functions using Assembler and made good progress, getting 10% faster than the compiled C++ code in a few places.

However, when I attempted to write another assembler function which would call one of my previous assembler functions as a subroutine, it refuses to compile. Can anyone explain what I might be doing wrong?

The assembler functions and certain points in the code for branches and loops are labelled in the .asm file like this, with a dot for branch points and no dots for the function labels:

  push {r4,lr}
  various code
  bl pins::getPinAddress
  more code
  bne .loopstart
  pop {r4,pc}

Note that the function can do things such as call pins.getPinAddress. No problem
But if I create another function in the same .asm file something like this:

  push {r4,r5,r6,r7,lr}
  cmp r0, #1
  bne .out
  more code....
  bl myFunction
  pop {r4,r5,r6,pc}

There appears to be no way of getting the subroutine call bl myFunction to work. Does anyone know what I need to do to make it work?

Ugh, I discovered that I had exceeded the conditional branch offset by commenting/uncommenting the bl command in the second example, hence it either working or not!

The other problem is that the assembler parser is rather flakey. If you are not editing your TS or C++ files at all and just tweaking the assembler, you can find that pressing the Download button to compile the .hex file will not succeed the first time but will work the second time. There are some latency issues in the system which can mean that perfectly good code will fail to compile if you don’t let the system “catch its breath for a second”.