Micron Turiŋ-Complete Aßembly Laŋuage
Micron Turiŋ-Complete Aßembly Laŋuage(Micron Turing-Complete Assembly Language, MTCASM for short) is designed by PSTF, based on Assembly Language of Windows, and X-ASM by the same author.
Prologue
MTCASM is a Turing-Complete, Strong, Hardward-based and Medium-level(almost High-level) language. It didn't works like Assembly Language in any system, because this is not REALLY Assembly.
Data Types
In this language, there are 6 data types.
- Numbers. They're defined by the arithmetic calculations(` is for nroot, x`y means x1/y), such as
(72 + 3 * 3) ` 2
. - Booleans. True or False.
- Strings. Quoted in quotation mark instead of apostrophe.
- Tables. Simply like the list in Python.
- Nonetype. None, NaN, Infinity, and invalid types.
- Lambda. Just a command block.
Data Storage
In this language, we use registers(RA, RB, RC, RD, AH~DH, AL~DL, CS, IP, DS, DP, SS, SP, QS, QP, IC, SR, QR, LR), a tape, three queues and a stack.
The first queue supports the data store, second is input(seperators will seperate elements and put them into this queue, then drag the element from queue and assign it to the object), third is output(stuff the outputting things into it all together, and drag them out, print with seperators, except the last one will print with terminator).
Module of Program
#include<windows.h> #include<basicext.h> assume CS:code, DS:data, SS:stack, QS:queue data block def dup 32 0 data endb stack block def dup 128 0 stack endb queue block def dup 32 0 queue endb code block start: nop @ Put the code of initialization jmp main main: nop @ Put the code of main program jmp ok ok: mov ic 9 ext 33 code endb end start
Instructions
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 notNegates the value. Note: You can addmov 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 out x dqu
- 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 data queue.
Conditional
cmp a, b jeq l jne l jab l jna l jbl l jnb 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.[1]
- If ZF is 0, then jump to specified label.
- If SF is 1 and ZF is 0, then jump to specified label.[2]
- 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-ELSE statement. Also you can use
elif cond
to make more branch.
Queue operations
pbk x cqu pft x ppb ppf
- Push x at the tail of the queue.
- Clear the queue.
- Push x at the head of the queue.
- Pop the tail of queue and put it into QR.
- Pop the head of queue and put it into QR.
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.
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
Examples
Truth machine
#include<windows.h> #include<basicext.h> assume CS:code, DS:data, SS:stack, QS:queue data block def dup 32 0 data endb stack block def dup 128 0 stack endb queue block def dup 32 0 queue endb code block start: lsn ra jmp main main: cmp ra, 0 jmp ok out ra jmp main ok: out ra mov ic 9 ext 33 code endb end start
Categories and References
- ↑ 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.
- ↑ 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.