You are reading a single comment by @JumJum and its replies. Click here to read the full conversation.
  • I was searching for a way to handle assembler code.
    Web Editor supports this in a nice way, but how should assembler be treated in modules.
    So a small object was born, which supports loading from array and/or from local sdCard.
    Location for storage are calculated inside the object, so multiple binarys are easy to handle.
    There is also a list of loaded binarys.

    function ASM(){
      this.ASMBase = process.memory().stackEndAddress;
      this.ASMList = [];
    }
    ASM.prototype.loadArray = function(varName,format,arr){
      var a = {name:varName,format:format,start:this.A­SMBase + 1};
      for(var i = 0; i < arr.length; i++){
        poke16(this.ASMBase,arr[i]);
        this.ASMBase += 2;
      }
      this.ASMList.push(a);
      eval('var ' + a.name + ' = E.nativeCall(' + a.start + ',"' + a.format + '");');
    };
    ASM.prototype.loadSD = function(varName,format,fileName){
      var arr,fs = require("fs");
      arr = new Uint16Array(E.toArrayBuffer(fs.readFile(­fileName)));
      return(this.loadArray(varName,format,arr­));
    };
    //convert to a module by uncomment next line
    //exports.connect = function(){ return new ASM(); }
    
    ASMMod = new ASM();
    //load binarys by name, format of variables and array or filename on SD
    ASMMod.loadArray("tst1","int(int,int)",[­0x1840,0x4770]);//add r0,r0,r1  ...  bx lr
    ASMMod.loadArray("tst2","int(int)",[0x47­70]);// bx lr
    ASMMod.loadSD("tst3","int(int,int)","nod­e_binaries/adder.BIN");//same as tst1 loaded as binary file from sdCard
    
    console.log(ASMMod.ASMList);
    
    console.log(tst1(2,6) + " should be 8");
    console.log(tst2(3) + " should be 3");
    console.log(tst3(4,5) + " should be 9");
    
About

Avatar for JumJum @JumJum started