- 论坛徽章:
- 0
|
我把源码粘上来,请大家给个答案.
;******************
; init.s
;******************
service equ 0x0c009000 ;存放C语言服务程序的内存
controlunit equ 0x0c008000 ;根据哪一个位上置1,来决定调用哪个函数,1-4位
area init,code,readonly
import Main
export ServiceFunction
entry
zero
b InitService
b .
ltorg
InitService
ldr r8,=controlunit
ldr r9,=0x0
str r9,[r8]
;初始化堆栈
ldr sp,=stack_base
b Main
b .
ltorg
ServiceFunction rout
ldr r8,=controlunit
ldr r9, [r8]
mov r7,#0x0
0 movs r9,r9,lsr #1
bcs %f1
add r7,r7,#4
b %b0
1 ldr r6,=service1
add r6,r6,r7
ldr pc,[r6]
align
area mydata,data,readwrite
^ service-0x100
stack_base # 256
^ service
service1 # 4
service2 # 4
service3 # 4
service4 # 4
end
/* service.c */
#include <stdio.h>
#define mCONTROLUNIT (*(volatile unsigned *)0x0c008000)
#define mService1 (*(volatile unsigned *)0x0c009000)
#define mService2 (*(volatile unsigned *)0x0c009004)
#define mService3 (*(volatile unsigned *)0x0c009008 )
#define mService4 (*(volatile unsigned *)0x0c00900c)
char * s1="this is No.1 string.";
char * s2="this is No.2 string.";
char * s3="this is No.3 string.";
char * s4="this is No.4 string.";
void print_msg1(void);
void print_msg2(void);
void print_msg3(void);
void print_msg4(void);
extern ServiceFunction(void);
int Main(){
int i=1;
printf("this message if from C.\n"); //这句也不好用
//设置服务函数地址
mService1=(unsigned)print_msg1;
mService2=(unsigned)print_msg2;
mService3=(unsigned)print_msg3;
mService4=(unsigned)print_msg4;
while(1){
if(i>8 ) i=1;
mCONTROLUNIT=i;
ServiceFunction();
i *= 2;
}
return 0;
}
void print_msg1(){
printf("%s\n",s1);
}
void print_msg2(){
printf("%s\n",s2);
}
void print_msg3(){
printf("%s\n",s3);
}
void print_msg4(){
printf("%s\n",s4);
}
[ 本帖最后由 2195113 于 2008-6-4 20:13 编辑 ] |
|