mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 21:11:12 +02:00
This commit adds support for writing inline assembler functions when targeting a RV32IMC processor. Given that this takes up a bit of rodata space due to its large instruction decoding table and its extensive error messages, it is enabled by default only on offline targets such as mpy-cross and the qemu port. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
34 lines
645 B
Python
34 lines
645 B
Python
# test the "data" directive
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def ret_num(a0) -> uint:
|
|
slli(a0, a0, 2)
|
|
addi(a0, a0, 16)
|
|
auipc(a1, 0)
|
|
add(a1, a1, a0)
|
|
lw(a0, 0(a1))
|
|
jal(zero, HERE)
|
|
data(4, 0x12345678, 0x20000000, 0x40000000, 0x7FFFFFFF + 1, (1 << 32) - 2)
|
|
label(HERE)
|
|
|
|
|
|
for i in range(5):
|
|
print(hex(ret_num(i)))
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def ret_num_la(a0) -> uint:
|
|
slli(a0, a0, 2)
|
|
la(a1, DATA)
|
|
add(a1, a1, a0)
|
|
lw(a0, 0(a1))
|
|
jal(zero, HERE)
|
|
label(DATA)
|
|
data(4, 0x12345678, 0x20000000, 0x40000000, 0x7FFFFFFF + 1, (1 << 32) - 2)
|
|
label(HERE)
|
|
|
|
|
|
for i in range(5):
|
|
print(hex(ret_num_la(i)))
|