flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Non-x86 architectures > hello world using fasm (arm) for android

Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 6328
Location: ˛                              ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣ Posts: 6699
if there are a guide on, how to do hello world using fasm (arm) for android, maybe kinda cool,
Post 09 May 2014, 06:47
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000

sleepsleep wrote:
if there are a guide on, how to do hello world using fasm (arm) for android, maybe kinda cool,



Compile with FASMARM (1.71.13)


Code:

        format ELF executable
        entry start

        segment readable executable

start:
        mov     r01
        mov     r1hello
        mov     r2len
        mov     r74 ; sys_write
        svc     0
    
        mov     r01
        mov     r71 ; sys_exit
        svc     0

hello:
        db      'Hello world android',10
len  =  $-hello 




Using adb.exe

Code:

adb push hello_world /sbin/hello_world
adb shell chmod 777 /sbin/hello_world
adb shell /sbin/hello_world




Above code can also be included in an app and executed at run time.

NOTE: I have a rooted phone so I'm able to throw stuff in that directory.
Post 31 May 2014, 07:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14588
Location: Planet Dirt
To make the code a bit more flexible you can do this:

Code:
;...
adr r1,hello
;...

Post 31 May 2014, 08:07
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
Oh. Lol, after banging my head I thought you'd moved it here.

And yup,

mov r1, hello
ldr r1, [hello]
adr r1, hello
Post 31 May 2014, 08:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14588
Location: Planet Dirt
ldr won't do it for you unless you put a pointer there.
Post 31 May 2014, 08:26
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14588
Location: Planet Dirt
Note that the reason I suggest using adr instead of mov is because by default fasmarm will use all available instructions from all architecture versions. So the mov will use the v7/T2 wide encoding to create "movw r1,0x8074". Whereas using adr will encode "add r1,r15,0x14" which is relocatable.

BTW: It is also advisable to use the processor and coprocessor directives to tell fasmarm which instructions are available. Without these you may get unavailable encodings for your particular CPU.
Post 31 May 2014, 11:38
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 6328
Location: ˛                              ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣ Posts: 6699
ok, this is cool, and i wanna say thank you first to typedef.
Post 31 May 2014, 17:21
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1179
Location: Athens
Hi all,

I have tested typedef's example using fasmarm and adb.exe as suggested above (day 1 in arm).
Then i try a string copy, but the code outputs nothing.


Code:

 format ELF executable
 entry start 

 segment readable executable 

start:
 mov    r1src
 mov    r0dest

strcopy
 ldrb   r2, [r1], 1
 strb   r2, [r0], 1
 tst    r2r2
 bne    strcopy

 mov     r01
 mov     r1dest
 mov     r25
 mov     r74   ; write syscall
 svc     0

 mov    r00  ; exit
 mov    r71
 svc    0

 src    db "12345",0
 dest   db "00000",0 


Post 01 Feb 2015, 11:54
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1179
Location: Athens
I would really appreciate a hint.
Post 01 Feb 2015, 19:22
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14588
Location: Planet Dirt
Which system are you using? Perhaps "svc 0", or the parameters you are passing, or the file format, is the problem because the copy code appears to be fine. Also the the note above about using "adr" instead of "mov" to get your code relocatable. And use the "processor" directive to avoid any silliness with incompatible CPUs.
Post 02 Feb 2015, 00:45
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1179
Location: Athens
Hi revolution,

I have windows xp connected with my android phone (CPU:ARM Cortex A7, GPU:ARM Mali-400 MP1) via usb cable. typedef's code along with few other tiny scripts i wrote are working, but the code above outputs "Segmentation fault" at my phone's terminal window. How to workaround this?
Post 02 Feb 2015, 20:09
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14588
Location: Planet Dirt
Did you try with ADR? Did you use the proper PROCESSOR setting?
Post 03 Feb 2015, 01:07
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1179
Location: Athens
I used adr but the error remains. What can be the correct settings in my case, can you show me a processor setting example ?
I noticed that whenever i use strb i am getting a "Segmentation fault".

p.s. I appreciate the assistance.
Post 03 Feb 2015, 07:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14588
Location: Planet Dirt
Perhaps the Android system enforces the read only attribute you used?

Code:
segment readable executable

Post 03 Feb 2015, 07:24
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1179
Location: Athens
Golden reply, thank you. Smile

I struggled enough and lost my temper for a while.
Post 03 Feb 2015, 17:04
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.