■Memcpy_Single

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#if EXAMPLE == 11
void MemFill(unsigned long ptr,unsigned long pattern,int size)
{
    long *= ptr;
    while(size--)
    {
        *s++ = pattern;
    }
 
}
void MemDump(unsigned long ptr,int size)
{
    long *= ptr;
    while(size--)
    {
        Uart_Printf("[%x]  ",*s++);
        if(size%4==0)
        Uart_Printf("\n");
    }    
}
 
 
void Main(void)
{    
unsigned char ch;
 
    unsigned long src = 0x33000000;
    unsigned long dst = 0x33100000;
    int size = 12;
    unsigned long pattern;
    MemFill(src,0x00000000,size);
    MemFill(dst,0x00000000,size);
    Uart_Printf("Start Memory copy test\n");
 
    pattern = 0x5555aaaa;
    Uart_Printf("\nFill pattern [0x%08x] to [0x%08x]\n",pattern,src);
    MemFill(src,pattern,size);    
    
    Uart_Printf("Dump Memory from [0x33000000] to [0x33000030]\n");
    MemDump(src,size);
    Uart_Printf("\nCopy from [0x%08x] to [0x%08x] by use LDR/STR\n",src,dst);
 
    MEMCPY_SINGLE(dst,src,size);
    Uart_Printf("Dump Memory from [0x33100000] to [0x33100030]\n");
    MemDump(dst,size);
            
}
# endif  
 
 
/******************************ARM*************************/
    .globl MEMCPY_SINGLE
 
MEMCPY_SINGLE:
    LDR    r3,[r1],#4
    STR    r3,[r0]
    add    r0,r0,#4
    subs r2,r2,#1
bne    MEMCPY_SINGLE
    mov pc,lr
/******************************ARM*************************/
 
cs

#결과


■Memcpy_Single



#LDM/STM의 어드레스 저장방식은 4가지가 있다. 

(Increment Before, Increment After, Decrement Before, Decrement After)

프로세스마다 방식이 다르며 참고로 ARM에서는 Stack 동작에서 Full Descending방식을 쓴다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
MEMCPY_MULTIPLE_IA:
    LDMIA    r1!,{r3-r5}
    STMIA    r0!,{r3-r5}        
    subs r2,r2,#3
bne    MEMCPY_MULTIPLE
    mov pc,lr
 
MEMCPY_MULTIPLE_IB:
    SUB        r1,r1,#0x4
    SUB     r0,r0,#0x4
kk:
    LDMIB    r1!,{r3-r5}
    STMIB    r0!,{r3-r5}        
    subs r2,r2,#3
bne    kk
    mov pc,lr
 
MEMCPY_MULTIPLE_DA:
    add        r1,r1,#0x2c
    add         r0,r0,#0x2c
kk:
    LDMDA    r1!,{r3-r5}
    STMDA    r0!,{r3-r5}        
    subs r2,r2,#3
bne    kk
    mov pc,lr
 
MEMCPY_MULTIPLE_DB:
    add        r1,r1,#0x30
    add         r0,r0,#0x30
kk:
    LDMDB    r1!,{r3-r5}
    STMDB    r0!,{r3-r5}        
    subs r2,r2,#3
bne    kk
    mov pc,lr
cs





+ Recent posts