Bird
Raised Fist0
ARM Architectureknowledge~10 mins

Sleep mode (WFI instruction) in ARM Architecture - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Sleep mode (WFI instruction)
CPU executes WFI
↓
CPU checks for interrupts
↓
Enter sleep
↓
Wait for interrupt
↓
Interrupt occurs
↓
CPU wakes up and resumes execution
The CPU executes the WFI instruction, checks for interrupts, and if none are pending, it enters sleep mode until an interrupt wakes it up.
Execution Sample
ARM Architecture
WFI  ; Wait For Interrupt
// CPU sleeps until an interrupt occurs
// Then resumes execution after waking up
This code puts the CPU into sleep mode until an interrupt wakes it up.
Analysis Table
StepActionInterrupt Pending?CPU StateResult
1Execute WFI instructionNoCheck interruptsCPU checks if any interrupt is pending
2Interrupt checkNoEnter sleep modeCPU goes to sleep waiting for interrupt
3WaitNoSleepingCPU remains in low power state
4Interrupt occursYesWake upCPU wakes up from sleep
5Resume executionYesRunningCPU continues normal operation after interrupt
6Execute next instructionDependsRunningCPU processes interrupt or next code
7EndN/ARunningWFI cycle complete
💡 CPU wakes up when an interrupt occurs, ending sleep mode and resuming execution
State Tracker
VariableStartAfter Step 2After Step 4Final
CPU StateRunningSleepingWaking upRunning
Interrupt PendingNoNoYesDepends
Key Insights - 3 Insights
Why does the CPU not sleep if an interrupt is already pending when WFI is executed?
Because at Step 2 in the execution_table, the CPU checks for pending interrupts before sleeping. If an interrupt is pending, it skips sleep and immediately wakes up to handle it.
What happens if no interrupt occurs after WFI is executed?
As shown in Step 3, the CPU stays in sleep mode indefinitely, waiting for an interrupt to wake it up.
Does WFI clear the interrupt or just wait for it?
WFI only waits for an interrupt; it does not clear it. The interrupt is handled after the CPU wakes up, as seen in Step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the CPU state immediately after executing the WFI instruction if no interrupt is pending?
ASleeping
BRunning
CWaking up
DHalted
💡 Hint
Refer to Step 2 and Step 3 in the execution_table where CPU enters sleep mode when no interrupt is pending.
At which step does the CPU wake up from sleep mode?
AStep 2
BStep 4
CStep 3
DStep 1
💡 Hint
Check the 'CPU State' and 'Result' columns in the execution_table for when the CPU changes from sleeping to running.
If an interrupt is pending before WFI executes, what will the CPU do?
AEnter sleep mode anyway
BIgnore the interrupt and continue running
CWake up immediately without sleeping
DReset the interrupt
💡 Hint
Look at Step 2 in the execution_table where the CPU checks for interrupts before sleeping.
Concept Snapshot
WFI (Wait For Interrupt) puts the CPU into low power sleep mode.
CPU checks for pending interrupts before sleeping.
If interrupt pending, CPU wakes immediately.
CPU stays asleep until an interrupt occurs.
After waking, CPU resumes normal execution.
Full Transcript
The WFI instruction causes the CPU to enter sleep mode to save power. When the CPU executes WFI, it first checks if any interrupt is pending. If yes, it wakes immediately without sleeping. If no interrupt is pending, the CPU enters sleep mode and waits. The CPU stays asleep until an interrupt occurs. When an interrupt happens, the CPU wakes up and resumes normal execution. This process helps reduce power consumption during idle times.

Practice

(1/5)
1. What is the primary purpose of the WFI instruction in ARM processors?
easy
A. To execute a debugging routine
B. To reset the processor immediately
C. To increase the processor clock speed temporarily
D. To put the processor into a low-power sleep mode until an interrupt occurs

Solution

  1. Step 1: Understand the function of WFI

    The WFI instruction stands for "Wait For Interrupt" and is designed to reduce power consumption by putting the processor to sleep.
  2. Step 2: Identify when the processor wakes up

    The processor wakes up only when an interrupt signal is received, allowing it to save energy during idle periods.
  3. Final Answer:

    To put the processor into a low-power sleep mode until an interrupt occurs -> Option D
  4. Quick Check:

    WFI = low-power sleep until interrupt [OK]
Hint: WFI means wait until an interrupt wakes the CPU [OK]
Common Mistakes:
  • Confusing WFI with reset or clock speed instructions
  • Thinking WFI wakes up on any signal, not just interrupts
  • Assuming WFI increases performance instead of saving power
2. Which of the following is the correct syntax to execute the WFI instruction in ARM assembly?
easy
A. WFI()
B. WFI
C. wfi
D. wait_for_interrupt

Solution

  1. Step 1: Recall ARM assembly instruction format

    ARM assembly instructions are usually uppercase and written without parentheses.
  2. Step 2: Identify the correct WFI syntax

    The correct instruction is simply WFI in uppercase letters without parentheses or underscores.
  3. Final Answer:

    WFI -> Option B
  4. Quick Check:

    ARM instructions are uppercase and simple: WFI [OK]
Hint: ARM instructions are uppercase without parentheses [OK]
Common Mistakes:
  • Adding parentheses like a function call
  • Using lowercase which is not standard assembly syntax
  • Using descriptive names instead of official instruction
3. Consider this ARM assembly snippet:
    MOV R0, #0
    WFI
    MOV R1, #1
What happens to the execution flow when the WFI instruction is reached?
medium
A. The processor enters sleep mode and resumes at the next instruction after an interrupt
B. The processor halts and never executes the next instruction
C. The processor immediately executes the next instruction without delay
D. The processor resets and starts from the beginning

Solution

  1. Step 1: Understand WFI behavior in code flow

    When the processor executes WFI, it enters a low-power sleep state and pauses execution.
  2. Step 2: Identify when execution resumes

    The processor wakes up only when an interrupt occurs, then continues with the next instruction MOV R1, #1.
  3. Final Answer:

    The processor enters sleep mode and resumes at the next instruction after an interrupt -> Option A
  4. Quick Check:

    WFI pauses until interrupt, then continues [OK]
Hint: WFI pauses execution until interrupt, then continues [OK]
Common Mistakes:
  • Assuming WFI skips next instructions
  • Thinking WFI causes a reset
  • Believing WFI does nothing and continues immediately
4. You wrote this ARM assembly code:
    WFI()
    MOV R0, #5
But the assembler gives an error. What is the problem?
medium
A. WFI must be lowercase
B. MOV instruction cannot follow WFI
C. Parentheses are not allowed in the WFI instruction
D. R0 register cannot be used after WFI

Solution

  1. Step 1: Check WFI syntax rules

    The WFI instruction is a standalone ARM assembly command and does not use parentheses.
  2. Step 2: Identify syntax error cause

    Using WFI() causes a syntax error because parentheses are invalid in ARM assembly instructions.
  3. Final Answer:

    Parentheses are not allowed in the WFI instruction -> Option C
  4. Quick Check:

    WFI must be written without parentheses [OK]
Hint: No parentheses in ARM instructions like WFI [OK]
Common Mistakes:
  • Adding parentheses like a function call
  • Changing case incorrectly
  • Assuming register usage causes error here
5. In an embedded system, you want to save power during idle times but still respond quickly to external events. How does using the WFI instruction help achieve this?
hard
A. It puts the processor to sleep until an interrupt wakes it, reducing power use without missing events
B. It speeds up the processor clock to handle events faster
C. It disables all interrupts to save power
D. It resets the processor to clear idle state

Solution

  1. Step 1: Understand power saving with WFI

    The WFI instruction puts the processor into a low-power sleep mode during idle times.
  2. Step 2: Recognize how interrupts affect wake-up

    The processor wakes immediately when an interrupt occurs, allowing quick response to external events.
  3. Step 3: Connect power saving and responsiveness

    This combination reduces energy use without missing important signals, ideal for embedded systems.
  4. Final Answer:

    It puts the processor to sleep until an interrupt wakes it, reducing power use without missing events -> Option A
  5. Quick Check:

    WFI = sleep + wake on interrupt = power save + responsiveness [OK]
Hint: WFI sleeps but wakes instantly on interrupts [OK]
Common Mistakes:
  • Thinking WFI disables interrupts
  • Assuming WFI speeds up processing
  • Believing WFI resets the processor
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard