From Esolang
Jump to: navigation, search

Addleq is a Turing-complete OISC language invented by Oleg (thank r.e.s.), very similar to Subleq, with the exception that it uses addition operation instead of subtraction. However it is much harder to program in Addleq than in Subleq.

Because of similarity to Subleq, the exactly same assembly notation can be used.

Elementary operations[edit]

The following variable definitions can be useful

. Z:0 dec:-1 inc:1 t1:0 t2:0

Z is zero and should not be changed, dec and inc are useful for decrementing and incrementing, t's are temporary variables.

If A has value and B is 0, then copying A to B as as simple as


If B is not zero, it has to be known if it is greater or less than zero. It is possible to clear B, for example, in the following way. Suppose that B is not less than 0, then

inc B
dec B ?+3
Z Z ?-6

does the trick. As in Subleq assembly ? signifies the address of the next memory cell. So the example above is the same as

        inc B
repeat: dec B do_smth_else
        Z Z repeat

If B>0 than

. Z:0 dec:-1 B:0 
dec B ?+3
Z Z ?-6

which compiles into

0 -1 0
1 2 9
0 0 3


Input and output operations can be defined exactly as in Subleq with a specail address (-1). This program echos input:

# Echo
       -1 x (-1)
       x (-1)

       # clear x
       dec x start
       Z Z ?-6

. Z:0 dec:-1 x:0

Hello, World![edit]

"Hello world" program is a bit more complex. For dereferencing operation the same technique as in Subleq can be used.

    # Hello world!

    # output *p; 
    dec a ?+3; Z Z ?-6
    p a
    a:1 (-1)

    # p++
    inc p

    # clear temps
    dec t1 ?+3; Z Z ?-6
    dec t2 ?+3; Z Z ?-6

    # t2=(-p+1)
    p t1
    dec t1 ?+3
    dec t2 ?-6

    # check if p<E
    dec t2
    dec t2 # now t2==-p-1
    E t2 (-1)
    Z Z 0

. p:H Z:0 dec:-1 inc:1 t1:0 t2:0
. H: "Hello, World!\n" E:E

In the above program the pointer is being checked for reaching the end (p==E). It is possible also to check the dereferenced value. In this case the program becomes a bit simpler:

    # Hello world!

    # prepare *p in a and b
    dec a ?+3; Z Z ?-6
    dec b ?+3; Z Z ?-6
    p a; p b

    # check that b>0
    dec t ?+3; Z Z ?-6
    b:1 t (-1)     

    # output a
    a:1 (-1)

    # p++
    inc p

    Z Z 0

. p:H Z:0 dec:-1 inc:1 t:0
. H:"Hello, World!\n\0"

How to run Addleq programs[edit]

Use sqasm.cpp to compile assembly program into the Addleq code. Then sqrun.cpp with the option (-a) to run the compiled code.

See also[edit]

External resources[edit]

  • Addleq on Oleg Mazonka's site.