-
• #2
Nice! If this were a module, you could do something like this from within an existing module, and it would all 'just work':
var tst1 = require("asm").load("int(int,int)",[0x1840,0x4770]);
The module could also do some more interesting stuff - perhaps using STM32F1Flash to write the data into flash memory, so it can still be used after power off.
-
• #3
Module could be like this
/* Copyright (c) 2014 Juergen Marsch, Pur3 Ltd. See the file LICENSE for copying permission. */ /*! **/ var ASMList,ASMBase; ASMBase = process.memory().stackEndAddress; ASMList = []; exports.connect = function(){ function ASM(){ this.loadArray = function(varName,format,arr){ var a = {name:varName,format:format,start:ASMBase + 1}; for(var i = 0; i < arr.length; i++){ poke16(ASMBase,arr[i]); ASMBase += 2; } ASMList.push(a); eval('var ' + a.name + ' = E.nativeCall(' + a.start + ',"' + a.format + '");'); }; this.loadSD = function(varName,format,fileName){ var arr,fs = require("fs"); arr = new Uint16Array(E.toArrayBuffer(fs.readFile(fileName))); return(this.loadArray(varName,format,arr)); }; this.list = function(){ return ASMList; } } return new ASM(); }
It could be used like this
var x = require("ASM").connect(); x.loadArray("tst1","int(int,int)",[0x1840,0x4770]); require("ASM").connect().loadArray("tst2","int(int)",[0x4770]); require("ASM").connect().loadSD("tst3","int(int,int)","node_binaries/adder.BIN"); console.log(require("ASM").connect().list()); console.log(tst1(2,6) + " should be 8"); console.log(tst2(3) + " should be 3"); console.log(tst3(4,5) + " should be 9");
I can't follow the comment about STM32F1Flash. That module already exists in your collection. Which kind of data would you write from ASM to Flash ?
I would like to keep ASM module as small as possible, so it doesn't add load which is used in special cases only. -
• #4
At the moment, the assembler code is written into RAM at the end of the stack. It means that if you power the board off and back on you'd have to call
loadArray
again (as well as making sure that ASMBase was set).By writing the data into flash, it could be stored there so the functions worked like you'd expect after power cycling (that's what STM32F1Flash can do).
-
• #5
IMHO, STM31F1Flash should support this with a command like copyMem(startAdress,endAdress,length)
It would be a overload for the small ASM module to require STM31F1Flash always. -
• #6
Sorry, I'm not sure I understand. You want another method inside it?
-
• #7
Let me try with other words.
The assembler module is designed to support handling of multiple binaries from everywhere (module or main code). We don't have too much experience with binaries, anyway my expection is that they are stored in memory in most cases. To be useful, the modul should be small.
The decision of storing in Flash is project specific. If somebody wants to copy binaries to flash, it would be helpful to have a function in the module for Flash handling. Some other functions like copy arrays to Flash may also be helpful.
In my project, this is not the case (yet?). Therefore I'm not asking for it. And I will not extend ASM module.
-
• #8
The situation here has now changed a bit...
When you write assembler it's now assembled into a 'flat string' which is stored in the RAM dedicated to variable storage. It means that you can now
save()
assembled code and it'll 'just work'.Loading from flash is now as easy as:
var myFunction = E.nativeCall(1, "JsVar(JsVar,JsVar)", require("fs").readFileSync("myFunction.bin"));
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.