Assembly

From Esolang
Jump to navigation Jump to search
Not to be confused with assembly language, assembly code, nor machine code.

Assembly is a esolang created by Mihai Popa (and arranged by Steve Abel). It is low-level, like real assembly languages. The instructions are:

Instruction table
Instruction From Meaning
add <num> (addition) Add the number after the instruction to the accumulator.
sub <num> (subtract) Subtract the number after the instruction from the accumulator.
mul <num> (multiply) Multiply the number after the instruction with the result from the accumulator and store the result in the accumulator.
div <num> (divide) Divide the number after the instruction with the result from the accumulator and store the result in the accumulator.
pow <num> (power) Power the number after the instruction (the exponent) with the result from the accumulator (the base) with and store the result in the accumulator.
mod <num> (modulo) Modulo the result from the accumulator by the number after the instruction and store the result in the accumulator.
dis (display) Display the result of the accumulator as a number.
dvr *<var> (display variable) Display the result of the variable.
dst (display string) Display the string.
das (display ascii) Display the result of the accumulator as a ASCII(Unicode) character from the ASCII(Unicode) decimal value.
dgbk (display GBK) Display the result of the accumulator as a GBK character from the GBK decimal value.
jmp %<lbl> (jump) Jump to the label specified after the instruction.
jnz %<lbl> (jump not zero) Jump to the label specified after the instruction if the result from the accumulator is not zero.
jze %<lbl> (jump zero) Jump to the label specified after the instruction if the result from the accumulator is zero.
jcxz %<lbl> (jump if CX is zero) Jump to the label specified after the instruction if the result from the accumulator is zero.
jne <num> %<lbl> (jump not equal) Jump to the label specified after the instruction if the result from the accumulator is not equal with the number after the instruction.
jeq <num> %<lbl> (jump equal) Jump to the label specified after the instruction if the result from the accumulator is equal with the number after the instruction.
jgr <num> %<lbl> (jump greater) Jump to the label specified after the instruction if the result from the accumulator is greater than the number after the instruction.
jls <num> %<lbl> (jump less) Jump to the label specified after the instruction if the result from the accumulator is less than the number after the instruction.
ja <num> %<lbl> (jump above) Jump to the label specified after the instruction if the result from the accumulator is greater than the number after the instruction.
jb <num> %<lbl> (jump below) Jump to the label specified after the instruction if the result from the accumulator is less than the number after the instruction.
jle <num> %<lbl> (jump less equal) Jump to the label specified after the instruction if the result from the accumulator is less or equal than the number after the instruction.
jge <num> %<lbl> (jump greater equal) Jump to the label specified after the instruction if the result from the accumulator is greater or equal than the number after the instruction.
jin (join) Store the result of the accumulator in a buffer. Can be used multiple times, so the results will be chained from left to right, but with a space between the values.
dbf (display buffer) Display the buffer as a string of ASCII characters from the ASCII decimal values. Spaces are removed from the buffer values before displaying.
dbfws (display buffer with spaces) Display the buffer as a series of ASCII characters from the ASCII decimal values. Spaces are kept from the buffer values before displaying.
dbn (display buffer number) Display the buffer as a number. Spaces are removed from the buffer values before displaying.
dbnws (display buffer number with spaces) Display the buffer as a series of numbers. Spaces are kept from the buffer values before displaying.
cbf (clear buffer) Clear the buffer.
cac (clear accumulator) Clear the value from the accumulator and reset to zero.
crg <reg> (clear register) Clear the value from the register and reset to zero.
push <reg> (push) Push the value from the register and put in the accumulator.
pop <reg> (pop) Pop the value from the accumulator and put in the register.
mov <reg> <reg2> (move) Copy the value from the input register and put in the output register.
slp <msec> (sleep) Pause execution for the amount of milliseconds after the instruction.
pas (pause) Pause execution until the next keystroke.
brk (break) Quit the execution of the program.
ipt *<var> (input) Prompt for user input and store the result in the variable.
psv *<var> (push variable) Push the value from the variable and put in the accumulator.
pov *<var> (pop variable) Pop the value from the accumulator and put in the variable.
nop (no operation) Do nothing.
and *<var> *<const> (and) Bitwise AND.
or *<var> *<const> (or) Bitwise OR.

It has 8 default registers, called: reg1, reg2, reg3, reg4, reg5, reg6, reg7 and reg8

You can also use AX, BX, CX, etc.

Syntax

Variables can be created with this syntax:

*example "Hello, world!"

Comments can be created like this:

<Here is a comment>
add 4
dis <Display the result>
!<
Multi-line
comment!
You can
comment
multiple
lines!
>!

Labels can be created with this syntax:

@label
    add 8
    jnq 6 %label2
@label2
    *hello "Hello!"
    dvr *hello

Examples

Hello, world!

add 72
jin
cac
add 101
jin
cac
add 108
jin
cac
add 108
jin
cac
add 111
jin
cac
add 44
jin
cac
add 32
jin
cac
add 119
jin
cac
add 111
jin
cac
add 114
jin
cac
add 108
jin
cac
add 100
jin
cac
add 33
jin
cac
dbf
pas
cbf
brk

Tiny "Hello, world!"

*text "Hello, world!"
dvr *text
pas
brk

Micro "Hello, world!"

dst "Hello, world!"
pas
brk

Cat

ipt *cat
dvr *cat
pas
brk

Truth Machine

ipt *var
psv *var
jze %zero
jgq 1 %one
@zero
    cac
    dis
    pas
    brk
@one
    cac
    add 1
    dis
    jmp %one

Note: This is NOT a real assembly language (like x86 or ARM). Also: unimplemented!