ARM汇编停止更新很久了!现在也不看那个了,我把大部分课本例题的源码发上来,不写那么详细的例题分析了,如果有指点以前代码的请看我以前的帖子吧! ;已知循环次数的 单循环程序设计 循环实现s=1+2*3+3*4+...+N(N+1)当N=10截止 AREA EX4_45,CODE,READONLY ENTRY CODE32 START MOV R0,#1 ;R0:S 循环置初始值 MOV R1,#2 ;R1:N REPEAT ADD R2,R1,#1 ;R2:N+1 程序循环体 MUL R3,R1,R2 ;R3:N(N+1) ADD R0,R0,R3 ADD R1,R1,#1 ;循环修改 CMP R1,#10 ;循环修改 BLE REPEAT B START END ;先进行判断后执行、修改 AREA EX4_4500,CODE,READONLY ENTRY CODE32 START MOV R0,#1 MOV R1,#2 CTR CMP R1,#10 BLE DOIT B START DOIT ADD R2,R1,#1 MUL R3,R1,R2 ADD R0,R0,R3 ADD R1,R1,#1 B CTR END ;未知次数的循环程序设计 实现DATA1和DATA2对应数据之和 并保存到SUM中 ;直到两数组和为零终止 AREA EX4_46,CODE,READONLY ENTRY CODE32 START LDR R1,=DATA1 LDR R2,=DATA2 LDR R3,=SUM MOV R0,#0 LOOP LDR R4,[R1],#04 LDR R5,[R2],#4 ADDS R4,R4,R5 STR R4,[R3],#4 ADD R0,R0,#1 BNE LOOP B START AREA BlockData,DATA,READWRITE DATA1 DCD 2,3,4,5,6,7,2,3,9,0 DATA2 DCD 3,4,2,3,5,6,7,7,-9,0 SUM DCD 0,0,0,0,0,0,0,0,0,0 END ;冒泡排序法实现 N EQU 10 AREA EX4_47,CODE,READONLY ENTRY CODE32 START LDR R0,=BUF ;DATAAREA START ADDR MOV R1,#0 ;OUTLOOP CON MOV R2,#0 ;INNERLOOP CON LOOPO ADD R3,R0,R1,LSL #2 ;OUTLOOP START ADDR MOV R4,R3 ;INNERLOOP FIRST ADDR ADD R2,R1,#1 ;INNERLOOP CON RW MOV R5,R4 ;INIT INNERLOOP FIRST ADDR LDR R6,[R4] ;GET FIRST NUM LOOPI ADD R5,R5,#4 ;INNERLOOP NEXT ADDR LDR R7,[R5] ;GET NEXT NUM CMP R6,R7 BLT NEXT ;< NEXT INNERLOOP SWP R7,R6,[R5] ; >= SWITCH MOV R6,R7 NEXT ADD R2,R2,#1 ;RW INNERLOOP CON CMP R2,#N ;INNERLOOP CTR BLT LOOPI SWP R7,R6,[R3] ADD R1,R1,#1 CMP R1,#N-1 BLT LOOPO B START AREA BlockData,DATA,READWRITE,ALIGN=4 BUF DCD 0XFF,0X00,0X40,0X10,0X90,0X20,0X80,0X30,0X50,0X70 END ;块复制实现 从数据源SRC复制到DST 以8字为单位复制 不足的以字复制 AREA EX4_5100,CODE,READONLY NUM EQU 20 ENTRY START LDR R0,=SRC LDR R1,=DST MOV R2,#NUM MOV SP,#0X400 blockcopy MOVS R3,R2,LSR #3 BEQ copywords STMFD SP!,{R4-R11} octcopy LDMIA R0!,{R4-R11} STMIA R1!,{R4-R11} SUBS R3,R3,#1 BNE octcopy LDMFD SP!,{R4-R11} copywords ANDS R2,R2,#7 BEQ stop wordcopy LDR R3,[R0],#4 STR R3,[R1],#4 SUBS R2,R2,#1 BNE wordcopy stop B START AREA BlockData,DATA,READWRITE SRC DCD 1,2,3,4,5,6,7,8,9,0,0,9,8,7,6,5,4,3,2,1 DST DCD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 END //汇编调用C中声明的变量 #include <stdio.h> int globvar=3; int main() { return(0); } AREA EX4_5700,CODE,READONLY EXPORT ARMCODE IMPORT globvar ENTRY ARMCODE LDR R1,=globvar LDR R0,[R1] ADD R0,R0,#2 STR R0,[R1] MOV PC,LR END AREA EX4_5800,CODE,READONLY EXPORT ARM_add IMPORT g ENTRY MOV SP,#0X400 ;设置SP栈首地址 ARM_add ADD LR,PC,#-8 ;保存此行命令PC STR LR,[SP,#-4]! ;保存LR到栈 MOV R0,#1 MOV R1,#2 MOV R2,#3 MOV R3,#4 MOV R4,#5 ;第五参数通过栈传递 STR R4,[SP,#-4]! ;保存第五参数到栈 BL g ;分支时会在LR中保存PC 此时PC指向下一行 ADD SP,SP,#4 ;调整SP指向先前存储的LR准备返回 LDR PC,[SP],#4 ;恢复栈中的PC 返回 END //C语言调用汇编实现5参数相加 #include<stdio.h> int g(int a,int b,int c,int d,int e) { return a+b+c+d+e; } //内嵌汇编实现字符串复制 #include <stdio.h> void my_strcopy(char *src,const char *dst) { int ch; __asm { loop: LDRB ch,[src],#1 STRB ch,[dst],#1 CMP ch,#0 BNE loop } } int main(void) { const char *a="hello word!"; char b[20]; __asm { MOV R0,a MOV R1,b BL my_strcopy,{R0,R1} } printf("original string:%s/n",a); printf("copied string:%s/n",b); return 0; } //内嵌汇编实现 中断的使能和禁止 __inline void enable_IRQ(void) { int tmp; __asm { MRS tmp,CPSR BIC tmp,tmp,#0x80 MSR CPSR_c,tmp } } __inline void disable_IRQ(void) { int tmp; __asm { MRS tmp,CPSR ORR tmp,tmp,0x80 MSR CPSR_c,tmp } } int main(void) { disable_IRQ(); enable_IRQ(); } AREA STRCPY,CODE,READONLY EXPORT strcopy strcopy ;参数通过寄存器传送 R0指向SRC ;R1指向dst LDRB R2,[R0],#1 STRB R2,[R1],#1 CMP R2,#0 BNE strcopy MOV PC,LR END //C语言调用汇编语句 实现字符串复制 #include<stdio.h> extern void strcopy(const char *src,char *dst); int main() { const char *src="First string-source"; char *dst="Second string-destination"; printf("Before copying:/n"); printf("%s/n%s/n",src,dst); strcopy(src,dst); printf("After copying:/n"); printf("%s/n%s/n",src,dst); return 0; } 没有时间整理了!见谅!