solutions

Embedded Systems Midterm Exam
Spring 2014
Name: ___________
Note: No Explanations, No Credits!
1. ARM CPU. (30 points)
a. There are 2 kinds of interrupts: Software and Hardware interrupts. How are they
different in ARM? (10 points)


Software interrupt is a synchronous event and is triggered by the swi instruction
Hardware interrupt is an asynchronous event and is triggered by peripheral device.
b. What is the difference between the following 2 instructions? When would you use
the instructions? (10 points)
mov
movs
pc, lr;
pc, lr;
Detailed operations
Usage case
pc ← lr
Return from a function
pc ← lr
cpsr ← spsr
Return from exception or
interrupt
c. ARM physically accepts 2 kinds of interrupt inputs. What are those, and What is the
reason of having those? (10 points)


nIRQ: Normal interrupt
nFIQ: Fast interrupt. Context switch is fast since it have dedicated registers.
1
2.
Write the ARM assembly (pseudo) code that prepares for the AT91’s timer interrupt. There are
3 timers in AT91: Timer0, Timer1 and Timer2. The priority of Timers is Timer0 > Timer1 >
Timer2. The Timers’ ISRs are given as shown below (15 points)
the higher number, the higher priority
// Timer 0
ldr r1, =SMR4
str #3, [r1]
ldr r1, =SVR4
ldr r2, =Timer0_ISR
str r1, [r2]
// Timer 1
ldr r1, =SMR5
str #2, [r1]
ldr r1, =SVR5
ldr r2, =Timer1_ISR
str r1, [r2]
// Timer 2
ldr r1, =SMR6
str #1, [r1]
ldr r1, =SVR6
ldr r2, =Timer2_ISR
str r1, [r2]
Timer0_ISR:
stmfa sp, {r0-r14}
…
Timer1_ISR:
stmfa sp, {r0-r14}
…
Timer2_ISR:
stmfa sp, {r0-r14}
…
2
3
3. Fill up the address and data fields in memory after executing each instruction. What does R13
contain after executing each instruction and why? (20 points)
Assume the followiing initial values;
R1 = 0x1
R2 = 0x2
R3 = 0x3
R4 = 0x4
R13 = 0x1000
stmfa
r13!, {r4,r2,r3,r1};
stmea
r13!, {r1-r4};
Memory (address, data)
0x1010
0x4
0x100C
0x3
0x1008
0x2
0x1004
0x1
Memory (address, data)
0x100C
0x4
0x1008
0x3
0x1004
0x2
0x1000
0x1
R13 = 0x1010
R13 = 0x1010
stmfd
r13!, {r4,r2,r3,r1};
stmed
r13!, {r1-r4};
Memory (address, data)
0xFFC
0x4
0xFF8
0x3
0xFF4
0x2
0xFF0
0x1
Memory (address, data)
0x1000
0x4
0xFFC
0x3
0xFF8
0x2
0xFF4
0x1
R13 = 0xFF0
R13 = 0xFF0
4
4. Convert the following C codes to ARM Assembly. Assume that the variables f, g, h, i, j are
assigned to registers R0, R1, R2, R3, and R4, respectively. Refer to the ARM condition table
(10 points)
int
unsigned
f, g, h, i, j;
f, g, h, i, j;
if (i > j) {
f = g + h;
} else {
f = g - h;
}
// R0 = f, R1 = g, R2 = h, R3 = i, R4 = j
if (i > j) {
f = g + h;
} else {
f = g - h;
}
// R0 = f, R1 = g, R2 = h, R3 = i, R4 = j
cmp R3, R4;
addhi R0, R1, R2
subls
R0, R1, R2;
cmp R3, R4;
addgt R0, R1, R2
suble
R0, R1, R2;
5
5. The SWI instruction is typically used to implement system calls in OS. The diverse system calls
in OS are differentiated by 24-bit immediate field in the SWI instruction. Write an ARM
assembly code that extracts the immediate field after jumping to the ISR of SWI. (15 points)
ldr
BIC
r10, [lr, #-4];
r10, r10, #0xff000000
6. What is the role of WDT (Watchdog Timer) in embedded systems? Explain in details with an
example (10 points)
Reset the system when it is not refreshed.
6