ARM程序集,用于更正值的分支

时间:2017-11-17 00:20:34

标签: assembly arm branch

我正在编写此代码以获取16个输入的温度值,相应地进行校正,求和然后取平均值。 例如,如果值介于(0-20)之间,则添加+0。如果值介于(21-39)之间,则加上+1 ..等。在第16个值之后,它退出循环并平均值。 这是我到目前为止所得到的,但显然它不起作用。

.text
.global _start
_start:

.equ NUM, 16

LDR R1, =Fahrenheit_Rough               @Load pointer to the Loaded values (Manually entered)
LDR R2, =Fahrenheit_True                @Load pointer to the corrected Values
LDR R3, =Round_Average                  @Load pointer to the Round_Average
MOV R4, #NUM                            @counter for going over 16 values
MOV R5, #0                              @Summing the corrected values, and then getting average

READING:
LDRB R6, [R1], #1                       @Load Temperaure value to R6, increment position by 1
CMP R6, #21                             @Compare first value to 21
ADDMI R6, R6, #0                        @IF less than 21, add +0
BMI COMPUTING                           @jump to Compuing to add the corrected value to the True array and sum avarage

CMP R6, #40                             @Compare second value to 40
ADDMI R6, R6, #1                        @if less than 40 add +1
BMI COMPUTING                           @Jump to computing to add to the corrected value to True array and update average

CMP R6, #60
ADDMI R6, R6, #3
BMI COMPUTING

CMP R6, #80
ADDMI R6, R6, #7
BMI COMPUTING

CMP R6, #100
ADDMI R6, R6, #12
BMI COMPUTING

CMP R6, #121
ADDMI R6, R6, #20
BMI COMPUTING

COMPUTING:
STRB R6, [R2], #1                       @Store the corrected value to the True array. increment by 1
ADD R5,R5,R6                            @Add the corrected value to average
SUBS R4, #1                             @Substract 1 from the ounter
BNE READING                             @If counter not zero, go back to READING
NOP

MOVS R5,R5,LSR #4                       @Shift 4 bit to the right to divide by 16
ADC R5,R5, #1                           @add one if there's a carry


.data
Fahrenheit_Rough:   .byte 0,15,20,25,40,55,65,79,80,85,95,99,102,110,120,121
Fahrenheit_True:    .byte 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
Round_Average:      .byte 0x0
.END

0 个答案:

没有答案