From Esolang
Jump to: navigation, search

Optimism is another implementation of the OISC idea, this one by ToothPic, but it's a little different in that it's based on addition, not subtraction. That is where it's name came from. Addition is giving, optimistic. The only instruction is ADDOV, which takes three operands. Code and data are separate, and memory mapped I/O is available.

Instruction layout

All data is one byte long. The Program Counter can be any number of hex digits long. One byte will be used on this page. As the only instruction is ADDOV, it isn't shown in the code. The three operands are written in hexadecimal form, with commas between the numbers and a terminating newline.


The first operand is the destination, followed by the source and finally the location for the jump. The jump is to a literal line number, and has to be included, even if it's unused.

FF is a reserved number in every field. If FF is in the jump field, it specifies that the source value is literal. If the source is FF, program prompts for input to the destination. If the destination is FF, then the number in source is output as an unsigned integer.

x,x,FF        The second operand is literal. Always goes to the next instruction, even on overflow
01,AA,FF      This adds AA(170) to data memory location 1
x,FF,x        The program will prompt for input
01,FF,00      The program will put the users input in 1. If n < 0 or > 255, a 0 will be stored
FF,x,x        The program outputs the value of the source
FF,01,00      If location 1 is 42, the program will output 42

Execution halts when the program reaches location FF. On a side note, no matter if the PC is 4-bits or 24-bits, the highest possible value for the PC is the endpoint and the immediate value flag. Just fill all digits with F's.

Comments are allowed in the code only if the jump pointer is followed by a comma, and include no commas.


To do subtraction, assuming 00-01:

03,01,FF,Make 03 = 1
00,03,06,Add 1 to 00
02,03,00,Add 1 to 01
03,01,FF,Add 1 to 03
04,FF,FF,Make 04 = 255
03,04,01,Add 255 to 2, making 03 = 1 and forcing a jump to 01
02,02,FF,Correct for the missed increment + inherent error
00,01,08,Add 01 to 00
00,02,09,Add inverse of 00 to 00

To test if 00 < 0:

01,80,FF,Make 01 = 128
00,01,x,Will only jump if highest bit is set, which is set in negative numbers.

That will jump to x if 00 < 0.

Using those two code snippets, and maybe some more code, it is possible to implement Subtract and branch if Not Positive.


Here is a program which prints the ASCII values of "Hi!":

00,48,FF,Move 72 ("H") into 00
FF,00,02,Print 00
00,21,FF,Add 33 to 72 to make 105 ("i")
FF,00,04,Print 00
00,B8,FF,Add 184 to 105 to make 289. 289 % 256 = 33 ("!")
FF,00,07,Print 00


In March of 2012, User:shadwick wrote a naive but functional Optimism-to-C translator. Just pump the resulting C through your favourite compiler, link it, and you're good to go. The source can be found here: http://paste.pocoo.org/show/567221/ (dead link)

See also