Closed sy2002 closed 3 years ago
Thank you for asking!
The way this sequence of instructions is intended is that upon entry X is undefined. After SHL 1, R1
, this undefined X-value gets copied into bit 0 of R1. The second instruction ADDC R5, R5
does not change that, and the third instruction SHR 1, R1
moves bit 0 of R1 back into the X-register. The X-register is therefore still undefined (but unchanged from before this sequence!).
In other words, bit 0 of R1 will temporarily (for the duration of these few instructions) contain an undefined value in bit 0. But after the sequence, all bits in R1 should be well-defined.
I have at least convinced myself that this sequence of instructions is correct! If I've convinced you too, then you may close this issue.
Thanks for taking the time to explain it to me. Got it now. 👍 Closing.
Just being paranoid :-) Here is a question for you:
Do you need to clear the X flag at the beginning of MTH$RAND?
I am asking, because of this code snippet (but I need to admit that I did not understand, how the whole function works):
The very first time, the code flow reaches
SHL 1, R1
, the X flag is undefined as far as I have seen that. From the second iteration on, X is filled by theSHR 1, R1