-
-
Save whaleygeek/2ff467983b79c322b3d7a1764938d9d9 to your computer and use it in GitHub Desktop.
The MicroPython thumb assembly instructions are documented here: https://docs.micropython.org/en/latest/reference/asm_thumb2_index.html
The simulator at python.microbit.org won't run the assembly instructions, but it does flash and run fine on the micro:bit even though there are lots of red marks over it all!
MakeCode shims mentioned here, that can call assembly language code from javascript code: https://forum.makecode.com/t/using-assembler-routines-in-both-js-and-c/2155
MakeCode extensions here (neopixel is a good example as it has assembly code in it as well): https://makecode.com/extensions
.asm files can't be added at present: microsoft/pxt-microbit#4426
The red underlining in the python.microbit.org editor for the asm lines can be removed with this fix:
42 in ASCII is a '*', this prints ABC then *BC, the assembly program has stored a 42 in the first memory location of the buffer data. id(b) is the bytearray address, the third longword32 of that memory holds the address of the actual buffer data.
# pyright: reportGeneralTypeIssues=false, reportUndefinedVariable=false
from machine import mem8, mem32
@micropython.asm_thumb
def ultimate_answer(r0):
mov(r1,42)
strb(r1,[r0,0])
b = bytearray(b'ABC')
print("before", b)
ITEMS_ADDR = mem32[id(b)+(4*3)]
ultimate_answer(ITEMS_ADDR)
print("after", b)
@carlosperate has some nice MicroPython examples here: https://gist.github.com/microbit-carlos?direction=asc&sort=created