updated the bulls and cows example
This commit is contained in:
+49
-50
@@ -8,53 +8,52 @@
|
||||
8 5 7 0 67
|
||||
9 5 8 0 68
|
||||
10 5 9 0 69
|
||||
11 5 1 0 50
|
||||
12 5 4 0 11
|
||||
13 5 60 0 70
|
||||
14 5 80 0 71
|
||||
15 5 10 0 3
|
||||
16 5 9 0 1
|
||||
17 15 0 1 1
|
||||
18 7 70 50 1
|
||||
19 5 2 0 2
|
||||
20 6 2 1 2
|
||||
21 8 2 3 4
|
||||
22 1 0 4 16
|
||||
23 2 0 3 1
|
||||
24 6 0 0 0
|
||||
25 6 1 11 1
|
||||
26 7 71 50 1
|
||||
27 5 2 0 5
|
||||
28 6 2 5 1
|
||||
29 8 11 50 11
|
||||
30 1 1 11 16
|
||||
31 5 0 1000 51
|
||||
32 5 7 0 11
|
||||
33 4 91 94 0
|
||||
34 5 90 0 70
|
||||
35 5 0 0 20
|
||||
36 5 4 0 21
|
||||
37 5 4 0 22
|
||||
38 6 1 21 15
|
||||
39 7 71 50 15
|
||||
40 6 1 22 16
|
||||
41 7 70 50 16
|
||||
42 2 15 16 50
|
||||
43 8 0 0 0
|
||||
44 1 5 1 50
|
||||
45 8 21 22 2
|
||||
46 1 5 2 49
|
||||
47 7 50 50 20
|
||||
48 1 6 0 50
|
||||
49 7 51 50 20
|
||||
50 8 22 50 22
|
||||
51 1 1 22 38
|
||||
52 8 21 50 21
|
||||
53 1 1 21 37
|
||||
54 3 20 20 0
|
||||
55 5 4 0 7
|
||||
56 8 20 7 1
|
||||
57 1 0 1 60
|
||||
58 8 11 50 11
|
||||
59 1 1 11 33
|
||||
60 3 81 84 0
|
||||
11 5 4 0 11
|
||||
12 5 60 0 70
|
||||
13 5 80 0 71
|
||||
14 5 10 0 3
|
||||
15 5 9 0 1
|
||||
16 15 0 1 1
|
||||
17 7 70 127 1
|
||||
18 5 2 0 2
|
||||
19 6 2 1 2
|
||||
20 8 2 3 4
|
||||
21 1 0 4 15
|
||||
22 2 0 3 1
|
||||
23 6 0 0 0
|
||||
24 6 1 11 1
|
||||
25 7 71 127 1
|
||||
26 5 2 0 5
|
||||
27 6 2 5 1
|
||||
28 8 11 127 11
|
||||
29 1 1 11 15
|
||||
30 5 0 1000 51
|
||||
31 5 7 0 11
|
||||
32 4 91 94 0
|
||||
33 5 90 0 70
|
||||
34 5 0 0 20
|
||||
35 5 4 0 21
|
||||
36 5 4 0 22
|
||||
37 6 1 21 15
|
||||
38 7 71 127 15
|
||||
39 6 1 22 16
|
||||
40 7 70 127 16
|
||||
41 2 15 16 127
|
||||
42 8 0 0 0
|
||||
43 1 5 1 49
|
||||
44 8 21 22 2
|
||||
45 1 5 2 48
|
||||
46 7 127 127 20
|
||||
47 1 6 0 49
|
||||
48 7 51 127 20
|
||||
49 8 22 127 22
|
||||
50 1 1 22 37
|
||||
51 8 21 127 21
|
||||
52 1 1 21 36
|
||||
53 3 20 20 0
|
||||
54 5 4 0 7
|
||||
55 8 20 7 1
|
||||
56 1 0 1 59
|
||||
57 8 11 127 11
|
||||
58 1 1 11 32
|
||||
59 3 81 84 0
|
||||
|
||||
+50
-51
@@ -6,7 +6,7 @@
|
||||
; 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 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
|
||||
@@ -16,53 +16,52 @@ 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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user