2020-04-28-----ARM指令实现

ARM指令实现

一、实验目的

1.将20个字(字长32位,每字位4个字节)的数据从内存的一个区间(src指向的)复制到另一个区间(dst指向的)。
2.熟悉嵌入式开发的软件环境,掌握汇编语言指令,学习代码的含义。

二、实验设备

Keil uVision4 MDK 集成开发环境

三、实验内容

程序实现20个字的内存之间的数据复制,使用ldr指令与stm指令实现多个字的数据加载与存储,一次处理8个字,2次循环实现16个字的数据复制。不足8个字的数据用ldr指令与stm指令实现单字的数据加载与存储,4次循环实现4个字的数据复制。

四、实验步骤

1.下载好Keil uVision4 MDK并用注册机破解,配置到集成开发环境。
2.在D:\lxq qianrushi\Mini2410-IV\4.2_asm2\Asm2_1文件夹中找见源程序,用keil uVision4 打开。
3.单击project -> options for … -> output,勾选产生16进制代码。
4.单击project -> rebuild all … ,控制窗口显示0个错误,0个警告。
5.单击debug -> start/stop … ,开始调试,观察地址内容。
6.单击view -> memory window ->memory 1,显示memory1窗口。
7.单击debug -> run ,开始运行程序,memory1 窗口地址内容改变,显示运行结果。

五、实验代码
;#*********************************************************************************************
;# NAME:	ARMcode.s																		 *
;# Author: 	EWUHAN  R & D Center, st																			 *
;# Desc:	ARMcode examples																 *
;#          copy words from src to dst														 *
;# History:	shw.He 2005.02.22																 *
;#*********************************************************************************************

;/*------------------------------------------------------------------------------------------*/
;/*	 								code								 				    */
;/*------------------------------------------------------------------------------------------*/
		
		GLOBAL	Reset_Handler
		area start,code,readwrite
		entry
		code32
num		EQU		20				 ;/*  Set number of words to be copied */
								 /*设置要复制字的个数*/
Reset_Handler
		ldr		r0, =src		;/*  r0 = pointer to source block */
                                 /*伪指令,src复制给r0*/
		ldr		r1, =dst		;/*  r1 = pointer to destination block */
                                /*伪指令,dst复制给r1*/
		mov		r2, #num		;/*  r2 = number of words to copy */
                                /*将立即数num放入寄存器r2*/
		ldr		sp, =0x30200000	;/*  set up stack pointer (r13) */
                                /*设置堆栈指针*/

blockcopy       
		movs	r3,r2, LSR #3		;/*  number of eight word multiples */
                                    /*将r2右移八个字的值放入r3*/
		beq		copywords			;/*  less than eight words to move ? */
                                    /*上步的结果为零则跳转到copywords*/
		stmfd	sp!, {r4-r11}		;/*  save some working registers */
                                    /*将r4-r11内容入栈*/

octcopy
		ldmia	r0!, {r4-r11}		;/*  load 8 words from the source */
                                    /*从r0内地址开始的存储器复制八个字到r4-r11*/
		stmia	r1!, {r4-r11}		;/*  and put them at the destination */
                                    /*r4-r11中内容放到r1内地址开始的存储器中*/
		subs	r3, r3, #1			;/*  decrement the counter */
                                     /*r3减一*/
		bne		octcopy		     	;/*  ... copy more */
                                    /*r3不等于零跳转,完成更多复制*/
		ldmfd	sp!, {r4-r11}	;
                                    /*  don't need these now - restore originals */
                                   /*将r4-r11出栈,还原现场*/

copywords
		ands	r2, r2, #7			;/*  number of odd words to copy */
/*r2=r2&7(0111),r2=4(0100)*/
		beq		stop				;/*  No words left to copy ? */
                                    /*r2=0跳转到stop,否则顺序执行*/

wordcopy
		ldr		r3, [r0], #4		;/*  a word from the source */
                                    /*传送当前一个值后,r0内容加4*/
		str		r3, [r1], #4		;/*  store a word to the destination */
                                    /*传送当前一个值后,r1内容加4*/
		subs	r2, r2, #1			;/*  decrement the counter */
                                    /*r2减1*/
		bne		wordcopy			;/*  ... copy more */
                                   /*如果r2不为零,跳转到wordcopy继续复制,直到r2=0*/

stop
		b		stop
;/*------------------------------------------------------------------------------------------*/
;/*	 								make a word pool		*/			 	
                                   /*产生一个文字池*/	 
   ;/*------------------------------------------------------------------------------------------*/
		ltorg
src
		dcd		1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4
dst
		dcd		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		end
五、实验结果

1.Run之前
在这里插入图片描述

2.Run之后在这里插入图片描述

六、实验总结

运行过程中报错:failed to execute ‘bin40\armasm’ ,原因是找不到armasm.exe 这个程序,在安装文件中找见该程序,在project -> mange ->components, … ->folders ->realview,中添加进该程序。最终成功运行。
具体解决请查看链接: https://blog.csdn.net/qq_45021462/article/details/105826485

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值