Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
One-instruction set computer
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Subtract and branch if less than or equal to zero === The {{mono|subleq}} instruction ("''subtract and branch if less than or equal to zero''") subtracts the contents at address {{mono|''a''}} from the contents at address {{mono|''b''}}, stores the result at address {{mono|''b''}}, and then, ''if the result is not positive'', transfers control to address {{mono|''c''}} (if the result is positive, execution proceeds to the next instruction in sequence).<ref name=agut />{{rp|4β7}} [[Pseudocode]]: '''Instruction''' <syntaxhighlight lang="nasm" inline>subleq a, b, c</syntaxhighlight> Mem[b] = Mem[b] - Mem[a] '''if''' (Mem[b] β€ 0) '''goto''' c Conditional branching can be suppressed by setting the third operand equal to the address of the next instruction in sequence. If the third operand is not written, this suppression is implied. A variant is also possible with two operands and an internal [[Accumulator (computing)|accumulator]], where the accumulator is subtracted from the memory location specified by the first operand. The result is stored in both the accumulator and the memory location, and the second operand specifies the branch address: '''Instruction''' <syntaxhighlight lang="nasm" inline>subleq2 a, b</syntaxhighlight> Mem[a] = Mem[a] - ACCUM ACCUM = Mem[a] '''if''' (Mem[a] β€ 0) '''goto''' b Although this uses only two (instead of three) operands per instruction, correspondingly more instructions are then needed to effect various logical operations. ==== Synthesized instructions ==== It is possible to synthesize many types of higher-order instructions using only the {{mono|subleq}} instruction.<ref name=agut />{{rp|9β10}} Unconditional branch: ;{{mono|JMP c}} :<syntaxhighlight lang="nasm"> subleq Z, Z, c </syntaxhighlight> Addition can be performed by repeated subtraction, with no conditional branching; e.g., the following instructions result in the content at location {{mono|a}} being added to the content at location {{mono|b}}: ;{{mono|ADD a, b}} :<syntaxhighlight lang="nasm"> subleq a, Z subleq Z, b subleq Z, Z </syntaxhighlight> The first instruction subtracts the content at location {{mono|a}} from the content at location {{mono|Z}} (which is 0) and stores the result (which is the negative of the content at {{mono|a}}) in location {{mono|Z}}. The second instruction subtracts this result from {{mono|b}}, storing in {{mono|b}} this difference (which is now the sum of the contents originally at {{mono|a}} and {{mono|b}}); the third instruction restores the value 0 to {{mono|Z}}. A copy instruction can be implemented similarly; e.g., the following instructions result in the content at location {{mono|b}} getting replaced by the content at location {{mono|a}}, again assuming the content at location {{mono|Z}} is maintained as 0: ;{{mono|MOV a, b}} :<syntaxhighlight lang="nasm"> subleq b, b subleq a, Z subleq Z, b subleq Z, Z </syntaxhighlight> Any desired arithmetic test can be built. For example, a branch-if-zero condition can be assembled from the following instructions: ;{{mono|BEQ b, c}} :<syntaxhighlight lang="nasm"> subleq b, Z, L1 subleq Z, Z, OUT L1: subleq Z, Z subleq Z, b, c OUT: ... </syntaxhighlight> Subleq2 can also be used to synthesize higher-order instructions, although it generally requires more operations for a given task. For example, no fewer than 10 subleq2 instructions are required to flip all the bits in a given byte: ;{{mono|NOT a}} :<syntaxhighlight lang="nasm"> subleq2 tmp ; tmp = 0 (tmp = temporary register) subleq2 tmp subleq2 one ; acc = -1 subleq2 a ; a' = a + 1 subleq2 Z ; Z = - a - 1 subleq2 tmp ; tmp = a + 1 subleq2 a ; a' = 0 subleq2 tmp ; load tmp into acc subleq2 a ; a' = - a - 1 ( = ~a ) subleq2 Z ; set Z back to 0 </syntaxhighlight> ==== Emulation ==== The following program (written in [[pseudocode]]) emulates the execution of a {{mono|subleq}}-based OISC: <syntaxhighlight lang="c"> int memory[], program_counter, a, b, c program_counter = 0 while (program_counter >= 0): a = memory[program_counter] b = memory[program_counter+1] c = memory[program_counter+2] if (a < 0 or b < 0): program_counter = -1 else: memory[b] = memory[b] - memory[a] if (memory[b] > 0): program_counter += 3 else: program_counter = c </syntaxhighlight> This program assumes that {{mono|memory[]}} is indexed by ''nonnegative'' integers. Consequently, for a {{mono|subleq}} instruction ({{mono|a}}, {{mono|b}}, {{mono|c}}), the program interprets {{mono|a < 0}}, {{mono|b < 0}}, or an executed branch to {{mono|c < 0}} as a halting condition. Similar interpreters written in a {{mono|subleq}}-based language (i.e., [[self-interpreter]]s, which may use [[self-modifying code]] as allowed by the nature of the {{mono|subleq}} instruction) can be found in the external links below. A general purpose [[Symmetric multiprocessing|SMP]]-capable 64-bit [[operating system]] called '''Dawn OS''' has been implemented in an emulated Subleq machine. The OS contains a [[C language|C]]-like compiler. Some memory areas in the virtual machine are used for peripherals like the keyboard, mouse, hard drives, network card, etc. Basic applications written for it include a media player, painting tool, document reader and scientific calculator.<ref>{{cite web | url=http://users.atw.hu/gerigeri/DawnOS/index.html | title=Dawn for SUBLEQ }}</ref> A 32-bit Subleq computer with a graphic display and a keyboard called '''Izhora''' has been constructed by [[Yoel Matveyev]] as a large [[cellular automaton]] pattern.<ref>https://www.gazetaeao.ru/zanimatelnaya-nauka-vchera-segodnya-zavtra/ A Russian article on popular science in [[Birobidzhaner Shtern]] with a brief discussion of Yoel Matveyev's Izhora computer</ref><ref>https://habr.com/ru/post/584596/ A description of the virtual computer Izhora on [[Habr]] (in Russian)</ref> ==== Compilation ==== There is a [[compiler]] called '''Higher Subleq''' written by Oleg Mazonka that compiles a simplified C program into {{mono|subleq}} code.<ref>Oleg Mazonka [https://arxiv.org/abs/1106.2593 A Simple Multi-Processor Computer Based on Subleq]</ref> Alternatively there is a self hosting [[Forth (programming language)|Forth]] implementation written by Richard James Howe that runs on top of a Subleq VM and is capable of interactive programming of the Subleq machine <ref>Richard James Howe [https://github.com/howerj/subleq SUBLEQ eForth]</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)