Micron Turiŋ-Complete Aßembly Laŋuage

From Esolang
Jump to navigation Jump to search

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.

  1. Numbers. They're defined by the arithmetic calculations(` is for nroot, x`y means x1/y), such as (72 + 3 * 3) ` 2.
  2. Booleans. True or False.
  3. Strings. Quoted in quotation mark instead of apostrophe.
  4. Tables. Simply like the list in Python.
  5. Nonetype. None, NaN, Infinity, and invalid types.
  6. 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
  1. Addition.
  2. Subtraction.
  3. Multiplication.
  4. Division.
  5. Modulo.
  6. Logarithm.
  7. N-root.
  8. Exponent.
  9. 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
  1. Bitwise and.
  2. Bitwise or.
  3. 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.
  4. Bitwise xor.
  5. Multiply x by 2y.
  6. Divide x by 2y.
  7. Cycle shift x to the left by y. The highest level is shifted to the left to become the lowest level, and vice versa.
  8. Cycle shift x to the right by y.

I/O

lsn x, y
rea x
wrt x
say x
out x
dqu
  1. Inputs a string, parse out the number with base-y(leave blank is ten), then store it into x.
  2. Inputs a string and directly store it into x.
  3. Print the value of x as character(Unicode).
  4. Print the value of x as integer.
  5. Print the value of x.
  6. 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
  1. Compares a and b and stores the results in the SF and ZF registers.
  2. If ZF is 1, then jump to specified label.[1]
  3. If ZF is 0, then jump to specified label.
  4. If SF is 1 and ZF is 0, then jump to specified label.[2]
  5. If SF is 1 or ZF is 1, then jump to specified label.
  6. If SF is 1, then jump to specified label.
  7. If SF is 0, then jump to specified label.
  8. IF-ELSE statement. Also you can use elif cond to make more branch.

Queue operations

pbk x
cqu
pft x
ppb
ppf
  1. Push x at the tail of the queue.
  2. Clear the queue.
  3. Push x at the head of the queue.
  4. Pop the tail of queue and put it into QR.
  5. Pop the head of queue and put it into QR.

Stack operations

psh x
pop x
  1. Push the value of x to the stack.
  2. Pop the ToS and store it into x. If leave x blank, then discard ToS.

Accumulators

psa x
ppa x
cac
chg x
  1. Push the value of x to the accumulator.
  2. Assign x to the value of accumulator and reset the accumulator.
  3. Reset accumulator to 0.
  4. Change all accumulator-operations to on x-th accumulator.

Variable

dcl a, t, v
  1. 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
  1. Jump to label k and decrease LR with 1.
  2. For-loop.
  3. 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

  1. 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.
  2. 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.