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

Problem with load and store data

Hey all!
I'm using Keil-uV3. Chip LPC2214 (Philips Semiconductors)
I have an external memory device connected to the expansion board.
The external device is using /CS0 and /CS1. Memory bank is 32 bits wide.
When moving data from external memory bank 1(at address 0x81000000) to 10words in bank 0, I wrote:

{
//R1-->address in bank 1
ldr r1,=0x81000000
//R2-->address in bank 0
ldr r0,=0x80000000
//R3=[R0]+10*4
add r3,r0,#40
loop:
LDR R1,[R0] //3MC
STR R1,[R2] //2MC
//Increment R0 to next memcells
ADD R0,#4 //1MC
//Compare with R3
CMP r3,r0 //1MC
//If r0==r3, exit, else return loop
bne loop //3MC

exit:
...
}
Loop waste 10MCs, but my project is only permit it <=6MCs,
I'm trying some way, but can't solve this prob, please help me!
Thanks before!

-----------
Tony Bui

  • Thanks for reply! Maybe I must solve this prob by hardware (using DMA),thought I really don't want so.
    Have some mistakes in previous program, I rewrite <inline>:

    __asm
    {
    //R2-->address in bank 1
    ldr r2,=0x81000000
    //R0-->address in bank 0
    ldr r0,=0x80000000
    //R3=R0+10*4
    ldr r3,=0x80000000
    add r3,#40
    loop:
    //Load data from addr 0x81000000
    LDR R1,[R2] //3MC
    //Then store in -->[R0]
    STR R1,[R0] //2MC
    //Increment R0 to next memory cells
    ADD R0,#4 //1MC
    //Compare with R3, remind: R3=R0+10*4
    CMP r3,r0 //1MC
    //If r0==r3, exit, else return loop
    bne loop //3MC


    exit:
    ...
    }

    _________________
    Tony Bui
    _________________

  • Why not use LDM/STM? This is particularly
    easy with a fixed length. No counting, and
    should be even faster if your memory can burst.

  • ..well, STM anyway. (I only now noticed that
    you're loading from the same place each time.)

  • Maybe I must solve this prob by hardware (using DMA),thought I really don't want so.

    You don't have to.

    If you always have a fixed number of bytes to copy, and memory usage is less important than execution time, you can unroll the loop by simply copying this block 40 times:

    LDR R1,[R2] //3MC
    STR R1,[R0] //2MC
    ADD R0,#4 //1MC

    You assembler might have "repeat" directives that allow repeating a block of code a number of times without explicitly copying it in the source file.

  • Thanks to Christoph Franck!
    Actual, this loop repeats 356 times! (^:^) If I rewrite this block 356 times, it is not a good suggest for my prob!
    To Bruce McKenney: I can't using LDM/STM <invalid>, I'm using Keil uV3, tools CARM, this block is written inline in my project. <main program using C language>
    Thanks again!

    --------------------------
    Tony Bui
    --------------------------

  • Sorry, I think I read it wrong the first time - it repeats 10 times in the above example (loop increment is +4, not +1).

    Actual, this loop repeats 356 times! (^:^) If I rewrite this block 356 times, it is not a good suggest for my prob!<p>

    As I said, your assembler might have directives that allow repeating a block of code without having to explicitly type it. Something along the lines of

    .repeat 356
    <block of code>
    .endr

    Depending on how important memory is, loops can also be partially unrolled, so that the loop counter is checked every X (X > 1) repetitions instead of every single repetition. This reduces the time spent doing (useless) loop condition checks.