Consider the following cortex-m3 assembly code loop PROC MOV r2,#0xffffffff MOV
ID: 3582843 • Letter: C
Question
Consider the following cortex-m3 assembly code
loop PROC
MOV r2,#0xffffffff
MOV r3,#1
label
AND r4,r3,r0
EOR r2,r2,r4
LSLS r2,r2,r1
BNE label
MOV r0,r2
BX lr
ENDP
The above code was generated by compiling C code that had the following overall form:
int loop(int x, int n) {
int result = ______________;
for (int mask = ________; mask ________; mask = _________) {
result ^= _______________;
}
}
Your task is to fill in the missing parts of the C code, and to answer several questions. Recall that the result of the function is returned in r0. You will find it helpful to examine the assembly code before, during, and after the loop to form a consistent mapping between the registers and the program variables.
(a) Which registers hold the values x, n, result, and mask?
(b) What are the initial values of result and mask?
(c) What is the test condition for mask?
(d) What is the C expression that updates mask? Name:
(e) What is the C expression that updates result?
(f) Fill in all the missing parts of the C code.
Explanation / Answer
(b) What are the initial values of result and mask?
Ans:Initially mask=1,result=-1
(c) What is the test condition for mask?
Ans:mask!=0
(d) What is the C expression that updates mask?
Ans:
(e) What is the C expression that updates result?
Ans:result ^= (mask & x);
(f)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.