I've got a little challenge for you all to try to figure out.

Here's a short Atom machine code program.

Code: Select all

```
10 DIM LL10
20 P=#2800
30[
40:LL0
50 LDA @#80
60 CLC
70 ADC #B002
80 BCS LL0
90 BMI LL0
100 RTS
110]
120 LINK #2800
130 P.$7
140 END
```

Code: Select all

```
2800 :LL0
2800 A9 80 LDA @#80
2802 18 CLC
2803 6D 02 B0 ADC #B002
2806 B0 F8 BCS LL0
2808 30 F6 BMI LL0
280A 60 RTS
```

Why?

Because program will only exit if C=0 and N=0 after the ADC. But because the accumulator is starting off at #80, this condition should be impossible.

i.e. Any value in #B002 that is large enough to cause the accumulator to become positive again should also have caused carry to be set.

You can work through the two cases in more detail:

- if #B002 was in the range #00..#7F, then C=0 and the result is #80-#FF so N=1

- if #B002 was in the range #80..#FF, then C=1 and the result is #00-#7F so N=0

On Atomulator it never exits.

But on a real Atom, after some time (maybe hours) it will eventually exit.

How can this be possible?

Dave