Files
mu808/examples/moo.mu8a
T

68 lines
3.5 KiB
Plaintext
Raw Normal View History

2025-04-22 20:02:27 +03:00
; 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
2025-04-30 13:37:40 +03:00
set 0 0 60 ; store digits 0 to 9 to locations 60 to 69
2025-04-22 20:02:27 +03:00
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
2025-04-30 13:37:40 +03:00
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 127 1 ; add the source base address to loc 1
set 2 0 2 ; init loc 2 with its own address
iva 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
jeq 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
dva 11 1 ; copy the counter into loc 1
fma 71 127 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
iva 5 1 ; indirectly copy the value from loc 2 to the address at loc 1
sub 11 127 11 ; decrement the counter at loc 11
jgt 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 dva 21 15 ; start of the inner loop; copy the outer counter
fma 71 127 15 ; shape the address of the target digit in loc 15
dva 22 16 ; copy the inner counter
fma 70 127 16 ; shape the address of the entered digit in loc 16
iat 15 16 127 ; prepare to save the digits difference into loc 1 (1 is stored at loc 127)
sub 0 0 0 ; do it
jne 1 :ei ; jump to the next comparator if the digits don't match
sub 21 22 2 ; save the _indices_ difference into loc 2
jne 2 :cc ; jump to the cow counter if the indices don't match
inc 20 ; increment the bull counter if they do
juc :ei ; skip the next instruction
:cc fma 51 127 20 ; increase the cow counter if they don't
:ei sub 22 127 22 ; decrease the inner loop counter
jgt 22 :ilp ; jump to the start of the inner loop if the inner counter is over zero
sub 21 127 21 ; decrease the outer loop counter
jgt 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
jeq 1 :end ; jump to the last instruction if they match
sub 11 127 11 ; decrement the attempt counter at loc 11
jgt 11 :prm ; jump to guess prompt if the counter is over zero
:end out 81 84 0 ; output the target number before halting