very simple program does not work

OP #2631431
Rate this post
useful
not useful
Hi,
I am starting with ARM but the simplest program does not work:

.text
.align 4
.global _start
.func _start
_start:
mov r1, #4
.size _start, . - _start
.endfunc
.end

I can compile with 'as' and link with 'ld', but when I run the program I 
get:
Illegal instruction

Where am I going wrong?

Thnaks
Guest #2631515
Rate this post
useful
not useful
Do you cross compile? Is that a standalone program or do you use some 
os?

I'm confused about "but when I run the program I get" means.
Are you sure your directives are correct? I mean is that a valid program 
entry?
OP #2631551
Rate this post
useful
not useful
thanks for your response Chillito.

I do not cross compile, I compile on a Debian system running on ARM 
processor and I run the program from the OS.

Yes I am sure the directives are fine, otherwise the assembler (GAS) 
would have complained.

I have tried to end the program with
SWI 0x11
But that gives segmentation fault when I run it.

I'm not sure how to explain "when I run it I get" further. The compiled 
program is called "mini" and when I type
# ./mini
The OS responds with:
Illegal instruction

regards
OP #2631885
Rate this post
useful
not useful
Guenther,

Although I am grateful for your now sensible response, I find it unfair 
that you accuse me of not making an effort. I have been spending the 
whole day on this problem and did numerous searches on the web for 
simple ARM programs, without succes.

The link you gave me is not realy a solution in assembler, it is just 
some code EMBEDED in C. What I need (for educational purpose) is a 
solution in pure assembler, which I can make with "as" and "ld".

I assure you that Google cannot find such an example or tutorial, hence 
my question on this forum.

And also the 'ret' instruction is not part of the ARM instruction set.

I think I realy need an expereinced ARM programmer to enlighten me.

regards

Gijs
OP #2632416
Rate this post
useful
not useful
You are not only rude Jim, but also too stupid to understand my previous 
post about EMBEDDED C code. Your link is just an other example of 
embedding ASM in C and that is not what I am after (also that example 
does not compile properly).

Maybe you better first learn to read before calling people names, now 
you look a bit silly.
Guest #2632423
Rate this post
useful
not useful
/* syscall exit(int status) */
mov     %r0, $0     /* status -> 0 */
mov     %r7, $1     /* exit is syscall #1 */
swi     $0          /* invoke syscall */

Does that help you in any way? That is part of a google result. Well 
seems to be a "plain asm  arm hello world" example for android, but it 
could be of value for you.
Since, as you noticed, I'm no arm expert at all and must rely on my 
intuition for helping you, no guarantee your problem is solved with that 
info. Maybe it is a hint.
OP #2635652
Rate this post
useful
not useful
I finally solved this problem, hurray!

After more digging I found and downloaded a package called FASMARM.
In one of the examples there it showed a way of ending a program 
properly with:
1
SWI 0x900001

So apparently you need 90 in the high order byte to call a system 
service for ARM processor.
Now it works, also using GAS (GCC assembler).
Thanks all.

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now