ref: 4b68ddfb5a004f97f60219399878d14635e73fdb
parent: ca47fef0061954cda2355cc10dba774d6567051e
author: spew <devnull@localhost>
date: Tue Jan 17 15:51:08 EST 2017
games/mix: document -g option, rename tests to examples as it is in the man page
--- a/sys/man/1/mix
+++ b/sys/man/1/mix
@@ -6,6 +6,9 @@
.SH SYNOPSIS
.B games/mix
[
+.B -g
+]
+[
.I file ...
]
.SH DESCRIPTION
@@ -18,7 +21,11 @@
files into memory and then presents a command
prompt to control an emulated
.B MIX
-machine.
+machine. The
+.B -g
+option causes the emulator immediately to run a complete assembled
+.B MIX
+program and exits the emulator when the emulator halts.
.PP
The following commands are accepted:
.TP
--- /dev/null
+++ b/sys/src/games/mix/examples/maximum.m
@@ -1,0 +1,14 @@
+# Entry condition R1 = n.
+# Exit: RA = max R2 = index of max in X
+X EQU 1000
+ORIG 3000
+MAXIMUM STJ EXIT # Subroutine linkage.
+INIT ENT3 0,1 # M1. Initialize k ← n.
+ JMP CHANGEM # j ← n, m ← X[n], k ← n-1.
+LOOP CMPA X,3 # M3. Compare.
+ JGE *+3 # To M5 if m ≥ X[k].
+CHANGEM ENT2 0,3 # M4. Change m. j ← k.
+ LDA X,3 # m ← X[k].
+ DEC3 1 # M5. Decrease k.
+ J3P LOOP # M2. All tested? To M3 if k > 0.
+EXIT JMP * # Return to main program.
--- /dev/null
+++ b/sys/src/games/mix/examples/maxmain.m
@@ -1,0 +1,25 @@
+ ORIG X
+ CON 0
+ CON 3910
+ CON 23
+ CON -45
+ CON 310
+ CON 475
+ CON 40291
+ CON 358
+ CON 20912
+RESULT ALF "MAX: "
+ CON 0
+ ALF " AT: "
+ CON 0
+ ORIG EXIT+1
+MAIN ENT1 RESULT-X-1
+ JMP MAXIMUM
+ CHAR
+ STX RESULT+1
+ ENTA ,2
+ CHAR
+ STX RESULT+3
+ OUT RESULT(19)
+ HLT
+ END MAIN
--- /dev/null
+++ b/sys/src/games/mix/examples/primes.m
@@ -1,0 +1,49 @@
+L EQU 500
+PRINTER EQU 18
+PRIME EQU -1
+BUF0 EQU 2000
+BUF1 EQU BUF0+25
+ ORIG 3000
+START IOC 0(PRINTER)
+ LD1 =1-L=
+ LD2 =3=
+2H INC1 1
+ ST2 PRIME+L,1
+ J1Z 2F
+4H INC2 2
+ ENT3 2
+6H ENTA 0
+ ENTX 0,2
+ DIV PRIME,3
+ JXZ 4B
+ CMPA PRIME,3
+ INC3 1
+ JG 6B
+ JMP 2B
+2H OUT TITLE(PRINTER)
+ ENT4 BUF1+10
+ ENT5 -50
+2H INC5 L+1
+4H LDA PRIME,5
+ CHAR
+ STX 0,4(1:4)
+ DEC4 1
+ DEC5 50
+ J5P 4B
+ OUT 0,4(PRINTER)
+ LD4 24,4
+ J5N 2B
+ HLT
+ORIG PRIME+1
+ CON 2
+ ORIG BUF0-5
+TITLE ALF "FIRST"
+ ALF " FIVE"
+ ALF " HUND"
+ ALF "RED P"
+ ALF "RIMES"
+ ORIG BUF0+24
+ CON BUF1+10
+ ORIG BUF1+24
+ CON BUF0+10
+ END START
--- a/sys/src/games/mix/repl.c
+++ b/sys/src/games/mix/repl.c
@@ -211,7 +211,7 @@
Binit(&bin, 0, OREAD);
- if(go) {
+ if(go && vmstart != -1) {
once = 0;
goto Go;
}
@@ -277,6 +277,8 @@
vmstart = mixvm(vmstart, once);
else
break;
+ if(go)
+ exits(nil);
if(vmstart == -1)
print("halted\n");
else