2 つのことを行うコードを作成しようとしています。値が ARM データ処理命令で定数として提示できる場合、レジスタ r2 に 1 を返します。このコードはそれを行います (効率が悪い場合は、より良い方法を提供してください)。ただし、MOV または MVN を使用する必要があるかどうかを教えてくれるように変更することも必要です。
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