Author Topic: Building and running Android x86 sample  (Read 457 times)


  • Regular Member
  • *
  • Posts: 7
Building and running Android x86 sample
« on: January 04, 2020, 02:31:12 AM »
The Android code is actually the same as the Linux32\Linux1.asm sample.

You need an x86 Android device (rare now) or emulator such as Bluestacks to run it.

You also need Android SDK and NDK (SDK because of Android Debug Bridge adb.exe, NDK because of linker ld.exe).

You don't need to root the device/emulator.


Code: [Select]

STDOUT      equ 1
SYS_EXIT    equ 1
SYS_WRITE   equ 4

msg DB "hellow from android", 13, 10

 mov eax, SYS_WRITE
 mov ebx, STDOUT
 mov ecx, offset msg
 mov edx, sizeof msg
 int 80h

 mov eax, SYS_EXIT
 mov ebx, 0
 int 80h

END _start


uasm64.exe -elf sample.asm

Link (the exact path depends on your NDK version):

%ANDROID_NDK_PATH%\toolchains\x86-4.9\prebuilt\windows-x86_64\i686-linux-android\bin\ld.exe -o sample.out --format elf32-i386 sample.obj

You should get sample.out executable file.

Copy to device (/data/local/tmp/ is usually available on all devices and emulators):

adb.exe push sample.out /data/local/tmp/

Set read and executable rights for all users:

adb.exe shell chmod 555 /data/local/tmp/sample.out

Run it:

adb.exe shell /data/local/tmp/sample.out