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

storing two programs at different memory location

Hello All,

I want to write some algorithm (program) in C and store it in some specifc memory area .In between my assembly code I would like to call my C routine stored at specific memory location.I wud like to know where i could store the algorithm ..I dont want this algorithm to be stored along with the memory area where my original program resides...I am giving an example below....


AREA PROGRAM,CODE, AT 0x40000000
ENTRY

//(a*b)+(c+d)
LDR r0,=numbers
ldr r1,[r0],#4 //a
ldr r2,[r0],#4 //b
ldr r3,[r0],#4 //c

function(1102);//this is the function writen in C that I want to store at some specific memory location.I would lie to know where I could store this and how I can insert a C fuction in between an assembly program?
ldr r4,[r0],#4 //d
mul r2,r1,r2 //a*b
add r3,r3,r4 //c+d
add r4,r3,r2 //(a*b)+(c+d)
str r4,[r0,#4]


AREA DATAMEM ,DATA,READWRITE

numbers :DD 0x5,0x6,0x7,0x8

End


looking for your help.

t.senthil

Parents
  • The linker controls where segments of the program live. See chapter 9 of the Assembler/Utilities manual -- in particular, the section "Segment and Memory Location Controls" (page 331 in my version).

    You'll want your C function to be in its own .c file. A .c file corresponds to a single code segment named ?CO?filename. You can then locate that segment whereever you wish.

    To put that segment in the middle of other code, you'll need to break that other code into at least two segments (two files), if it's not already. You can then use the linker directives to assign the order of segments and fixed addresses as you wish.

    If you're planning on jumping to a fixed address (rather than using public/extern and linking, or using some sort of vector table), you should probably disable the optimizations for common entry/exit code. Sharing code in the procedure entry seems like it would be likely to make the job of starting at the real beginning of the function harder.

Reply
  • The linker controls where segments of the program live. See chapter 9 of the Assembler/Utilities manual -- in particular, the section "Segment and Memory Location Controls" (page 331 in my version).

    You'll want your C function to be in its own .c file. A .c file corresponds to a single code segment named ?CO?filename. You can then locate that segment whereever you wish.

    To put that segment in the middle of other code, you'll need to break that other code into at least two segments (two files), if it's not already. You can then use the linker directives to assign the order of segments and fixed addresses as you wish.

    If you're planning on jumping to a fixed address (rather than using public/extern and linking, or using some sort of vector table), you should probably disable the optimizations for common entry/exit code. Sharing code in the procedure entry seems like it would be likely to make the job of starting at the real beginning of the function harder.

Children
  • in C and store it in some specifc memory area .In between my assembly code
    anyhow, why the fixed address, it is 117 times easier to just link the .obj or - even - have it in a library.

    It this one of these fancy schemes to hide some code from someone, if it is, the 2 above suggestions do not disclose anything more than "stored in a fixed location" would.

    Erik

  • Hello all,

    Thanks for all your replies.Well my plan is to remove the common or repeating code from my main program and keep those common code in a seperate memory as some function and call the fuction whenever the corresponding instruction (repeated instruction ) has to be executed.In my example ,function(1102) corresponds to the function which has the common code that appears in my main program.

    That's why i would like to place this function in some memory area other than the memory area where my main program code sits.Which memory area will apt for placing this function() code?

    looking for ur ideas.
    t.senthil

  • In that case, why is the exact address of the function important? Just declare the function's existence to the assembler with EXTERN and let the linker resolve the address.

    Programmers usually run into a need to specify the address when their program is delivered or upgradable in separate pieces. For example, there might be a library of flash routines in ROM, and an upgradeable application in rewritable flash. The app code has to be able to call the flash library; one way to do that is to specify the exact entry points of the library calls.

    But the situation you describe sounds like the normal use of a function -- to gather up repeated code into a resuable subroutine. Usually it's not important where each function actually lives. People invented linkers to avoid having to do that work by hand.