Closed urish closed 3 years ago
One effect of this bug, found by @sutaburosu:
Running MicroPython and typing in the following code will result in a weird error:
>>> def factorial(x):
... if x == 0:
... return 1
... r = x * factorial(x-1)
... return r
...
...
>>> factorial(5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in factorial
File "<stdin>", line 4, in factorial
File "<stdin>", line 4, in factorial
File "<stdin>", line 4, in factorial
File "<stdin>", line 5, in factorial
NameError: local variable referenced before assignment
>>>
Can confirm the currently deployed changes fix this issue. Thanks, Uri.
The STR instruction has a form where you can specify base register + offset register, e.g.
It's possible to use a negative offset value (e.g. -4), and the target address will still be correct as the result should wrap at 32 bits. This doesn't work correctly in the current implementation. The following test case passes on the physical hardware but fails in the emulator:
I suspect that a similar bug exists for other instructions that accept a memory address in the form of base register + offset register, e.g. STRH, STRB, LDR, LDRB, LDRH, LDRS, LDRSB.