Id really appreciate if somebody could help me.
Why doesn't code branch on the first reading of BEQ, if comparing r2 with r2. Apparently the final value in r0 is 0X0000001B. Thank you so much, im very confused and frustrated running this over and over in Keil.
MOV r0,#1
MOV r1, #0X3
MOV r2,#0X3
MOVS r2,r2
while
BEQ stop
MUL r0,r1,r0
SUBS r2,r2,#1
B while
stop
Your code doesn't branch because BEQ test if Z flag is equal to 1.
If you want to set the Z flag to 1, you can use CMP to check the flags N and Z. Such will do R2-R2 = 0, Z=1
MOV r0,#1
MOV r1, #0X3
MOV r2,#0X3
CMP r2,r2
while
BEQ stop
MUL r0,r1,r0
SUBS r2,r2,#1
B while
stop
Another, less efficient method would be to use another register with SUBS, setting all the flags (NZCV).
MOV r0,#1
MOV r1, #0X3
MOV r2,#0X3
SUBS r3, r2,r2
while
BEQ stop
MUL r0,r1,r0
SUBS r2,r2,#1
B while
stop
Good luck!
User contributions licensed under CC BY-SA 3.0