News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Android command-line environment for programming in ARM64 assembly language

Started by lucho, December 01, 2024, 09:10:17 PM

Previous topic - Next topic

lucho

Today, ARM64 (a.k.a. "aarch64") and Android are undoubtedly the most widely used instruction set architecture (ISA) and operating system (OS), respectively. So, let's pay special attention to the assembly language programming environment for this ISA in this OS.

Recently, I found out that unlike the UserLand command-line Linux environment, the similar Termux environment allows debugging with the GNU Debugger (gdb). In order to install Termux, you may have to allow installation from "unknown sources". After you install it, run the following commands:

termux-change-repo
pkg upgrade
pkg install binutils clang make gdb

Now you can build, run and debug (including step-by-step) all text-mode programmes written for Linux on your Android-based smartphone or tablet without having to buy a Raspberry Pi, an Orange Pi or a similar ARM64-based computer.

If you execute the following command, you can monitor the register values in real time in full screen (TUI) mode (press Ctrl-L to redraw the screen if output has shifted the windows up):

echo -e "tui enable\nlayout regs" >> .gdbinit



And if you execute the following commands (see this page for info on the first one)

termux-setup-storage
pkg install openssh
echo "pgrep sshd > /dev/null || (sshd && echo 'sshd started')" >> ../usr/etc/termux-login.sh

then you can login remotely to your Android device using SSH like this (omitting the angle brackets):

ssh -p 8022 <IP_address>

and copy files to and from it via "scp" (some Android folders are accessible too at "/storage/emulated/0"). Run "ifconfig" in Termux to find out the IP_address assigned to your Android device. See the Termux Wiki for more info, e.g. on authentication. You may also want to ensure the device stays "awake" while charging to prevent it from "falling asleep" during SSH sessions. To run CPU-intensive tasks from SSH, some Android versions require that Termux stays in the foreground.

NOTES

If your Android version is 12 or later, you may need to disable the so-called "phantom process killer" in order to avoid unexpected terminations of Termux indicated by the "[Process completed (signal 9) - press Enter]" message you may suddenly get. (If your Android version is 14 or newer, there is a much simpler method – just go to Settings → Developer Options → Disable child process restrictions. If the "Developer Options" menu is not shown, you need to enable it first.)

If you use a Bluetooth or USB keyboard, you can disable the terminal toolbar with extra virtual keys that appears by default at the bottom of the Termux window by pressing the "K" key of that keyboard while holding the "Volume Up" button of the Android device. With such a keyboard, you can also alter the font size by pressing the "-" or "+" keys while holding "Ctrl" and "Alt".

If your device is made by Huawei, you may see large strips on both sides of the Termux window in landscape mode. The fix to this is described here.

CAVEATS

The drawback of Termux is that unlike UserLand, it doesn't support 32-bit and 64-bit programs at the same time. To develop 32-bit programs, the "armeabi-v7a" version of Termux is needed. And it cannot be installed on the same device along with the "arm64-v8a" version.



32-bit programs (as in the above and below "gdb" screenshots) are supported only if your CPU cores are "Cortex-Axx" (where xx is a 2-digit number) and your Android version is below 14. If your CPU cores are "Cortex-Axxx" (where xxx is a 3-digit number) or your Android versions is 14 or newer, they're not supported.

See Settings → About and find your processor shown there in this template to find out its "Cortex-A" core number. If no Android version in shown in Settings → About, see this list of custom Android Distributions to find out the Android version your operating system is based on.


TimoVJL

Is any Android emulator good for testing ?
I tested one some time ago and it was big, awful and very slow.
May the source be with you

lucho

Haven't thought about it. What operating system are you using? If it's Windows 10 or 11, wouldn't it be better to install text mode Linux in it?