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)