function strtrim(a){return a.replace(/^\s+|\s+$/g,"")}function MiMicILAsm(a){this._def=a}MiMicILAsm.prototype={version:"MiMicILAsm/1.1.0",_exception:new Object(),_def:undefined,OPR_WM:1,OPR_INT:2,OPRSET_NONE:257,OPRSET_WM:258,OPRSET_INT:259,OPRSET_WM_WM:260,OPRSET_WM_INT:261,_log:new String(),assemble:function(a){var g=false;var d=new String();this._log=new String();var c=a.replace(/\r/g,"\n").split("\n");for(var e=0;e<c.length;e++){var b=c[e];if(b.length>0){var f=this._line2bc(e,b);if(d==null||f==null){d=null}else{d=d.concat(this._line2bc(e,b))}}}return d},getErrors:function(){return this._log},_line2bc:function(m,p){var w=this;function n(i,e){w._log+="["+i+"] Line("+m+")"+e+"\r\n"}function o(e,i){var x=(e>>>0).toString(16).toLowerCase();if(x.length>i){n("ERROR","Range Error. value="+e+" digit="+i);throw w._exception}while(x.length<i){x="0"+x}return x}function k(e){return o(e,2)}function r(e){var y=e.split(".");var z=w._def;for(var x=0;x<y.length;x++){if(z[y[x]]==undefined){return null}z=z[y[x]]}switch(typeof z){case"number":case"string":return z}return null}function j(B){if(B==null){return new Array()}var A=B.split(",");var z=new Array();for(var x=0;x<A.length;x++){var y=strtrim(A[x]);if(y.match(/^[a-zA-Z]{1}[0-9a-zA-Z._]+$/)){var e=r(y);if(e==null){n("ERROR","Unknown constant name '"+y+"'");throw w._exception}y=e.toString()}if(y.match(/^0x[0-9a-fA-F]{0,7}[0-9a-fA-F]$/)){z.push({t:w.OPR_INT,v:parseInt(y,16)})}else{if(y.match(/^[0-9]+$/)){z.push({t:w.OPR_INT,v:parseInt(y,10)})}else{if(y.match(/^#[0-9a-fA-F]{0,1}[0-9a-fA-F]$/)){z.push({t:w.OPR_WM,v:parseInt(y.substring(1),16)})}}}}return z}function s(e){switch(e.opr.length){case 0:return w.OPRSET_NONE;case 1:switch(e.opr[0].t){case w.OPR_WM:return w.OPRSET_WM;case w.OPR_INT:return w.OPRSET_INT}break;case 2:switch(e.opr[0].t){case w.OPR_WM:switch(e.opr[1].t){case w.OPR_WM:return w.OPRSET_WM_WM;case w.OPR_INT:return w.OPRSET_WM_INT}}}n("ERROR","Invalid operand type");throw w._exception}function h(x,i,e,y){switch(s(x)){case w.OPRSET_WM_WM:return i+k(x.opr[0].v)+k(x.opr[1].v);case w.OPRSET_WM_INT:return e+k(x.opr[0].v)+o(x.opr[1].v,Math.floor(y/4))}n("ERROR","Invalid operand. 'OP [WM],[WM|INT]'");throw w._exception}function q(i,e){switch(s(i)){case w.OPRSET_WM_WM:return e+k(i.opr[0].v)+k(i.opr[1].v)}n("ERROR","Invalid operand. 'OP [WM],[WM]'");throw w._exception}function l(i,e,x){switch(s(i)){case w.OPRSET_WM_INT:return e+k(i.opr[0].v)+o(i.opr[1].v,Math.floor(x/4))}n("ERROR","Invalid operand. 'OP [WM],[INT]'");throw w._exception}function f(x,e,i){switch(s(x)){case w.OPRSET_NONE:return e;case w.OPRSET_INT:return i+o(x.opr[0].v,2)}n("ERROR","Invalid operand. 'OP [|INT]'");throw w._exception}function c(e,i){switch(s(e)){case w.OPRSET_WM:return i+k(e.opr[0].v)}n("ERROR","Invalid operand. 'OP [WM]'");throw w._exception}function d(e,i,x){switch(s(e)){case w.OPRSET_INT:return i+o(e.opr[0].v,Math.floor(x/4))}n("ERROR","Invalid operand. 'OP [INT]'");throw w._exception}function b(i,e){switch(s(i)){case w.OPRSET_NONE:return e}n("ERROR","Invalid operand. 'OP'");throw w._exception}function t(e,x,i,y){switch(s(e)){case w.OPRSET_WM:return x+k(e.opr[0].v);case w.OPRSET_INT:return i+o(e.opr[0].v,Math.floor(y/4))}n("ERROR","Invalid operand. 'OP [WM|INT]'");throw w._exception}var g=[["AND",function(e){return h(e,"AA","AB",32)}],["OR",function(e){return h(e,"AE","AF",32)}],["XOR",function(e){return h(e,"AI","AJ",32)}],["NOT",function(e){return c(e,"AM")}],["SHL",function(e){return h(e,"BB","BA",8)}],["SHR",function(e){return h(e,"BF","BE",8)}],["ADD",function(e){return h(e,"CA","CB",32)}],["SUB",function(e){return h(e,"CE","CF",32)}],["MUL",function(e){return h(e,"CI","CJ",32)}],["MGET",function(e){return h(e,"DB","DA",32)}],["MPUT",function(e){return h(e,"DF","DE",32)}],["SGET",function(e){return c(e,"EA")}],["SPUT",function(e){return t(e,"EE","EF",32)}],["LD",function(e){return h(e,"FA","FB",32)}],["NOP",function(e){return f(e,"ZA","ZB")}],["CALL",function(e){return t(e,"ZE","ZF",32)}],["EXIT",function(e){return b(e,"ZZ")}],[".END",function(e){return b(e,".E")}],[".D32",function(e){return d(e,"",32)}]];try{var a=function(x){var i=strtrim(x.split(";")[0]);if(strtrim(i).length==0){return null}var e=i.indexOf(" ");if(e<0){return{op:i,opr:[]}}var y={op:i.substr(0,e),opr:j(strtrim(i.substr(e+1)))};return y}(p);if(a==null){return""}for(var u=0;u<g.length;u++){if(g[u][0]==a.op.toUpperCase()){return g[u][1].call(this,a)}}n("ERROR","Unknown instruction '"+p+"'");throw this._exception}catch(v){if(v!==this._exception){throw v}}return null}};