Write ARM code to implement the following C operation.
int s = 0;
for ( i = 0; i < 10; i++) {
s = s + i*i;)
AREA SumSquares, code, readwrite
ENTRY
MOV r0,#0 ;loop counter i preset to 0
MOV r1,#0 ;s = 0
Loop MUL r2,r0,r0 ;calc i*i
ADD r1,r1,r2 ;s = s + i*i
ADDS r0,r0,#1 ;i = i + i
CMP r0,#10 ;test for end
BNE Loop ;continue until all added
END
We can improve this code by counting down rather than up to remove the comparison. We can also use the
multiply and accumulate operation to perform the i2 and addition.
AREA SumSquares2, code, readwrite
ENTRY
MOV r0,#9 ;loop counter i preset to 9
MOV r1,#0 ;s = 0
Loop MLA r1,r0,r0,r1 ;calc i*i
SUBS r0,r0,#1 ;i = i - i
BNE Loop ;continue until all added
END
Computer Science & Information Technology
You might also like to view...
How many Book objects are created by the following statement? Book[] books = new Book[10];
a. 10 b. 0 c. 5 d. None of the above.
Computer Science & Information Technology
One of the unique features of the Mac desktop is the _____.
A. Dock B. window C. Start key D. Home key
Computer Science & Information Technology
Windows offers two types of user accounts.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology
Oracle offers a free download of all editions of the Oracle Database for purposes of education, testing, or development.
Answer the following statement true (T) or false (F)
Computer Science & Information Technology