内存分配 ( DCD
) 在与代码声明相同的区域中完成。这意味着它可能会像AREA PROGRAM, CODE, READONLY
设置一样被使用,因此 keil 不会组装它。这也意味着如果它被组装,数据位置将是READONLY
. 变量的正确声明将在前面AREA <a section name>, DATA, READWRITE
Main
LDR R1, =Value1 -- load Value1 inside R1
LDR R2, =Value2 -- load Value2 inside R2
LDR R1,[R1] -- load indirect the address pointed to by the value of R1 to R1 -- (I have reservations about the functionality of this code)
LDR R2,[R2] -- load indirect the address pointed to by the value of R2 to R2 -- (I have reservations about the functionality of this code)
Return
ANDS R3, R1,R2 -- R3 = R1 AND R2
BNE SEND -- branch if not equal to SEND label
BEQ NEXT -- branch to NEXT if equal
END
SEND
LDR R4, =Result -- load Result to R4
LDR R4,[R4] -- load indirect the address pointed to by the value of R4 to R4 -- (I have reservations about the functionality of this code)
STR R3, [R4] -- store indirect to address pointed to by the value of R4 with the value of R3
END
NEXT
MOV R1, R2 -- copy R2 to R1
LDR R2, =Value3 -- load Value3 to R2
LDR R2, [R2] -- load indirect the address pointed to by the value of R2 to R2 -- (I have reservations about the functionality of this code)
B Return -- unconditional branch to Return label
END
Value1 DCD &0202 -- word allocation with hex value of
Value2 DCD &0101 -- word allocation with hex value of
Value3 DCD &0001 -- word allocation with hex value of
Result DCD &FFFFFFF0 -- word allocation with hex value of
此代码试图保存r2
和r1
相等的事实,否则由于保存在其中的值的静态性质,将发生无限循环Value<1-3>