; Bulls and Cows game in MU8A for mu808 VM ; Enter your guesses digit by digit, you have 7 attempts ; After each guess, the game replies with bulls.cows ; (if you have 4.0, you win) ; On victory or after running out of attempts, the game ; displays the target digits and halts ; Created by Luxferre in 2025, released into public domain set 0 0 60 ; store digits 0 to 9 to locations 60 to 69 set 1 0 61 set 2 0 62 set 3 0 63 set 4 0 64 set 5 0 65 set 6 0 66 set 7 0 67 set 8 0 68 set 9 0 69 set 1 0 50 ; store 1 into loc 50 set 4 0 11 ; store the counter to loc 11 set 60 0 70 ; store the source base address 60 to loc 70 set 80 0 71 ; store the target base address 80 to loc 71 set 10 0 3 ; store the constant 10 to loc 3 :dsl set 9 0 1 ; store the upper boundary to loc 1 rnd 0 1 1 ; store a random digit into loc 1 fma 70 50 1 ; add the source base address to loc 1 set 2 0 2 ; init loc 2 with its own address cpy 2 1 2 ; read the value at that loc 1 address back into loc 2 sub 2 3 4 ; subtract 10 from the read value into loc 4 jmp 0 4 :dsl ; jump back to digit selection if the value at loc 4 is zero iat 0 3 1 ; enable indirect addressing to... cpy 0 0 0 ; ...set the value at the address still at loc 1 to 10 cpy 1 11 1 ; copy the counter into loc 1 fma 71 50 1 ; add the counter and the target base address (result is 81..84 at loc 1) set 2 0 5 ; set the constant 2 into loc 5 cpy 2 5 1 sub 11 50 11 ; decrement the counter at loc 11 jmp 1 11 :dsl ; jump back to digit selection if the counter is over zero set 0 1000 51 ; store 0.1 to loc 51 set 7 0 11 ; the number to guess is at loc 81..84; store the attempt counter to loc 11 :prm inp 91 94 0 ; prompt the player to enter the number digit by digit into loc 91 to 94 set 90 0 70 ; store the entered digits base address to loc 70 set 0 0 20 ; init bull/cow counter at loc 20 set 4 0 21 ; init outer loop counter at loc 21 :olp set 4 0 22 ; start of the outer loop; init inner loop counter at loc 22 :ilp cpy 1 21 15 ; start of the inner loop; copy the outer counter fma 71 50 15 ; shape the address of the target digit in loc 15 cpy 1 22 16 ; copy the inner counter fma 70 50 16 ; shape the address of the entered digit in loc 16 iat 15 16 50 ; prepare to save the digits difference into loc 1 (1 is stored at loc 50) sub 0 0 0 ; do it jmp 5 1 :ei ; jump to the next comparator if the digits don't match sub 21 22 2 ; save the _indices_ difference into loc 2 jmp 5 2 :cc ; jump to the cow counter if the indices don't match fma 50 50 20 ; increase the bull counter if they do jmp 6 0 :ei ; skip the next instruction :cc fma 51 50 20 ; increase the cow counter if they don't :ei sub 22 50 22 ; decrease the inner loop counter jmp 1 22 :ilp ; jump to the start of the inner loop if the inner counter is over zero sub 21 50 21 ; decrease the outer loop counter jmp 1 21 :olp ; jump to the start of the outer loop if the outer counter is over zero out 20 20 0 ; output the match result set 4 0 7 ; store the constant 4.0 at loc 7 sub 20 7 1 ; store the difference between the result and 4 to loc 1 jmp 0 1 :end ; jump to the last instruction if they match sub 11 50 11 ; decrement the attempt counter at loc 11 jmp 1 11 :prm ; jump to guess prompt if the counter is over zero :end out 81 84 0 ; output the target number before halting