The following is a loop expressed in ARM code. The code is wrong. Why?


MOV r0,#10 ;Loop counter – ten times round the loop
Next ADD r1,r1,r0 ;add loop counter to total
SUB r0,r0,#1 ;decrement loop counter
BEQ Next ;continue until all done


This fragment of code has several errors. The total is not initialized to zero. This may not be an error if r1 has been
previously cleared. The subtraction does not set the CCR. You must use SUBS.

The final branch tests the wrong condition. It should be branch back on not zero. The code should be:


MOV r0,#10 ;Loop counter – ten times round the loop
MOV r1,#0 ;Clear sum in r1
Next ADD r1,r1,r0 ;add loop counter to total
SUBS r0,r0,#1 ;decrement loop counter
BNE Next ;continue until all done

Computer Science & Information Technology

You might also like to view...

What is the data type of the following function prototype's parameter variable?

int myFunction(double); a. int b. double c. void d. cannot tell from the prototype

Computer Science & Information Technology

The Do…Loop While repetition statement tests the condition the body of the loop executes.

a) before b) while c) after d) None of the above.

Computer Science & Information Technology

A(n) ____ statement stores the value of the right-hand side of the expression in the memory location of the left-hand side.

A. construct B. arithmetic C. equals D. assignment

Computer Science & Information Technology

The Merge & Center button is in the ________ group on the Home tab

A) Font B) Alignment C) Number D) Cells

Computer Science & Information Technology