This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Something about  mixed programming,C and Assembly

Note: This was originally posted on 28th August 2011 at http://forums.arm.com

Recently I am learning ARM11.in fact ,I am a beginner for ARM.
The processor I use is S3C6410,with ARM1176JZF-S core.Someone who has used this should know that the processor support SD-boot,the way i choose.
The steps to make my program run: first,compile and link the program,generate the binary file.second ,use Winhex tool to copy the content in the binary file to the specific sectors in SD card,where should place the BL1 when using OS.Then put the SD card in the slot,and Power on,the program will run on the processor.

I tried writing the code with assemblylanguage at first,and it worked,the program ran as wished.the assembly code is as followed:


------------------------------------------------------------------------------------------------------
;pheriperal circuit : each of the four ports GPK4 to GPK7 connect a LED

;if this program runs,the four LEDS get on and off one by one
rGPKCON0     EQU 0x7F008800;                       
                        AREA    LED1,CODE,READONLY    ;
                        ENTRY                ;
                        CODE32                ;            
START
                        ldr r0,=rGPKCON0;
loop
                        ldr r1,=0x00010000;
                        str r1,[r0];
                        bl delay;
                        ldr r1,=0x00100000;
                        str r1,[r0];
                        bl delay;
                        ldr r1,=0x01000000;
                        str r1,[r0];
                        bl delay;
                        ldr r1,=0x10000000;
                        str r1,[r0];
                        bl delay;
                        b loop;
delay
                        ldr r3,=0x4ffff;
tag
                        sub r3,r3,#1;
                        cmp r3,#0x0;
                        bne tag;
                        mov pc,lr;   
                        END
-------------------------------------------------------------------------------------------------------


After this little success,I began another project.I put an assembly source and a C-sourcefile in one project. codes are as followed:



------------------------------------------------------------------------------------------------------

;***code in a.S

                        AREA    LED1,CODE,READONLY
                        IMPORT   xmain
                        ENTRY               
                        CODE32                                                         
START
      b xmain
      END



//*****code in a.c


#define GPKCON0 (*(volatile unsigned *)(0x7F008800))//
#define GPKDATA (*(volatile unsigned *)(0x7F008808))
void delay(int);
void xmain()
{
GPKCON0=0x11110000; //config GPK4-GPK7 as output ports
while(1)
{
GPKDATA=0x000000f0;//led off
delay(20);
GPKDATA=0x0;  //led on
delay(20);

}

void delay(int B)
{
int a=400000;
while(b--)
while(a--);

}


------------------------------------------------------------------------------------------------------


This project still succeeded to compile,0 errors.But when I copy the generated binary file to SD card and Power on,nothing happenned,the LEDs all kept off .It seemed that the program had't run at all!



But,if I remove the "delay" fuction from the code,include the function declaration and the definition, and put several lines of code which have the same effects with the function "delay"  where there used to be a calling for "delay", like this:


---------------------------------

......

while(1)
{
GPKDATA=0x000000f0;//led off
//delay(20);
a=8000000;
while(a--);
GPKDATA=0x0;  //led on
//delay(20);
a=8000000;
while(a--);


......

---------------------------------

then the generated binary file can run in the processor!


So I am confused.I think the effects should be the same,but they aren't.
Can it be that the C fuctions are not allowed to call another sub function in mixed-programing ,or I should add something in my code or config something to guide aARMlinker in RVDS2.2 to link my program correctly?



Another strange thing ,in RVDS environment, it seems that the RO_base doesn't influence the program.I have tried give it different numbers,but it makes no difference,the program can always run normally if I use the valid code.  I am not very clear what the RO_base stands for and why it make no difference.



0