Created
October 22, 2013 04:13
-
-
Save kyl191/7095122 to your computer and use it in GitHub Desktop.
ECE222 Midterm Practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MOV r0, #0 | |
LDR r1, =N; N is label in memory, assuming it's +/- 4096 | |
MOV r2, #0; r2 is the counter | |
LOOP; just a label | |
MUL r3, r2, r2; i * i | |
ADD r0, r0, r3; total += i*i | |
ADD r2, r2, #1; i++ | |
CMP r2, r1; break out of loop when i = N | |
BNE LOOP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MOV r0, #0 | |
MOV r1, =X; Array address that we're looking at | |
MOV r2, #0; counter | |
MOV r3; =N; max value | |
LOOP | |
CMP [r1], #-1 | |
BEQ endLOOP; Break on X[i] == -1, need this here because X[0] case | |
LDR r4, [r1]; load X[i] into r4 | |
LDR r5, [r1, #4]; load X[i+1] into r5 | |
ADD r4, r4, r5; X[i]+X[i+1] | |
STR r1, [r4]; X[i] = X[i]+X[i+1] | |
ADD r1, r1, #4; Move to next array element | |
ADD r2, r2, #1; i++ | |
CMP r2, r3 | |
BNE LOOP; Break on i == N | |
endLOOP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment