diff --git a/sys/man/1/mix b/sys/man/1/mix index 54a443200..88668d70d 100644 --- a/sys/man/1/mix +++ b/sys/man/1/mix @@ -6,6 +6,9 @@ assembler and emulator .SH SYNOPSIS .B games/mix [ +.B -g +] +[ .I file ... ] .SH DESCRIPTION @@ -18,7 +21,11 @@ architecture. The command assembles the named 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 diff --git a/sys/src/games/mix/examples/maximum.m b/sys/src/games/mix/examples/maximum.m new file mode 100644 index 000000000..65c611692 --- /dev/null +++ b/sys/src/games/mix/examples/maximum.m @@ -0,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. diff --git a/sys/src/games/mix/examples/maxmain.m b/sys/src/games/mix/examples/maxmain.m new file mode 100644 index 000000000..42c57a67d --- /dev/null +++ b/sys/src/games/mix/examples/maxmain.m @@ -0,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 diff --git a/sys/src/games/mix/examples/primes.m b/sys/src/games/mix/examples/primes.m new file mode 100644 index 000000000..31b7b86f0 --- /dev/null +++ b/sys/src/games/mix/examples/primes.m @@ -0,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 diff --git a/sys/src/games/mix/repl.c b/sys/src/games/mix/repl.c index fa10b2aae..323e5507e 100644 --- a/sys/src/games/mix/repl.c +++ b/sys/src/games/mix/repl.c @@ -211,7 +211,7 @@ repl(int go) Binit(&bin, 0, OREAD); - if(go) { + if(go && vmstart != -1) { once = 0; goto Go; } @@ -277,6 +277,8 @@ repl(int go) vmstart = mixvm(vmstart, once); else break; + if(go) + exits(nil); if(vmstart == -1) print("halted\n"); else