Msp430 编写汇编语言,求四个数中的最小值,并用LED显示其位置

2019-03-24 11:54发布

电子系大一新生,刚刚接触到msp430单片机。刚刚得到一个task是用汇编语言在四个数中找出其中的最小值,并用led显示其位置。。。。
这个是task的原文:
Task 2:

Write a program in assembly to find the the location of the smallest value in an array that contains 4 values of type int. e.g. given the array 1024, 520, 56, 670 your code should return location 2. The location should be displayed to the user in binary using the red and green LED on the MSP430 Launchpad.


然后在老师的blog里找到了一个很相似的,是找出一组数中的最大值
BIS.B #0xFF,&P1DIR ; Set port1 as output
BIC.B #0x01,&P1OUT ; clear bit0
; Main loop here
start: MOV.W #0, R7 ; initialise max value register
MOV.W #arr1, R4 ; load the starting address of the array1 into the register R4
loop: MOV.W @R4+,R5 ; load the value stored at the address in register R4 into R5
CMP.W #0000h,R5 ; check for end of array delimiter '0'
JZ done ; if end of array jump to done
CMP.W R7,R5 ; compare current value with max value
JGE update ; if current value is larger than max value jump to update
JMP loop

update: MOV.W R5,R7 ; move current value into max value register
JMP loop ; jump to loop

done: BIS.B #0x01,&P1OUT ; set bit 0 to indicate done
JMP start ; return to start

arr1: .word 1,2,3,4,5,7,6,0 ; array of 16 bit integers (with '0' delimiter)



问题的关键就在于怎样输出最小值得位置啊,快到deadline真的是憋不出来。。。。真的不懂汇编啊,求大神教下要怎样用LED输出位置 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
walkwk
1楼-- · 2019-03-24 17:00
< 国外留学?好吧。。。心情好来回答下问题

没学过msp430,说错请误喷

第一个修改的地方是start: MOV.W #0, R7 改成MOV.W #FFFF, R7
第二个:JGE update 改成JL update
airqj
2楼-- · 2019-03-24 18:45
< :TI_MSP430_内容页_SA7 --> 代码没注意看
告诉你一个快速的办法,其实可以用C写出来之后反汇编,而且430的汇编和C感觉没什么大的区别的

一周热门 更多>

相关问题

    相关文章