Created
March 20, 2024 21:33
-
-
Save whaleygeek/2ff467983b79c322b3d7a1764938d9d9 to your computer and use it in GitHub Desktop.
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)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!
![Screenshot 2024-03-20 at 22 10 26](https://private-user-images.githubusercontent.com/4086785/314693199-7564a637-bcc2-4d8b-a6fb-b7e9fbcef160.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyMjEzMDQsIm5iZiI6MTcyMTIyMTAwNCwicGF0aCI6Ii80MDg2Nzg1LzMxNDY5MzE5OS03NTY0YTYzNy1iY2MyLTRkOGItYTZmYi1iN2U5ZmJjZWYxNjAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MTdUMTI1NjQ0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTEzZTYwNWFlMzM1MDljNTQwODNhZWIxNjY4ZDhjMjA1ZDZjMzBhMTQ2Y2Y0ZDc4NmQyYTA5NWQwMDk1MzU3NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.beuq4dKd3QkNPYuC68-vWkawNB9L1TyGS2KNqjKIRTc)