Hi,
I am a C programmer, and now I got a task to write assembly
language (in Linux enviroment) for some time crucial function....
I am not very familiar with gcc. I have written
the following very simple function, it compiles successfully. However
when I run it, I got segmentation fault....
In the C program side, I wrote (main.c):
---------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
long mul(long a, long b, long *c, long *d);
int
main(int argc, char **argv) {
long a, b, c, d;
a=atol(argv[1]);
b=atol(argv[2]);
mul(a, b, &c, &d);
fprintf(stderr, "%ld %ld\n", a, b);
fprintf(stderr, "%lx %lx %lx %lx\n", a, b, c, d);
}
-------------------------------------------------------------------------------------------
The mul fuction is written in Assembly (mul.S) as follow:
(not finished Yet, just simple function doing nothing)
----------------------------------------------------------------------
.text
.align
.global mul
.global _mul
mul:
_mul:
stmdb sp!, {r4-r12, lr} @ push everything onto the stack...
adr r0, Rm_backup
str r1, [r0]
ldmia sp!, {r4-r12, pc} @ return with <lr> destroyed
Rm_backup:
.word 12
Rs_backup:
.word 12
ip_backup:
.word 12
.end
---------------------------------------------------------------------------
The Makefile is
---------------------------------------------------------------------------
CC=arm-linux-gcc
CFLAGS= -Wall -O \
-fforce-mem -fforce-addr -fthread-jumps -fcse-follow-jumps \
-fcse-skip-blocks -fexpensive-optimizations -fregmove\
-fschedule-insns2 -fstrength-reduce -finline-functions\
-fomit-frame-pointer
all: main
main: mul.o main.o
$(CC) $(CFLAGS) -o main mul.o main.o
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o
mul.o: mul.S
$(CC) $(CFLAGS) -c mul.S -o mul.o
-------------------------------------------------------------------------------
The intention in mul.S is to declare 3 local variables,
Rm_backup, Rs_backup and ip_backup and store value of r1 into it
but when I run, I got segmentatin fault immediately. Why???
Another question: can someone tell me how can I implement the
following C functions in ARM assembly language:
1) long mul(long a, long b, long *c, long *d) {
long e=3;
*c=a+e;
*d=*c;
return *d;
}
2) long mul(long a) {
c=a; // c is global variable
return d; // d is global variable...
}
Yick
_______________________________________________
http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
Please visit the above address for information on this list.