Difficulty: Medium
Correct Answer: General purpose registers, program counter, stack pointer, and status or flag registers that together represent the current state of execution
Explanation:
Introduction / Context:
When an operating system switches the CPU from running one process to running another, it must perform a context switch. This involves saving the current process state and restoring the state of the next process. Much of this state is stored in CPU registers, which hold temporary data, addresses, and control information. Understanding which types of registers are involved is important for grasping how process scheduling works.
Given Data / Assumptions:
Concept / Approach:
During a context switch, the operating system saves the CPU context of the currently running process into its process control block and restores the context of the next process to run. The context includes general purpose registers that hold data and addresses, the program counter that indicates the next instruction to execute, the stack pointer that refers to the top of the process stack, and status or flag registers that record condition codes and control bits. On some architectures, additional registers such as segment registers, floating point registers, and control registers may also be saved and restored when necessary. However, the core set is the combination of general purpose registers, program counter, stack pointer, and status registers.
Step-by-Step Solution:
Step 1: Identify the registers that directly influence the flow and results of program execution.Step 2: Recognize that general purpose registers hold temporary data and addresses in use by the process.Step 3: Note that the program counter must be saved so that the process can resume at the correct instruction.Step 4: Include the stack pointer and status or flag registers, which manage call stacks and conditional execution.Step 5: Choose the option that lists these categories together as the main types of registers saved and restored.
Verification / Alternative check:
Descriptions of context switching in textbooks and processor manuals often show code that pushes all general purpose registers and status registers onto a stack or saves them to memory. For example, on x86 architecture, context switches typically save registers such as EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP, EIP, and EFLAGS. This set corresponds to general purpose registers, stack pointer, program counter, and status flags. Similar patterns exist on other architectures, confirming that these are the fundamental registers involved.
Why Other Options Are Wrong:
Option B: Claims that only the program counter is needed, which ignores the many other registers that store important process state.Option C: Refers to input and output device registers, which are not the primary concern of CPU context switching for user processes.Option D: Focuses solely on floating point registers, which may be part of the context but are not the only or main registers that must be saved.
Common Pitfalls:
One mistake is to underestimate how much state is stored in registers and overestimate what is kept in memory. While memory holds program code and data, registers hold the immediate working set of a process. Another pitfall is to assume that only user visible registers matter. In reality, some control registers and special purpose registers may also be involved, especially in kernel mode context switches. The key idea for exam questions is the set of general purpose, program counter, stack pointer, and status registers.
Final Answer:
The correct answer is General purpose registers, program counter, stack pointer, and status or flag registers that together represent the current state of execution.
Discussion & Comments