6502, ai 

I was playing with a 6502 genetic programmer and as a test I asked it to make me a program that does Collatz iteration on A register (x -> x/2 if x is even, 3x+1 if x is odd), and it came up with this cutie:

```
* = 8000
8000 85 00 STA $00
8002 6A ROR A
8003 90 03 BCC $8008
8005 65 00 ADC $00
8007 0A ASL A
8008 60 RTS
8009 .END
```

explanation re: 6502, ai 

- put the value of A in memory (at address $00)
- rotate A right (ie divide by 2 and if doesn't divide evenly set the carry flag)
- if carry flag set, jump to the end (we're done)
- add the value from memory (original value of A) to A, with +1 due to carry (which is set); A is now original_A + A/2-1/2 (because we're rounding down) + 1 = original_A + A/2 + 1/2
- shift A left (ie multiply by 2); A is now 3 * original_A + 1
- return

Show thread
Follow

re: explanation re: 6502, ai 

correction: if carry flag NOT set, jump to the end

Sign in to participate in the conversation
Computer Fairies

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!