The MASM Forum

64 bit assembler => UASM Assembler Development => Topic started by: mazegen on January 04, 2020, 02:31:12 AM

Title: Building and running Android x86 sample
Post by: mazegen 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.

sample.asm:

.686
.MODEL FLAT

STDOUT      equ 1
SYS_EXIT    equ 1
SYS_WRITE   equ 4

.DATA
msg DB "hellow from android", 13, 10

.CODE
_start:
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


Assemble:

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