Assemble

From Esolang
Jump to navigation Jump to search

Assemble is an Esolang designed by PSTF to expand the original Assembly language.

Instructions

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(or register).
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 CX 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.
rsrg <reg> (reset 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.
pau (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.
inc $<var> (increase) Set the value of var to var+1.
dec $<var> (decrease) Set the value of var to var-1.

You can use all default registers, and the reg01, reg02, and so on.

Other syntax

To introduce a comment, you may write this code:

<-- This is a comment. -->
mov ax, 4
mov bx, ax
mov cx, 3
mov bx, bx + cx
dvr bx <-- This instruction prints the value of ax + cx. -->

<"""
You may also 
writes some document comment
or comment block
in your code.
""">

To define a variable, you may write this code:

$a "Nope." <-- This instruction defines a variable a and assign it to "Nope.".

To define a label, you may write this code:

%label%
$t NULL
mov t, 5
mov t, t * 6
psv t
jeq 30 ~label2
%label2%
dst "Successfully transferred from label to label2."
pau
brk

Example

Hello, world!

dst     "Hello, world!"
pau
brk

Cat

$st ""
ipt st
dvr st
pas
brk

Judge a number is even or odd

$a   0
ipt  a
mov  ax, a
push ax
jmp  ~even
%even%
mod  2
jze  ~yes
jnz  ~nope
%yes%
dst  "Even"
jmp  ~end
%nope%
dst  "Odd"
jmp  ~end
%end%
pau
brk

Category