Yick,
I'm not too sure how much improvement you will be able to make by using assembler, but I think I can answer your questions...
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???
You have declared the 'variables' in a .text (ie program code) section of the assembler file. When you try and write to one of them it is the same as writing over program code. To prevent the problem, you need to put them in the '.bss' section (or the '.data' section if they are statically initialised).
Can you tell me how can I implement the following C functions in ARM assembly language:
Try compiling each one with 'gcc -S -O2 -fomit-frame-pointer'...
------------------------------------------------------------ long mul (long a, long b, long *c, long *d) { long e=3;
*c=a+e; *d=*c; return *d; } ------------------------------------------------------------
gives:
------------------------------------------------------------ @ Generated by gcc 2.95.2 19991024 (release) for ARM/elf .file "tst.c" gcc2_compiled.: .text .align 2 .global mul .type mul,function mul: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, current_function_anonymous_args = 0 add r0, r0, #3 str r0, [r2, #0] str r0, [r3, #0] mov pc, lr .Lfe1: .size mul,.Lfe1-mul .ident "GCC: (GNU) 2.95.2 19991024 (release)" ------------------------------------------------------------
------------------------------------------------------------ static long c = 12; static long d = 12;
long mul (long a) { c=a; // c is global variable return d; // d is global variable... } ------------------------------------------------------------
gives:
------------------------------------------------------------ @ Generated by gcc 2.95.2 19991024 (release) for ARM/elf .file "tst2.c" gcc2_compiled.: .data .align 2 .type c,object .size c,4 c: .word 12 .align 2 .type d,object .size d,4 d: .word 12 .text .align 2 .global mul .type mul,function mul: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, current_function_anonymous_args = 0 ldr r3, .L3 ldr r2, .L3+4 str r0, [r3, #0] ldr r0, [r2, #0] mov pc, lr .L4: .align 2 .L3: .word c .word d .Lfe1: .size mul,.Lfe1-mul .ident "GCC: (GNU) 2.95.2 19991024 (release)" ------------------------------------------------------------
Andre --
__________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com