I'm trying to write code to do two things: return a 1 to register r2 if my value is presentable as a constant in the ARM data processing instruction. This code does that (offer better methods if it's inefficient please). However, I also want to modify it to tell me whether a MOV or MVN needs to be used.
AREA ArmExample18b, CODE
ENTRY
MOV r2, #0 ;register return value. if =1, representable, otherwise, not representable
LDR r1, TABLE1 ;input value we want to use
LDR r3, TABLE1+4 ;upper bound register
LDR r4, TABLE1+8 ;lower bound register
MOV r5, #12
INVCHECK CLZ r6, r1 ;r6 contains number of leading zeros in r1
RBIT r7, r1
CLZ r8, r7 ;r8 contains number of trailing zeros in r1
CMP r6, r8
SUBCS r9, r6, r8
RSBCC r9, r6, r8
CMP r9, #8
MVNHI r1, r1
BHI INVCHECK
BLS LOOP
LOOP
CMP r3, r1 ;compare input value with upper bound
BLO STOP ;if bigger than u.b, stop, r2 = 0
CMP r4, r1 ;compare input value with lower bound
MOVLS r2, #1 ;if larger than lower bound, it falls within range, set r2 = 1
BLS STOP ;then stop
CMP r4, #0 ;if r4 has reached 0, then we are at the end of comparisons and can stop
BEQ STOP
LDR r3, TABLE1 + r5 ;change upper bound
ADD r5, r5, #4
LDR r4, TABLE1 + r5 ;change lower bound
ADD r5, r5, #4
B LOOP
STOP B STOP
TABLE1 DCD 0x500, 0x3fc0, 0x1000, 0xff0, 0x400, 0x3fc, 0x100, 0xff, 0
END
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…