Created
March 20, 2024 21:33
-
-
Save whaleygeek/2ff467983b79c322b3d7a1764938d9d9 to your computer and use it in GitHub Desktop.
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 red underlining in the python.microbit.org editor for the asm lines can be removed with this fix:
microbit-foundation/python-editor-v3#774 (comment)