CreativeASM/Assembler

From Esolang
Jump to navigation Jump to search

Back to CreativeASM

Here is the assembler for CreativeASM that assembles to Batch! Version 13.0! Written in pure Batch! WOW!

Code

@echo off
REM Registers
set ra=
set rb=
set rc=
set rd=
REM Another set
set rax=
set rbx=
set rcx=
set rdx=
REM Special ones
set r=
set s=
set t=
set u=
REM x86 assembly ones
set eax=
set ebx=
set ecx=
set edx=
REM If the file doesn't exist
if not exist %1 (
  echo E02: CreativeASM file doesn't exist
  echo Backend expection: %1.casm
  echo                    ^^
  echo                    ^| [HERE]
  echo.
  echo Assembling to %1.bat failed! :(
) else (
goto asm
)
:asm
REM Assembling to Batch...
echo @echo off >> %1.bat
echo set ra= >> %1.bat
echo set rb= >> %1.bat
echo set rc= >> %1.bat
echo set rd= >> %1.bat
echo REM Another set >> %1.bat
echo set rax= >> %1.bat
echo set rbx= >> %1.bat
echo set rcx= >> %1.bat
echo set rdx= >> %1.bat
echo REM Special ones >> %1.bat
echo set r= >> %1.bat
echo set s= >> %1.bat
echo set t= >> %1.bat
echo set u= >> %1.bat
echo REM x86 assembly ones >> %1.bat
echo set eax= >> %1.bat
echo set ebx= >> %1.bat
echo set ecx= >> %1.bat
echo set edx= >> %1.bat
for /F "eol= tokens=1,2,3,4,5* delims= " %%A in (%1) do (
  if %%A EQU put (
    echo set %%B=%%C %%D %%E %%F >> %1.bat
  )
  if %%A EQU int if %%C EQU 01h (
    echo echo %%%%B%% >> %1.bat
  )
  if %%A EQU int if %%C EQU 00h (
    echo set /p %%B=? >> %1.bat
  )
  if %%A EQU add (
    echo set /a %%D=%%%%B%%+%%%%C%% >> %1.bat
  )
  if %%A EQU sub (
    echo set /a %%D=%%%%B%%-%%%%C%% >> %1.bat
  )
  if %%A EQU mul (
    echo set /a %%D=%%%%B%%*%%%%C%% >> %1.bat
  )
  if %%A EQU div (
    echo set /a %%D=%%%%B%%/%%%%C%% >> %1.bat
  )
  if %%A EQU mod (
    echo set /a %%D=%%%%B%%%%%%%%%%C%% >> %1.bat
  )
  if %%A EQU @ (
    echo REM %%B %%C %%D %%E %%F >> %1.bat
  )
  if %%A EQU mrk (
    echo REM %%B %%C %%D %%E %%F >> %1.bat
  )
  if %%A EQU bl (
    echo echo. >> %1.bat
  )
  if %%A EQU beqrax (
    echo if %%rax%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU beqrbx (
    echo if %%rbx%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU beqrcx (
    echo if %%rcx%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU beqrdx (
    echo if %%rdx%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU beqeax (
    echo if %%eax%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU beqebx (
    echo if %%ebx%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU beqecx (
    echo if %%ecx%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU beqedx (
    echo if %%edx%% EQU %%B goto %%C >> %1.bat
  )
  if %%A EQU lbl (
    echo :%%B >> %1.bat
  )
  if %%A EQU start (
    echo :%%B >> %1.bat
  )
  if %%A EQU slp (
    echo pause ^>nul >> %1.bat
  )
  if %%A EQU jmp (
    echo goto %%B >> %1.bat
  )
  if %%A EQU hal (
    echo exit >> %1.bat
  )
  if %%A EQU clr (
    echo cls >> %1.bat
  )
  if %%A EQU for (
    echo for /L %%%%%%B in ^(%%C,%%E,%%D^) do ^( >> %1.bat
  )
  if %%A EQU endfor (
    echo ^) >> %1.bat
  )
  if %%A EQU tit (
    echo title %%B %%C %%D %%E %%F >> %1.bat
  )
  if %%A EQU cpy (
    echo set %%C=%%%%B%% >> %1.bat
  )
  if %%A EQU mov (
    echo set %%C=%%%%B%% >> %1.bat
    echo set %%B= >> %1.bat
  )
  if %%A EQU or (
    echo set /a %%D=%%%%B%%^|^|%%%%C%% >> %1.bat
  )
  if %%A EQU xor (
    echo set /a %%D=%%%%B%%^^^^%%%%C%% >> %1.bat
  )
  if %%A EQU rnd (
    echo set /a math=%%D-%%C+1 >> %1.bat
    echo set /a %%B=%%random%%%%%%%%math%%+%%C >> %1.bat
  )
  if %%A EQU slt (
    echo ping /n 1 localhost ^>nul >> %1.bat
  )
  if %%A EQU sls (
    echo ping /n 2 localhost ^>nul >> %1.bat
  )
  if %%A EQU col (
    echo color %%B >> %1.bat
  )
  if %%A EQU dat (
    echo echo %%date%% >> %1.bat
  )
  if %%A EQU tim (
    echo echo %%time%% >> %1.bat
  )
  if %%A NEQ put if %%A NEQ int if %%A NEQ add if %%A NEQ sub if %%A NEQ mul if %%A NEQ div if %%A NEQ @ if %%A NEQ mrk if %%A NEQ beqrax if %%A NEQ beqrbx if %%A NEQ beqrcx if %%A NEQ beqrdx if %%A NEQ beqeax if %%A NEQ beqebx if %%A NEQ beqecx if %%A NEQ beqedx if %%A NEQ lbl if %%A NEQ hal if %%A NEQ slp if %%A NEQ jmp if %%A NEQ clr if %%A NEQ for if %%A NEQ endfor if %%A NEQ mov if %%A NEQ cpy if %%A NEQ start if %%A NEQ bl if %%A NEQ tit if %%A NEQ or if %%A NEQ xor if %%A NEQ rnd if %%A NEQ slt if %%A NEQ sls if %%A NEQ col if %%A NEQ dat if %%A NEQ tim if %%A NEQ mod (
    echo E01: Instruction not valid, or didn't put comments with "@" or "mrk".
	echo Backend expection: %%A
	echo                    ^^
	echo                    ^| [HERE]
	echo.
	echo Assembled to %1.bat, but with errors! :^|
  )
)
echo Assembled to %1.bat! :)

To use it:

CreativeASM.bat hello.casm

Replace "hello.casm" with the name of the program you want to assemble. Older versions are still avabile in CreativeASM/Assembler/Old Versions