EmbDev.net

Forum: ARM programming with GCC/GNU tools very simple program does not work


Author: Gijs v. (gijs_v)
Posted on:

Rate this post
0 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

Author: Klaus Wachtler (mfgkw)
Posted on:

Rate this post
0 useful
not useful
I never wrote ASM for ARM, but as far as I see there is no loop and no 
program end.
What shall it do after the move? I assume it runs arbitrary code after 
the move.

Author: Gijs v. (gijs_v)
Posted on:

Rate this post
0 useful
not useful
thanks Klaus.

So I should rephrase my question to: how do I end my ASM program?
I expected the .end directive told the assembler to do so, but perhaps 
not.

regards

Gijs

Author: Chillito (Guest)
Posted on:

Rate this post
0 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?

Author: Gijs v. (gijs_v)
Posted on:

Rate this post
0 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

Author: Günther (Guest)
Posted on:

Rate this post
0 useful
not useful
With this information, there might be more to help you.
Try ret and then the .end directive. The directive will not
terminate the process. that is why you get illegal instruction.

Author: Klaus Wachtler (mfgkw)
Posted on:

Rate this post
0 useful
not useful
Since you have defined a function _start i assume it will be called by 
some startup code as a function.
So I guess you miss a ret instruction to return to the caller (which I 
hope terminates the program).

Perhaps you should search for docu or a working example?

Author: Günther (Guest)
Posted on:

Rate this post
0 useful
not useful
Gijs, you do not seem to be interested in finding a solution on your 
own. As far as you told us, your setup seems proper and easy. So, you 
only need an assembler (your first post suggests you already have) AND a 
hello world arm asm source.

So you want us to find a hello world program for you???

http://blogs.arm.com/software-enablement/139-hello...

Author: Gijs v. (gijs_v)
Posted on:

Rate this post
0 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

Author: Jim Meba (turboj)
Posted on:

Rate this post
0 useful
not useful
> I assure you that Google cannot find such an example or tutorial, hence
> my question on this forum.

Now we KNOW you are a troll:

http://blogs.arm.com/software-enablement/139-hello...

This was the first Link that Google gave me in my first try:
http://www.google.com/search?q=arm+asm+Hello+World

You might want to learn how to google first.

Author: Gijs v. (gijs_v)
Posted on:

Rate this post
0 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.

Author: Chillito (Guest)
Posted on:

Rate this post
0 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.

Author: Günther (Guest)
Posted on:

Rate this post
0 useful
not useful
Hey Gijs,
somehow I still have the feeling your are not "really" searching on your 
own.

The first result when googling "arm assembly" is

http://www.eng.auburn.edu/~nelson/courses/elec5260...

and that document is full of sample codes in "real" ARM assembly.

The examples show that "ret" is called "SWI &11" on ARM.

Author: Gijs v. (gijs_v)
Posted on:

Rate this post
0 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:
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

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.