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!
==== 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>
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)