Learn To Optimize Code In Assembly… For Android

When programming a microcontroller, there are some physical limitations that you’ll come across much earlier than programming a modern computer, whether that’s program size or even processor speed. To make the most use of a small chip, we can easily dig into the assembly language to optimize our code. On the other hand, modern processors in everyday computers and smartphones are so fast and have so much memory compared to microcontrollers that this is rarely necessary, but on the off-chance that you really want to dig into the assembly language for ARM, [Uri Shaked] has a tutorial to get you started.

The tutorial starts with a “hello, world” program for Android written entirely in assembly. [Uri] goes into detail on every line of the program, since it looks a little confusing if you’ve never dealt with assembly before. The second half of the program is a walkthrough on how to actually execute this program on your device by using the Android Native Deveolpment Kit (NDK) and using ADB to communicate with the phone. This might be second nature for some of us already, but for those who have never programmed on a handheld device before, it’s worthwhile to notice that there are a lot more steps to go through than you might have on a regular computer.

If you want to skip the assembly language part of all of this and just get started writing programs for Android, you can download an IDE and get started pretty easily, but there’s a huge advantage to knowing assembly once you get deep in the weeds especially if you want to start reverse engineering software or bitbanging communications protocols. And if you don’t have an Android device handy to learn on, you can still learn assembly just by playing a game.

11 thoughts on “Learn To Optimize Code In Assembly… For Android

  1. It’s not ARM or Intel assembly, but MIPS has a wonderful set of simulators thanks to it’s use teaching in universities. Last I checked Mars was the best of these, not that it’s under very active development.

  2. Nice! I have done my share of Android programming with ADT (their customized Eclipse), but I welcome this chance to break loose from the accursed IDE and get a little more cozy with my phone.

    1. +1
      Good point, the bloated ‘standard’ ide for Java at present bit complex and needs good platform, though the real-time power reporting pretty good, it is a lot to wade through just to get simple stuff started that is outside a few std deviations of most app requirements…

  3. IMHO, HaD needs the love button. I just love this article! Thank you so much for the link to this awesome story! Brings back so much good memories of DOS times. Would now really be nice to see a minimal working APK, showing the Hello World message box.

  4. One of the easiest methods to get in contact with ARM Thumb2 assembler code may be MicroPython.
    It gives you a convenient and well working environment, while allowing to use inline assembler code by using the @micropython.asm_thumb decorator.
    And you can also easily exchange data between assembler and Python code, so you can harvest the speed of assembler for time critical routines, while still having the convenience of python for user interaction, file I/O, floating point math, etc.

    https://docs.micropython.org/en/latest/reference/asm_thumb2_index.html

  5. Nice post, will be checking it out.
    My eldest son who is back from MIT to Perth, Western Austrakua wrote a java app for the Samsung S2-S6 to display data from a simple voltage/current DC logger but, with a rather different graphical format that for the technically proficient user and neophyte alike balances content (plus options) with just enough complexity whilst offering simple indication of trend/history. The only issue with the android graphics interface is the constant page refreshing/switching as a whole which isn’t as efficient as updating the changed elements on that single page. Ie. The graphics side set up to swap whole pages by default other than the system letting us know where the current screen page is in memory do we can just amend the relevant pickles, this would be a great boon to not just efficiency but a few other effects too like suitably sized embedded MP4 though for a different reason entirely in commercial day analytics – nuff said ;-)
    Once I’ve better understood the assembler layout and cpu/thread programming model I can run some tests to get the nitty gritty of how to access the current page and find the relevant bits to ensure refreshed correctly. Will still need a java front end but, with my code inserted with appropriate debug indicators…
    Thanks for post, great prompt to make progress finally, cheers :-)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.