Subleq: Difference between revisions

2,141 bytes added ,  1 year ago
m
syntax highlighting fixup automation
(add BQN)
m (syntax highlighting fixup automation)
Line 51:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F subleq(&a)
V i = 0
L i >= 0
Line 66:
 
subleq(&[15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 72,
101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0])</langsyntaxhighlight>
 
{{out}}
Line 75:
=={{header|8080 Assembly}}==
 
<langsyntaxhighlight lang="8080asm"> ;;; ---------------------------------------------------------------
;;; SUBLEQ for CP/M. The word size is 16 bits, and the program
;;; is given 16 Kwords (32 KB) of memory. (If the system doesn't
Line 419:
emem: db 'Memory error$'
einv: db 'Invalid integer: '
eiloc: db ' $' </langsyntaxhighlight>
 
=={{header|8086 Assembly}}==
Line 425:
This program reads a file given on the command line. Optional CR/LF translation is included, for SUBLEQ programs that expect the UNIX line ending convention. The word size is 16 bits, and the program is given 64 KB (32 Kwords) of memory.
 
<langsyntaxhighlight lang="asm"> ;;; -------------------------------------------------------------
;;; SUBLEQ interpreter that runs under MS-DOS.
;;; The word size is 16 bits, and the SUBLEQ program gets a 64KB
Line 714:
fbuf: resb RBUFSZ ; File buffer
stack: resw 128 ; 128 words for main stack (should be enough)
memtop: equ $</langsyntaxhighlight>
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
 
procedure Subleq is
Line 784:
Execute_Program(Memory);
end Subleq;</langsyntaxhighlight>
 
<pre>>./subleq
Line 792:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68"># Subleq program interpreter #
# executes the program specified in code, stops when the instruction pointer #
# becomes negative #
Line 839:
)
)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 847:
=={{header|ALGOL W}}==
{{Trans|Algol 68}}
<langsyntaxhighlight lang="algolw">% Subleq program interpreter %
begin
 
Line 912:
end
 
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 920:
{{works with|GNU APL}}
 
<langsyntaxhighlight APLlang="apl">#!/usr/local/bin/apl -s --
⎕IO←0 ⍝ Index origin 0 is more intuitive with 'pointers'
∇Subleq;fn;text;M;A;B;C;X
Line 949:
Subleq
)OFF
</syntaxhighlight>
</lang>
 
 
=={{header|ARM Assembly}}==
<syntaxhighlight lang="text"> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@ ARM SUBLEQ for Linux @@@
@@@ Word size is 32 bits. The program is @@@
Line 1,101:
prog: .space 0x400000 @ Lower half of program memory
fbuf: .space 0x400000 @ File buffer and top half of program memory
mem_end = .</langsyntaxhighlight>
 
{{out}}
Line 1,111:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SUBLEQ.AWK SUBLEQ.TXT
# converted from Java
Line 1,154:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,166:
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="gwbasic">10 DEFINT A-Z: DIM M(8192)
20 INPUT "Filename";F$
30 OPEN "I",1,F$
Line 1,184:
180 GOTO 90
190 IF M(A)=10 THEN PRINT ELSE PRINT(CHR$(M(A) AND 255));
200 GOTO 90</langsyntaxhighlight>
{{out}}
<pre>Filename? HELLO.SUB
Line 1,191:
=={{header|BBC BASIC}}==
The BBC BASIC implementation reads the machine code program as a string from standard input and stores it in an array of signed 32-bit integers. The default size of the array is 256, but other values could easily be substituted. No attempt is made to handle errors arising from invalid Subleq programs.
<langsyntaxhighlight lang="bbcbasic">REM >subleq
DIM memory%(255)
counter% = 0
Line 1,218:
ENDIF
ENDIF
UNTIL counter% < 0</langsyntaxhighlight>
 
Output:
Line 1,225:
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
// Read a string
Line 1,303:
freevec(mem)
$)
$)</langsyntaxhighlight>
{{out}}
<pre>Filename? hello.sub
Line 1,315:
Also note that in some buggy interpreters you may need to pad the Befunge playfield with additional blank lines or spaces in order to initialise a writable memory area (without which the Subleq source may fail to load).
 
<langsyntaxhighlight lang="befunge">01-00p00g:0`*2/00p010p0>$~>:4v4:-1g02p+5/"P"\%"P":p01+1:g01+g00*p02+1_v#!`"/":<
\0_v#-"-":\1_v#!`\*84:_^#- *8< >\#%"P"/#:5#<+g00g-\1+:"P"%\"P"v>5+#\*#<+"0"-~>^
<~0>#<$#-0#\<>$0>:3+\::"P"%\"P"/5+g00g-:1+#^_$:~>00gvv0gp03:+5/"P"\p02:%"P":< ^
>>>>>> , >>>>>> ^$p+5/"P"\%"P":-g00g+5/"P"\%"P":+1\+<>0g-\-:0v>5+g00g-:1+>>#^_$
-:0\`#@_^<<<<<_1#`-#0:#p2#g5#08#3*#g*#0%#2\#+2#g5#08#<**/5+g00g</langsyntaxhighlight>
 
{{out}}
Line 1,328:
Since Subleq programs can potentially run forever, this program prints each character with a newline.
 
<langsyntaxhighlight lang="bqn">
# Helpers
_while_ ← {𝔽⍟𝔾∘𝔽_𝕣_𝔾∘𝔽⍟𝔾𝕩}
Line 1,345:
}
 
Subleq ToNum¨•args</langsyntaxhighlight>
<syntaxhighlight lang="text">$ cbqn subleq.bqn 15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0
H
e
Line 1,360:
d
!
</syntaxhighlight>
</lang>
 
=={{header|C}}==
Takes the subleq instruction file as input, prints out usage on incorrect invocation.
<langsyntaxhighlight Clang="c">#include <stdlib.h>
#include <stdio.h>
 
Line 1,413:
return 0;
}
</syntaxhighlight>
</lang>
Input file (subleqCode.txt), first row contains the number of code points ( integers in 2nd row):
<pre>
Line 1,427:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
 
namespace Subleq {
Line 1,463:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Hello, world!</pre>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <fstream>
#include <iostream>
Line 1,515:
return 0;
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,524:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">% Read numbers from a stream
read_nums = iter (s: stream) yields (int)
while true do
Line 1,613:
stream$close(file)
subleq(m, pi, po)
end start_up</langsyntaxhighlight>
{{out}}
<pre>$ cat hello.sub
Line 1,622:
=={{header|COBOL}}==
For compatibility with online COBOL compilers, where file IO is not supported, this implementation reads the Subleq program from the console. Note that COBOL tables (arrays) are indexed from 1 rather than 0, and so are character sets: in an ASCII environment 'A' is coded as 66 (the sixty-sixth character), not 65.
<langsyntaxhighlight lang="cobol">identification division.
program-id. subleq-program.
data division.
Line 1,702:
if memory(adjusted-index-b) is equal to zero
or memory(adjusted-index-b) is negative
then move c to instruction-pointer.</langsyntaxhighlight>
{{out}}
<pre>READING SUBLEQ PROGRAM... 0032 WORDS READ.
Line 1,712:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defun run (memory)
(loop for pc = 0 then next-pc
until (minusp pc)
Line 1,732:
(let ((memory (vector 15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72
101 108 108 111 44 32 119 111 114 108 100 33 10 0)))
(run memory)))</langsyntaxhighlight>
{{out}}<pre>Hello, world!</pre>
 
=={{header|D}}==
<langsyntaxhighlight Dlang="d">import std.stdio;
 
void main() {
Line 1,768:
instructionPointer += 3;
} while (instructionPointer >= 0);
}</langsyntaxhighlight>
 
{{out}}
Line 1,775:
=={{header|Delphi}}==
{{Trans|Java}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program SubleqTest;
 
Line 1,820:
readln;
end.
</syntaxhighlight>
</lang>
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">\util.g
 
proc nonrec rdch() byte:
Line 1,883:
fi
od
corp</langsyntaxhighlight>
{{out}}
<pre>A>type hello.sub
Line 1,893:
=={{header|Forth}}==
Note that Forth is stack oriented. Hence, the code is toggled in in reverse.
<syntaxhighlight lang="text">create M 32 cells allot
 
: enter refill drop parse-word evaluate ; : M[] cells M + ;
Line 1,906:
-1 0 0 15 15 -1 3 16 -1 1 16 -1 -1 17 -1 17 15
 
init subleq</langsyntaxhighlight>
{{out}}
<pre>init subleq
Line 1,919:
But Fortran 90 introduced the ability to specify the lower bounds of an array, so MEM(0:LOTS) is available without difficulty, and formulae may be translated with greater ease: handling offsets is a simple clerical task; computers excel at simple clerical tasks, so, let the computer do it. Otherwise, the following code would work with F77, except possibly for the odd usage of $ in a FORMAT statement so that each character of output is not on successive lines.
 
<syntaxhighlight lang="fortran">
<lang Fortran>
PROGRAM SUBLEQ0 !Simulates a One-Instruction computer, with Subtract and Branch if <= 0.
INTEGER LOTS,LOAD !Document some bounds.
Line 1,949:
IF (IAR.GE.0) GO TO 100 !Keep at it.
END !That was simple.
</syntaxhighlight>
</lang>
For simplicity there are no checks on memory bounds or endless looping, nor any trace output. The result is
<pre>
Line 1,958:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
Dim As Integer memoria(255), contador = 0
Dim As String codigo, caracter
Line 1,990:
Loop Until contador < 0
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,999:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,045:
log.Fatalln("write:", err)
}
}</langsyntaxhighlight>
A much longer version using types, methods, etc
and that supports supplying a program via a file or the command line,
Line 2,053:
=={{header|Haskell}}==
Inspired by the Racket solution.
<langsyntaxhighlight Haskelllang="haskell">{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.State
import Data.Char (chr, ord)
Line 2,082:
zip [0..]
[15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33, 10, 0]
</syntaxhighlight>
</lang>
 
=={{header|J}}==
 
<langsyntaxhighlight Jlang="j">readchar=:3 :0
if.0=#INBUF do. INBUF=:LF,~1!:1]1 end.
r=.3 u:{.INBUF
Line 2,112:
end.
OUTBUF
)</langsyntaxhighlight>
 
Example:
 
<langsyntaxhighlight Jlang="j"> subleq 15 17 _1 17 _1 _1 16 1 _1 16 3 _1 15 15 0 0 _1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0
Hello, world!</langsyntaxhighlight>
 
=={{header|Janet}}==
<langsyntaxhighlight lang="clojure">(defn main [& args]
(let [filename (get args 1)
fh (file/open filename)
Line 2,141:
(put memory b (- (get memory b) (get memory a)))
(if (<= (get memory b) 0)
(set pc c))))))))</langsyntaxhighlight>
 
{{Out}}
Line 2,149:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.util.Scanner;
 
public class Subleq {
Line 2,183:
} while (instructionPointer >= 0);
}
}</langsyntaxhighlight>
 
<pre>Hello, world!</pre>
Line 2,198:
or some post-processing. The output shown below assumes the -j
(--join-output) command-line option is available.
<langsyntaxhighlight lang="jq"># If your jq has while/2 then the following definition can be omitted:
def while(cond; update):
def _while: if cond then ., (update | _while) else empty end;
Line 2,229:
 
subleq([15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1,
72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0])</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">$ jq -r -j -n -f subleq.jq
Hello, world!</langsyntaxhighlight>
 
=={{header|Julia}}==
Line 2,238:
 
'''Module''':
<langsyntaxhighlight lang="julia">module Subleq
using OffsetArrays
Line 2,268:
end # module Subleq
</syntaxhighlight>
</lang>
 
'''Main''':
<langsyntaxhighlight lang="julia">using .Subleq
 
print(Subleq.interpret("15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101
108 108 111 44 32 119 111 114 108 100 33 10 0"))
</langsyntaxhighlight>{{out}}
<pre>
Hello, world!
Line 2,281:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
 
fun subleq(program: String) {
Line 2,311:
val program = "15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0"
subleq(program)
}</langsyntaxhighlight>
 
{{out}}
Line 2,319:
 
=={{header|Logo}}==
<langsyntaxhighlight lang="logo">make "memory (array 32 0)
 
to load_subleq
Line 2,357:
load_subleq
run_subleq
bye</langsyntaxhighlight>
 
{{Out}}
Line 2,366:
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">function subleq (prog)
local mem, p, A, B, C = {}, 0
for word in prog:gmatch("%S+") do
Line 2,387:
end
 
subleq("15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0")</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
{{trans|R}}
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[memory, MemoryGet, MemorySet, MemorySubtract]
memory = {15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0,
0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33,
Line 2,413:
];
p += 3;
]</langsyntaxhighlight>
{{out}}
<pre>H
Line 2,432:
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">memory = []
step = 3
currentAddress = 0
Line 2,470:
print out
print "-------------------"
print "Execution Complete"</langsyntaxhighlight>
{{out}}
<pre>
Line 2,485:
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE Subleq;
FROM Terminal IMPORT Write,WriteString,WriteLn,ReadChar;
 
Line 2,524:
 
ReadChar
END Subleq.</langsyntaxhighlight>
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import streams
 
type
Line 2,560:
except IndexDefect:
echo "ip: ", intr.ip
echo "mem: ", intr.mem</langsyntaxhighlight>
 
{{out}}
Line 2,567:
=={{header|Objeck}}==
{{trans|Java}}
<langsyntaxhighlight lang="objeck">use System.IO;
 
class Sublet {
Line 2,604:
while (instructionPointer >= 0);
}
}</langsyntaxhighlight>
 
<pre>
Line 2,612:
=={{header|Oforth}}==
 
<langsyntaxhighlight lang="oforth">: subleq(program)
| ip a b c newb |
program asListBuffer ->program
Line 2,627:
[15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0 ]
subleq</langsyntaxhighlight>
 
=={{header|ooRexx}}==
Line 2,633:
{{trans|REXX}}
reformatted and long variable names that suit all Rexxes.
<langsyntaxhighlight lang="oorexx">/*REXX program simulates execution of a One-Instruction Set Computer (OISC). */
Signal on Halt /*enable user to halt the simulation. */
cell.=0 /*zero-out all of real memory locations*/
Line 2,670:
Return cell._ /*return the contents of "memory" loc _*/
halt: Say 'REXX program halted by user.'
Exit 1</langsyntaxhighlight>
{{out}}
<pre>Hello, world!</pre>
Line 2,678:
Using an array object instead of a stem for cells.
<br>Array indexes must be positive!
<langsyntaxhighlight lang="oorexx">/*REXX program simulates execution of a One-Instruction Set Computer (OISC). */
Signal on Halt /*enable user to halt the simulation. */
cell=.array~new /*zero-out all of real memory locations*/
Line 2,713:
Exit
halt: Say 'REXX program halted by user.';
Exit 1</langsyntaxhighlight>
 
=={{header|Pascal}}==
{{works with|Free Pascal|1.06}}
<langsyntaxhighlight lang="pascal">PROGRAM OISC;
 
CONST
Line 2,777:
LOADTEXT (FILENAME, MEM);
SUBLEQ (MEM);
END.</langsyntaxhighlight>
 
{{in}}
Line 2,788:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/env perl
use strict;
use warnings;
Line 2,812:
}
}
}</langsyntaxhighlight>
{{Output}}<pre>Hello, world!</pre>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">procedure</span> <span style="color: #000000;">subleq</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">code</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ip</span> <span style="color: #0000FF;">:=</span> <span style="color: #000000;">0</span>
Line 2,838:
<span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">72</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">101</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">108</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">108</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">111</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">44</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">32</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">119</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">111</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">114</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">108</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">100</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">33</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,845:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de mem (N)
(nth
(quote
Line 2,858:
((lt0 B) (prin (char (car (mem A)))))
((le0 (dec (mem B) (car (mem A))))
(setq IP (mem C)) ) ) ) )</langsyntaxhighlight>
Output:
<pre>Hello, world!</pre>
Line 2,864:
=={{header|PowerShell}}==
{{trans|Python}}
<syntaxhighlight lang="powershell">
<lang PowerShell>
function Invoke-Subleq ([int[]]$Program)
{
Line 2,902:
}
}
</syntaxhighlight>
</lang>
<syntaxhighlight lang="powershell">
<lang PowerShell>
Invoke-Subleq -Program 15,17,-1,17,-1,-1,16,1,-1,16,3,-1,15,15,0,0,-1,72,101,108,108,111,44,32,119,111,114,108,100,33,10,0
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,912:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">DataSection
StartData:
Data.i 15,17,-1,17,-1,-1,16,1,-1,16,3,-1,15,15,0,0,-1,72,101,108,108,111,44,32,119,111,114,108,100,33,10,0
Line 2,930:
ip=nip
Wend
Input()</langsyntaxhighlight>
 
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">import sys
 
def subleq(a):
Line 2,956:
subleq([15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15,
0, 0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111,
114, 108, 100, 33, 10, 0])</langsyntaxhighlight>
 
=={{header|R}}==
 
<langsyntaxhighlight lang="rsplus">
mem <- c(15, 17, -1, 17, -1, -1, 16, 1,
-1, 16, 3, -1, 15, 15, 0, 0,
Line 2,987:
instructionPointer <- instructionPointer + 3
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Hello, world!</pre>
Line 2,993:
=={{header|Racket}}==
{{trans|Go}} The negative addresses are treated as -1.
<langsyntaxhighlight Racketlang="racket">#lang racket
 
(define (subleq v)
Line 3,020:
0))
 
(subleq Hello)</langsyntaxhighlight>
{{out}}
<pre>Hello, world!</pre>
Line 3,027:
(formerly Perl 6)
{{trans|Perl}}
<syntaxhighlight lang="raku" perl6line>my @hello-world =
|<15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1>,
|"Hello, world!\n\0".comb.map(*.ord);
Line 3,048:
}
 
run-subleq @hello-world;</langsyntaxhighlight>
 
{{out}}
Line 3,057:
 
The REXX language has no concept of a &nbsp; ''word'', &nbsp; but for storing numbers, the default is nine decimal digits.
<langsyntaxhighlight lang="rexx">/*REXX program simulates the execution of a One─Instruction Set Computer (OISC). */
signal on halt /*enable user to halt the simulation.*/
parse arg $ /*get optional low memory vals from CL.*/
Line 3,079:
/*──────────────────────────────────────────────────────────────────────────────────────*/
@: parse arg @z; return @.@z /*return a memory location (cell @Z).*/
halt: say 'The One─Instruction Set Computer simulation pgm was halted by user.'; exit 1</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 3,086:
 
=={{header|Ruby}}==
<langsyntaxhighlight Rubylang="ruby">class Computer
def initialize program
@memory = program.map &:to_i
Line 3,128:
subleq = Computer.new ARGV
 
subleq.run</langsyntaxhighlight>
'''Sample usage:'''
<pre>
Line 3,137:
=={{header|Scala}}==
===Imperative, Javaish, destructible opcodes read===
<langsyntaxhighlight Scalalang="scala">import java.util.Scanner
 
object Subleq extends App {
Line 3,155:
instructionPointer += 3
} while (instructionPointer >= 0)
}</langsyntaxhighlight>
{{Out}}See it running in your browser by [https://scastie.scala-lang.org/f4MszRqZR5qtxI6YwarJhw Scastie (JVM)].
 
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">var memory = ARGV.map{.to_i};
var ip = 0;
 
Line 3,175:
ip = c
}
}</langsyntaxhighlight>
 
{{out}}
Line 3,187:
 
Requires at least 2k of RAM.
<langsyntaxhighlight lang="basic"> 10 DIM M(32)
20 INPUT P$
30 LET W=1
Line 3,219:
310 GOTO 160
320 PRINT CHR$ (M(A+1)-1);
330 GOTO 160</langsyntaxhighlight>
{{in}}
<pre>15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 46 43 50 50 53 27 1 61 53 56 50 42 28 118 0</pre>
Line 3,229:
{{trans|Python}}
 
<langsyntaxhighlight lang="swift">func subleq(_ inst: inout [Int]) {
var i = 0
Line 3,257:
 
subleq(&prog)
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,265:
=={{header|Tcl}}==
 
<syntaxhighlight lang="tcl">
<lang Tcl>
namespace import ::tcl::mathop::-
 
Line 3,290:
fconfigure stdout -buffering none
subleq {15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0}
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,296:
 
=={{header|uBasic/4tH}}==
<syntaxhighlight lang="text">GoSub _Initialize ' Initialize memory
 
i = 0 ' Reset instruction pointer
Line 3,347:
@(30) = 10 ' Replace with =ORD(c) when required
@(31) = 0
Return</langsyntaxhighlight>
{{out}}
<pre>Hello, world!
Line 3,355:
=={{header|UNIX Shell}}==
===dash===
<langsyntaxhighlight lang="bash">#!/bin/sh
 
mem="15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0 "
Line 3,397:
done
echo "Total step:"$STEP
</syntaxhighlight>
</lang>
===bash===
<langsyntaxhighlight lang="bash">#!/usr/bin/env bash
 
mem=(15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1
Line 3,422:
done
printf 'Total step:%d\n' "$step"
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="ecmascript">import "io" for Stdin, Stdout
 
var subleq = Fn.new { |program|
Line 3,453:
 
var program = "15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0"
subleq.call(program)</langsyntaxhighlight>
 
{{out}}
Line 3,462:
=={{header|zkl}}==
{{trans|Python}}
<langsyntaxhighlight lang="zkl">fcn subleq(a,a1,a2,etc){ a=vm.arglist.copy();
i:=0;
while(i>=0){ A,B,C:=a[i,3];
Line 3,470:
i+=3;
}
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">subleq(15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15,
0, 0, -1, 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108,
100, 33, 10, 0);</langsyntaxhighlight>
{{out}}<pre>Hello, world!</pre>
 
=={{header|ZX Spectrum Basic}}==
Reads the Subleq program from the keyboard, as space-separated numbers, and executes it. A couple of implementation details (arrays being indexed from 1 rather than from 0; the control character ASCII 10 needing to be intercepted specially, because it would otherwise be printed as <code>?</code> rather than as a newline character) are hidden from the Subleq programmer. Lines <code>10</code> to <code>140</code> are the machine code loader, lines <code>150</code> to <code>310</code> the VM.
<langsyntaxhighlight lang="zxbasic"> 10 DIM m(512)
20 INPUT p$
30 LET word=1
Line 3,508:
290 IF m(a+1)=10 THEN PRINT : GO TO 160
300 PRINT CHR$ m(a+1);
310 GO TO 160</langsyntaxhighlight>
{{out}}
<pre>Hello, world!</pre>
10,333

edits