Code your own instructions, lazyass

From Esolang
Jump to navigation Jump to search

Code your own instructions, lazyass is an esoteric programming language where you have to code in the instructions. Wow, you just give code and it runs? People are so lazy nowadays. You now have to code the code.

This page is still work in progress!

Coding instructions

You have to start any Code your own instructions, lazyass program by coding in the instructions. If you don't, then your program will do nothing! You can use these commands, which operate on a brainfuck-style tape, called the instruction tape.

The instruction tape will always start like this:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
^

With the ^ being what cell is currently active.

To actually add commands, you push them to the instruction stack. There are only numbers on the instruction stack.

Some commands require arguments (ex: reading a variable requires its name), which you have to push to the instruction stack.

+ Increments the current cell by one.
- Decrements the current cell by one.
* Multiplies the current cell by 2.
/ Divides the current cell by 2, rounding the answer.
> Moves the cell pointer to the next one to the right.
< Same thing as > but moves it left instead.
. Pushes the current cell's value to the instruction stack.
, Takes a number as input and pushes it to the instruction stack.
! Reverses the instruction stack.

Each cell, like brainfuck, has the wrapping feature. Each cell is limited to 5 bits (0-31). It will wrap around if it goes above 31 and wrap the other direction if it goes below 0.

Once you're done with adding instructions, it's now time to execute them! Use the ; command to indicate that you are done giving instructions to follow.

Example:

+..>++++++**.!;

Note that this doesn't actually do anything.

However, that's only the first part. That's just coding the instructions.

Code execution

When the program starts running the commands, it does these things (in this order):

  1. Pop the top command. This is done before anything else.
  2. Check the command if it has arguments
  3. Pop any additional arguments from that command if required.

Real program

The real program uses a named variable system for memory. Variable names are all numbers.

The real program will use 1 as truthy values and 0 as falsy.

Actual instructions

Instruction notes: The "codename" is what it will be referred to in code, to simplify things. "Command #" is what gets checked when popping instructions. When a command requires parameters, it will say, "pop x" or "pop x and y". x would be the topmost item, and y would be second. The "name" is the descriptive name of the command. All arguments titled x, y, or z are variable names.

For all variable manipulation commands: If a command tries to write to a variable that doesn't exist, then it will be created. If a command tries to read from a nonexistent variable, it will throw a "nonexistentVariable" error.

Memory manipulation

# Codename Name Arguments Function
1 W Write x and y Write x to variable y.

I/O

# Codename Name Arguments Function
2 Ic Input char x Take a single character input, and write its Unicode value to x.
3 In Input number x Take a number from input and write it to x.
4 Oc Output char x Read variable x and output its corresponding Unicode character.
5 On Output number x Read and output variable x

Arithmetic and logic

# Codename Name Arguments Function
6 + Add x, y, z Reads variables x and y, and stores x + y in z.
7 - Subtract x, y, z Does same thing as Add instruction but does x - y instead.
8 * Multiply x, y, z Same but multiplication
9 / Divide x, y, z Does x / y and stores the result in z. Division is float division.
10 % Mod x, y, z Does x mod y and stores the result in z. Modulo takes the remainder of the long division result of two numbers.
11 ! Not x Store 1 in x if x is 0, otherwise stores 0.
12 AND Bitwise AND x, y, z Performes bitwise x AND y and stores the result in z.
13 OR Bitwise OR x, y, z Same as Bitwise AND but does bitwise OR.
14 XOR Bitwise XOR x, y, z Same but does bitwise XOR.

Conditional branching

# Codename Name Arguments Function
15 CP# Conditionally pop # items x, y Pop x amount of items off the instruction stack if y is non-zero.
31 end End - Ends the program.

Self-modification

# Codename Name Arguments Function
16 PIS Push to instruction stack # Push # to the instruction stack.

Examples

In these examples, I will be showing the code for the instructions, and the actual instructions. Generated instructions use codename from the tables above. For the instruction stack: The leftmost item is on the top. The only code you will see when running a Code your own instructions, lazyass program is the instruction code. The generated instructions is just here so you know what's happening. // means comment.

# = Unspecified number; ? = One unspecified character

A+B problem

Instruction code:

+++ .   Input number (3)
.       3
.       Input number (3)
+ .     4
++ .    Add (6)
-- .    4
- .     3
> . <   0
++ .    Output number (5)
> .     0
!       (reverse instruction stack)

Instruction code (minimized form):

+++...+.++.--.-.>.<++.>.!

Instruction stack:

3, 3, 3, 4, 6, 4, 3, 0, 5, 0

Generated instructions:

1 | In(3)      // Input number and store in V3
2 | In(4)      // Input number and store in V4
3 | +(4, 3, 0) // Add V4 + V3, and store result in V0
4 | On(0)      // Output V0

Memory after each instruction:

1 | [V3: #]
2 | [V3: #] [V4: #]
3 | [V3: #] [V4: #] [V0: V4 + V3]
4 | [V3: #] [V4: #] [V0: V4 + V3]