X-ASM

X-ASM is an Assembly-like programming language designed by PSTF.
= Language Overview =
X-ASM is a variant of Assembly Language, but it is not real Assembly Language(such as like x86, ARM, MASM, etc.), thus it is a Medium-level language. It is inspired by X-script, Assembly/Assemble, MASM, and C++.
It uses register, memory, a stack, ten accumulators, and variables.
= Basic Syntax Overview =
== Procedural framework ==
X-ASM uses this procedural framework:
alloc cs: code, ds: data, ss: stack, bs: buffer
# Main label(main) is the entrance of the program.
buffer seg
	dat rep(8) 0
buffer endseg
data seg
	dat rep(8) 0
data endseg
stack seg
	dat rep(128) 0 # Allocate stack space in advance to prevent stack overflow and stack underflow.
stack endseg
code seg
main: 
	nop # Put your code here
	jmp ok
ok: 
	mov fr, 0
	ext 0
code endseg
== Arithmetic operations ==
add x, y
sub x, y
mul x, y
div x, y
mod x, y
log x, y
nrt x, y
exp x, y
mov x, y
# Addition.
# Subtraction.
# Multiplication.
# Division.
# Modulo.
# Logarithm.
# N-root.
# Exponent.
# Assignment.
== Bitwise operations ==
and x, y
or x, y
not x
xor x, y
shl x, y
shr x, y
rtl x, y
rtr x, y
# Bitwise and.
# Bitwise or.
# Bitwise not Negates the value. Note: You can add mov bw, 1 to make bitwise not, and set bw to 0 to make arithmetic not.
# Bitwise xor.
# Multiply x by 2y.
# Divide x by 2y.
# Cycle shift x to the left by y. The highest level is shifted to the left to become the lowest level, and vice versa.
# Cycle shift x to the right by y.
== I/O ==
lsn x, y
rea x
wrt x
say x
dis x
dbf
dbfws
# Inputs a string, parse out the number with base-y(leave blank is ten), then store it into x.
# Inputs a string and directly store it into x.
# Print the value of x as character(Unicode).
# Print the value of x as integer.
# Print the value of x.
# Print the whole buffer as character array.
# Print the whole buffer as integer array, and seperate with spaces.
== Conditional ==
cmp a, b
jeq l
jne l
jab l
jna l
jbl l
jnb l
aje x, l
ajd x, l
aja x, l
aju x, l
ajb x, l
ajv x, l
if cond do code else code2 end
# Compares a and b and stores the results in the SF and ZF registers.
# If ZF is 1, then jump to specified label.Note: The ZF register is used to determine whether the value of an operation is 0. Mathematically, if two numbers are subtracted and the result is 0, then the two numbers are equal.
# If ZF is 0, then jump to specified label.
# If SF is 1 and ZF is 0, then jump to specified label.Note: SF stores the symbols of the calculation results. If the result is positive or 0, the value is 0, and if the result is negative, the value is 1.
# If SF is 1 or ZF is 1, then jump to specified label.
# If SF is 1, then jump to specified label.
# If SF is 0, then jump to specified label.
# If accumulator is equal to x, then jump to specified label.
# If accumulator isn't equal to x, then jump to specified label.
# If accumulator is greater than x, then jump to specified label.
# If accumulator is under x, then jump to specified label.
# If accumulator is less than x, then jump to specified label.
# If accumulator is over x, then jump to specified label.
# IF-ELSE statement. Also you can use elif cond to make more branch.
== Buffer operations ==
jin
cbf
# Join the result of accumulator(acc) to the buffer.
# Clear the buffer.
== Stack operations ==
psh x
pop x
# Push the value of x to the stack.
# Pop the ToS and store it into x. If leave x blank, then discard ToS.
== Accumulators ==
psa x
ppa x
cac
chg x
# Push the value of x to the accumulator.
# Assign x to the value of accumulator and reset the accumulator.
# Reset accumulator to 0.
# Change all accumulator-operations to on x-th accumulator.
== Variable ==
dcl a, t, v
# Declare a variable with the name a, type t, and v as value. Leave t blank is integer, leave v blank is initial value.
=== Data types ===
Currently, we have these types: 
* Numbers, such as 3, 7, 3.14, -2, 114514, 1e20, 3.683E-34, 3.130582375184619046479671967486, etc. Initial value is 0 for int, and 0.0 for float.
* Strings, such as 'Hello' (or "Hello"). Strings can be enclosed in double quotes or single quotes, just like work in Python. Initial value is "".
* Booleans. It can only be True, or False. Initial value is False.
* Tables. This is the most important data type in X-ASM, it can express a list or a dictionary, such as {1, 2, 3}, or {key: value}. Initial value is {}. Also, if you define a table as a list, then you use brackets instead of braces.
** List. It uses the brackets for table parentheses. initial value is []. You can use slice, as slice in Python.
** Set. It is the common type of table, and it will sort when initialized, and sort after every deletion and insertion. Initial value is {}.
** Dictionary. It is a table with key-value bind. Initial value is {}.
* Tuples. It is just a "unchangable table", such as (5, 2), (4, 8, 3, 8, 9), but (1, ) instead of (1). Initial value is (,).
* Functions. They're 1st-class citizens, which can be passed and returned as arguments.
* Empty types. They has only a value, None. They converts to 0, but they can used to be true. When they converted to string, they becomes "".
* User-defined types. They're defined by "structure" command.
* Undefined behaviour. This often occurs when you trying to do something incorrect, such as 5/0. They converts to 0, but they can used to be false. When they converted to string, they becomes 99 bottles of beer.
* Thread. It can fork a process out to do another program.
== Loop ==
loop k
for iter in iter_cup do code end
while cond do code end
# Jump to label k and decrease LR with 1.
# For-loop.
# While-loop.
== Function ==
=== Header ===
func_alloc name
=== Real code ===
func name (type) param_list
code
ret retval_list
end
= Categories and References =
Category:Languages
Category:2025
Category:Turing complete