您的位置 首页 国产IC

ARM 汇编与 C 言语彼此调用试验

4.7汇编与C语言相互调用实验4.7.1实验目的阅读S3C2410启动代码,观察处理器启动过程;学会使用MDK集成开发环境辅…

4. 7 汇编C 言语彼此调用试验

4. 7. 1 试验意图

阅览S3C2410 发动代码,调查处理器发动进程;

学会运用 MDK 集成开发环境辅佐窗口来分析判断调试进程和成果;

学会在 MDK 集成开发环境中编写、编译与调试汇编和C 言语彼此调用的程序。

4. 7. 6 试验参阅程序

1.randtest.c 参阅源代码:

/*********************************************************************************************
* File: randtest.c

* Author: Wuhan R&D Center, embest
* Desc: Random number generator demo program

* Calls assembler function randomnumber defined in random.s

* History:

*********************************************************************************************/

/*——————————————————————————————*/

/* extern function */

/*——————————————————————————————*/

extern unsigned int randomnumber( void );

unsigned int unRandom[10];

/*********************************************************************************************

* name: main

* func: c code entry

* para: none

* ret: none

* modify:

* comment:

*********************************************************************************************/

int __main()

{

unsigned int i,nTemp;

for( i = 0; i < 10; i++ )

{

nTemp = randomnumber();

unRandom[i] = nTemp;

}

while(1);

}

2.random.s 参阅源代码:

;#************************************************************************************************************
;# File: random.s *

;# Author: Wuhan R&D Center, embest *
;# Desc: Random number generator *

;# This uses a 33-bit feedback shift register to generate a pseudo-randomly *

;# ordered sequence of numbers which repeats in a cycle of length 2^33 – 1 *

;# NOTE: randomseed should not be set to 0, otherwise a zero will be generated *

;# continuously (not particularly random!). *

;# This is a good application of direct ARM assembler, because the 33-bit *

;# shift register can be implemented using RRX (which uses reg + carry). *

;# An ANSI C version would be less efficient as the compiler would not use RRX. *

;# AREA |Random$$code|, CODE, READONLY *

;# History: *

;#*************************************************************************************************************

;/*——————————————————————————————*/

;/* global symbol define */

;/*——————————————————————————————*/

global randomnumber

global seed

;/*——————————————————————————————*/

;/* code */

;/*——————————————————————————————*/

AREA BLOCK, code , readonly

EXPORT randomnumber

randomnumber

;# on exit:

;# a1 = low 32-bits of pseudo-random number

;# a2 = high bit (if you want to know it)

ldr ip, seedpointer

根据S3C2410 嵌入式 MDK 开发试验与实践――EduKit 系列丛书
Email:support@edukit.com.cn Tel:0755-25631365

ldmia ip, {a1, a2}

tst a2, a2, lsr #1 ;/* to bit into carry */

movs a3, a1, rrx ;/* 33-bit rotate right */

adc a2, a2, a2 ;/* carry into LSB of a2 */

eor a3, a3, a1, lsl #12 ;/* (involved!) */

eor a1, a3, a3, lsr #20 ;/* (similarly involved!) */

stmia ip, {a1, a2}

BX lr

seedpointer

DCD seed

seed

DCD 0x55555555

DCD 0x55555555

END

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/ic/274804.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部