I'd like to load a 32bit constant into a register, but haven't found a way to do that yet.
I've also made labels and branches to jump around around data() statements, and haven't been able to load a register with an address relative to the PC.
What HAS worked, is moving PC (r15) to a low register, subtracting 4 two times (because it insists there's no #imm8 with adds or subs), and indirecting fetch twice (first to get the register address, second to read the register).
Here's the other things I've tried, with the errors they gave:
# ldr(r0, [pc, #0]) # thonny doesn't recognize; pico gives invalid syntax
instruction LDR Rd, [Rn, #imm] nope
instruction LDR Rd, [PC, imm8] nope
# ldr(r0, TBASE) # unsupported Thumb instruction 'ldr' with 2 arguments
instruction LDR Rd, label nope
# adr(r0, DATA) # unsupported Thumb instruction 'adr' with 2 arguments
instruction ADR Rd, label nope
Probably because it's an ARM assembler pseudo-instruction?
# add(r0,r0,-8) # 'add' integer 0xfffffff8 doesn't fit in mask
instruction ADDS Rd, RD, #imm8 nope
Even though the document for the instruction says it has an 8-bit immediate field.
It's shorter to pass the address to a little fetcher routine:
Code: Select all
@micropython.asm_thumb
def readreg(r0):
ldr(r0, [r0,0])
Thanks!