■ARM 예제

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
int main(void)
{
int a;
int b;
int c;
int i;
int result;
int start,end,sum,max;
 
    HOW_TO_RETURN(); 
 
 
 
#if 0    
    a=9;b=11/* a < b condition */
    result = CONDITIONAL_EXECUTE(a,b);
 
    a=11;b=10/* a < b condition */
    result = CONDITIONAL_EXECUTE(a,b);
 
    a=10;b=10/* a < b condition */
    result = CONDITIONAL_EXECUTE(a,b);
#endif
 
 
#if 0
    a=11;b=22;c=30;
    result = DATA_PROCESS1(a,b,c);
#endif
 
#if 0
    a=0x10; b=0x33;
    result = DATA_PROCESS2(a,b);
#endif
 
#if 0
    start =1;end =5;
    sum = SUM_OF_DEC(start,end);
#endif
 
 
#if 1
    start =0;end =1;
    sum = Fibonacci(start,end);
#endif
 
 
return i;
}
 
cs

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
 
                        /* 프로그램 시작 */
    .text              /* 프로그램 정의 */
    .arm               /* ARM 프로세서 */
    .global HOW_TO_RETURN
    .global CONDITIONAL_EXECUTE
    .global DATA_PROCESS1
    .global DATA_PROCESS2
    .global SUM_OF_DEC
    .global Fibonacci
 
 
RESET:  B      MAIN        /* MAIN으로 점프 */
        /* 메인 프로그램 */
        .org    0x100
MAIN:   MOV     R0,#2          /* R0 <- 2 */
        MOV     R1,R0          /* R1 <- R0 */
    b main
 
 
HOW_TO_RETURN:
   mov r0,#0x00000010
   mov pc,lr
 
CONDITIONAL_EXECUTE:
    cmp r0,r1
    movgt r0,#1    
    movlt r0,#2
    moveq r0,#3    
    mov pc,lr
DATA_PROCESS1:
    add r0,r0,r1
    sub r0,r0,r2
    mov pc,lr 
DATA_PROCESS2:
    and r3,r1,#15
    orr r3,r3,r0,LSL#2
    mov r3,r0
    mov pc,lr 
 
SUM_OF_DEC:
    mov r3,#0
FOR:
    add r3,r3,r0
    add r0,r0,#1
    cmp r0,r1
    ble FOR
    mov r0,r3
    mov pc,lr
 
Fibonacci:
 
Fibonacci1:
    add r2,r0,r1
    mov r0,r1
    mov r1,r2
b Fibonacci1
    
    mov pc,lr
 
.end
cs




#피보나치 결과




+ Recent posts