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
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.
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
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?
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
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.
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?
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-world-in-assembly/
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
> 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-world-in-assembly/ 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.
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.
/* 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.
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_6260/ARM_AssyLang.pdf and that document is full of sample codes in "real" ARM assembly. The examples show that "ret" is called "SWI &11" on ARM.
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:
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.