A Game of NIM
  1. Start with 23 dots in DOTS.
  2. My first move is always 2.
  3. Store my move in MYGO.
  4. Display it.
  5. Subtract MYGO from DOTS.
  6. Check if DOTS is now ONE.
  7. Get your move in YRGO.
  8. Subtract YRGO from DOTS.
  9. Calculate my move by subtracting your move from 4.
  10. Go to step 3.
Note that this program does not validate the other player's input ... so cheating is possible! But it really won't help because the program cheats right back!

I will indicate "I Win!" by "1111" - the closest I can get to four exclamation marks.


 LDA #23
 STA DOTS
 LDA #2
LOOP: STA MYGO
 OUT MYGO
 LDA DOTS
 SUB MYGO
 STA DOTS
 SUB #1
 BEQ IWIN
 INP YRGO
 LDA DOTS
 SUB YRGO
 STA DOTS
 LDA #4
 SUB YRGO
 JMP LOOP
IWIN: LDA #1111
 STA WIN
 OUT WIN
 HLT

LDA #23
STA DOTS
LDA #2
LOOP: STA MYGO
OUT MYGO
LDA DOTS
SUB MYGO
STA DOTS
SUB #1
BEQ IWIN
INP YRGO
LDA DOTS
SUB YRGO
STA DOTS
LDA #4
SUB YRGO
JMP LOOP
IWIN: LDA #1111
STA WIN
OUT WIN
HLT

Assembler