新手求教嵌入式汇编实验题
要求:完成10个字节数据的升序排列
有个字节复制的例子可以参考:
#*********************************************************************************************
# NAME: ARMcode.s *
# Author: Embest *
# Desc: ARMcode examples *
# copy words from src to dst *
# History: shw.He 2005.02.22 *
#*********************************************************************************************
/*------------------------------------------------------------------------------------------*/
/* constant define */
/*------------------------------------------------------------------------------------------*/
.global _start
/*------------------------------------------------------------------------------------------*/
/* code */
/*------------------------------------------------------------------------------------------*/
.text
.equ num, 20 /* Set number of words to be copied */
_start:
ldr r0, =src /* r0 = pointer to source block */
ldr r1, =dst /* r1 = pointer to destination block */
mov r2, #num /* r2 = number of words to copy */
mov sp, #0x400 /* set up stack pointer (r13) */
blockcopy:
movs r3,r2, LSR #3 /* number of eight word multiples */
beq copywords /* less than eight words to move ? */
stmfd sp!, {r4-r11} /* save some working registers */
octcopy:
ldmia r0!, {r4-r11} /* load 8 words from the source */
stmia r1!, {r4-r11} /* and put them at the destination */
subs r3, r3, #1 /* decrement the counter */
bne octcopy /* ... copy more */
ldmfd sp!, {r4-r11} /* don't need these now - restore originals */
copywords:
ands r2, r2, #7 /* number of odd words to copy */
beq stop /* No words left to copy ? */
wordcopy:
ldr r3, [r0], #4 /* a word from the source */
str r3, [r1], #4 /* store a word to the destination */
subs r2, r2, #1 /* decrement the counter */
bne wordcopy /* ... copy more */
stop:
b stop
/*------------------------------------------------------------------------------------------*/
/* make a word pool */
/*------------------------------------------------------------------------------------------*/
.ltorg
src:
.long 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4
dst:
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.end
PS:因为是刚学汇编,理论学的倒是挺好,不知道实际怎么开发,看大多数人并不把重点放在写代码上,但是我想先打好基础,c语言我学的不错,但是汇编完全没思路 ,能介绍写嵌入式汇编的书吗,好的文章页行,在网上查的一些觉得不实用,只做实验部给经验的也很感谢,要是给我介绍下经验的就爱死你了