Things I've learned and suspect I'll forget.
I wanted to play with some ARM over the weekend, but unlike x86, I don't have an arm development environment. I'll need a way to compile arm binaries within x86 and then test them out on an ARM device. One easy (and free) solution for this is to write the assembly in linux, cross compiled for ARM, and then test the code inside the Android Emulator. The Android Emulator is a full emulator, and so it not only gives developers the ability to test their Java code, but also any native ARM code they developed for Android.
Steps:
.syntax unified
.data
message:
.asciz "Hello, world.\n"
len = . - message
.text
.global _start
_start:
mov r0, $1
ldr r1, =message
ldr r2, =len
mov r7, $4
swi $0
mov r0, $0
mov r7, $1
swi $0
$ ~/tools/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-as -o helloworld.S helloworld.s
$ ~/tools/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld -o helloworld.exe helloworld.S
$ emulator -avd Android21 &
[1] 16467
# adb -e shell will let you execute any command on the device
abd -e shell "mkdir /data/data/test"
adb -e push "helloworld.exe /data/data/test"
# need to set permissions for execution
adb -e shell "chmod 777 /data/data/test/helloworld.exe"
# lets try to execute
adb -e shell "/data/data/helloworld.exe"
Hello, world.
published on 2012-11-03 by alex