Jump to content

Subleq: Difference between revisions

810 bytes added ,  11 months ago
m (Clarify that the control transfer is to C itself, not the contents of memory location C.)
(→‎{{header|Commodore BASIC}}: Add implementation)
Line 1,743:
HALTED AFTER 0073 INSTRUCTIONS.</pre>
 
=={{header|Commodore BASIC}}==
The only change from the task description is that the character codes are changed to PETSCII.
<syntaxhighlight lang="basic">100 READ N:REM SIZE OF PROGRAM
110 DIM M%(N-1)
120 FOR I=1 TO N
130 : READ M%(I-1)
140 NEXT I
150 IP=0
160 FOR D=0 TO 1 STEP 0
170 : IF IP < 0 OR IP > N-3 THEN D=1:GOTO 290
180 : A=M%(IP):B=M%(IP+1):C=M%(IP+2)
190 : IP=IP+3
200 : IF A >= 0 THEN 240
210 : GET K$: IF K$="" THEN 210
220 : M%(B) = ASC(K$)
230 : GOTO 290
240 : IF B >= 0 THEN 270
250 : PRINT CHR$(M%(A));
260 : GOTO 290
270 : M%(B)=M%(B)-M%(A)
280 : IF M%(B) <= 0 THEN IP=C
290 NEXT D
300 END
310 DATA 33
320 DATA 15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 14
330 DATA 104, 69, 76, 76, 79, 44, 32, 87, 79, 82, 76, 68, 33, 13, 0</lang>
 
{{Out}}
<pre>Hello, world!</pre>
=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">(defun run (memory)
1,480

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.