Translate

vineri, 29 decembrie 2023

how build a assembly compiler for atmega328 in javascript

 I build here an assembly compiler for atmega328 in javascript https://www.costycnc.it/avr-hex-uploader/

Buid an html document with a textarea box and a js script to read textarea box :

<html>

<body>

<textarea id="code" cols="50" rows="20"> </textarea>

<button onclick="compile();">Compile</button>

<script>

         // for verify https://regex101.com/

var regex=/^[\t ]*(?:\.def\s+(\w+),(\w+)|\.org\s+(\d+)|(\w+):)?/;

                  //this regex if  ".def PINB1,1" return [1]="PINB1",  [2]="1"
                  //this regex if  ".org 00" return [3]="00"
                  //this regex if  ":abc" return [4]="abc"

function compile(){

         var input=document.getElementById("code").value;

         var lines = input.split('\n'); 

          for (var i = 0, l = lines.length; i < l; i++) {  

                       var match = regex.exec(lines[i]); 

  console.log("param1:", match[1]);

 console.log("param2:",match[2]);   

 console.log("param3:",match[3]);   

  console.log("param4:", match[4]);   

}

                 }

 

</script>

</body>

</html>