When is assembly necessary?

Posted on
  • This page http://www.espruino.com/Compilation says that there are moments when you would want your code to run faster than normal speeds you get from source code, I'm curious if anybody has ever genuinely been in that situation (I'm just a beginner and don't know any situations that would call for a microcontroller to transmit over 5KHtz unless you were trying to drive a motor or something)?

  • #assembly #assembler #performance

    Espruino Javascript is great for high-level things, but when it comes down to move byte by byte - and even worse - bit by bit - around, then the system is more busy with running all the niceties of the environment then actually doing the work. I see the hybrid approach the best... and that is genuinely taken by Espruino. Things that have to go fast are low-level implemented with an easy access interface on the Javascript (interpretative) level.

    When I did graphics, such as retrieving bytes to store them away to later restore them, assembler / native is the answer... (not just because I was accessing the bytes SPI, but also the number of bytes: n bytes per pixel.

    Regarding your 5KHz transmission thing... what kind of code would be in that loop of 5KHz?... because already an empty loop is slower... (see about performance). When @JumJum and I did meddle around with ILI9341 driven 320x240 262K Color LCD, speed became of essence... Even when I used it for driving a Stepper Motor in continuous mode, I touched the limit. Others have tried to work with cheap RF / wireless, and it is just not enough juice in the setup... except low level things move into native...

    Therefore, for time critical things, have sub controllers that do nothing else than just run, for example, the stepper continuously, or do transmission continuously... and interface them easily with Espruino over what ever communication interface is available on the coarse granularity of whole messages / information packages, etc. Espruino may be able to run one device on a low level, bit / byte banging thing, but everything has to wait, and when the system is busy with something else and the time for bit / byte banging is there, it will miss it... (not completely because Espruino has an event queue to survive input/interrupt bursts... but that means that times of bursts have to be followed by low activity / down times so the queue can be worked through).

    When talking performance, Espruino's power consumption performance has to be taken into consideration... and in that respect Espruino is at the top...

  • I think @allObjects has probably hit everything there...

    My personal feeling is Espruino is fine (without any assembler/compiled code) for 95% of things you might want to do - especially if you're willing to write your code in a way that works well with the interpreter.

    The Assembler is there for the other 5% - it'll be much harder to use than if you wrote JavaScript, but it means that if you hit problems it's not a matter of ditching Espruino and going for a platform that's all compiled ahead of time - you can just fix the one problem you were having with Assembler and can then carry on in JavaScript.

    The compiler is a sort of a halfway house - hopefully it'll mean you can do 98% of things, all in JavaScript - but it's not going to be a magic bullet for 'compiled' performance on everything.

    As things like compiled code get a bit more mature, the plan is also to use them in modules - so things like Stepper motor control will 'just work' at very high speeds, and you won't have to care how.

  • if you hit problems it's not a matter of ditching Espruino and going for a platform that's all compiled ahead of time

    Absolutely,... because:

    I did Arduino stuff for a while... but when I 'bumped' into Espruino, I didn't hesitate a split second - measurable not even with assembly - and ordered it, including some other devices, such a GPS, TFT display, wifi,... There is so much in an app that doesn't need at all the attention of a compiled/compilable language... but still having the option to have pieces in native for runtime makes Espruino even more the platform of choice ... and the capability of inline machine code/assembly and compiled directive grows by the hours right now.

    Having to do everything in Arduino style was just too much nitty gritty.

    Just too bad I bumped not earlier into Espruino, such as at the kickstarter. So I made sure to be with the pico kickstarter - which very very successfully passed it's funding (in 3 days it made it to 100%, and in 30 - and finally 400..500%) and is about to be delivered. Looking forward to it to be THE link between my computing device - Laptop / Tablet / Phone - and my electronic project gadgets - either tethered over USB or wireless over wifi. And very good news is the fact that the very same software runs on standard AND pico board.

    More and more of the connectible devices / modules come with very powerful processor(s) and built in firmware, that makes it easy to use them in the Espruino context. Furthermore, the development with it's testing / motoring option (way beyond a console test output, see, for example, Test OR / AND operations UI and more to come soon) makes the whole thing a package of choice.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

When is assembly necessary?

Posted by Avatar for user52526 @user52526

Actions