Instruction cycle
How a stored-program computer runs: fetch, decode, optional indirect cycle, execute, and the interrupt check; the registers involved, register-transfer notation, the PC after the fetch, memory references per instruction and the clock cost of each instruction.
Why it exists
A computer does not know what a program is. It has a memory full of numbers and a small loop built into the hardware: take the number the program counter points to, treat it as an instruction, do what it says, and move on. Every program ever run is this loop repeated billions of times per second. The instruction cycle is that loop. Understanding it explains what the processor registers are for, why a jump is just an assignment to the program counter, why indirect addressing costs an extra memory access, and why the pipeline (a later topic) is an attempt to run several cycles at once. GATE questions ask which register holds what, what the PC contains at a given moment, how many memory accesses or clock cycles an instruction takes, and what the register transfers of a given instruction are.
Prerequisites
You need registers and their load and shift operations from registers and shift registers, and a picture of memory as numbered words.
Precise definitions
Stored-program computer (von Neumann architecture). Instructions and data are kept in the same memory and both are binary words. The processor fetches an instruction exactly as it fetches data; what the word means depends only on when it is used. A Harvard architecture has separate instruction and data memories (so an instruction and a data word can be fetched at the same time); modern caches are usually split this way.
The registers of the basic processor.
| Register | Role |
|---|---|
| PC (program counter) | address of the next instruction to fetch |
| MAR (memory address register) | address of the memory word to read or write |
| MDR or MBR (memory data/buffer register) | the word read from, or about to be written to, memory |
| IR (instruction register) | the instruction being decoded and executed |
| AC (accumulator) | the working data register of a one-address machine |
| general registers, SP, flags | data, the stack pointer, condition bits |
The instruction cycle repeats these phases:
- Fetch. Read the instruction at the address in PC into IR and advance PC.
- Decode. The control unit examines the opcode (and addressing-mode bits) in IR and decides which micro-operations follow.
- Indirect cycle (only for indirect addressing). Read the word at the given address to get the effective address of the operand.
- Execute. Carry out the operation: read an operand, use the ALU, write a result, or change PC.
- Interrupt check. If an enabled interrupt is pending, save PC and jump to the interrupt handler before fetching the next instruction (interrupts).
Register-transfer notation (RTL). A micro-operation is written ; means the memory word at that address. The fetch of the basic machine is:
Several transfers that use different buses and do not depend on each other can happen in the same clock (for example alongside the memory read), so the number of clocks for a fetch depends on the design. Here every transfer takes one clock so that each is visible.
Key facts about the PC. After the fetch, PC points to the next instruction (the address after the current one, i.e. current address plus the instruction length), not to the one being executed. A jump or taken branch simply overwrites PC with the target address; an untaken conditional branch leaves it alone. This is why PC-relative offsets are measured from the next instruction.
Memory references per instruction. Every instruction costs at least 1 (its own fetch). A direct memory operand adds 1 read or write. An indirect operand adds 1 more read (to get the address). An instruction using only registers or an immediate operand adds none.
Cost. If each micro-operation takes one clock, the cycle counts (for the basic machine in the animations) are: fetch 4, decode 1, then execute 3 for a direct load, add or store, 1 for a halt, and 2 more clocks for an indirect operand (indirect cycle). The average clocks per instruction is CPI, and execution time is (performance).
How it works
The animation runs this program on a small accumulator machine with 16-bit words (indirect bit, 3-bit opcode, 12-bit address): LDA 8, ADD 9, STA 10, HLT, with 5 at address 8 and 7 at address 9. Watch the PC: after each fetch it already points to the next instruction. Registers that just changed are amber; the memory row that just changed is amber too.
Instruction cycle: LDA, ADD, STA, HLT: step 1
Machine run, not typed(power on)| addr | hex | meaning | |
|---|---|---|---|
| 000 | 1008 | LDA 8 | PC |
| 001 | 3009 | ADD 9 | |
| 002 | 200A | STA 10 | |
| 003 | 0000 | HLT | |
| 008 | 0005 | ||
| 009 | 0007 | ||
| 00A | 0000 |
Step 1
All registers are 0. The program is already in memory; the memory rows on the right show the words and what they mean. PC = 0 points at the first instruction.
With indirect addressing the instruction LDA (5) does not contain the operand's address, but the address of a word that contains it. The machine needs an extra memory read, visible as the extra steps after decoding.
Indirect addressing: LDA (5), STA 11, HLT: step 1
Machine run, not typed(power on)| addr | hex | meaning | |
|---|---|---|---|
| 000 | 9005 | LDA (5) | PC |
| 001 | 200B | STA 11 | |
| 002 | 0000 | HLT | |
| 005 | 000A | ||
| 00A | 002A | ||
| 00B | 0000 |
Step 1
All registers are 0. The program is already in memory; the memory rows on the right show the words and what they mean. PC = 0 points at the first instruction.
Worked examples
EX 1The same machine written in C
EasyThe program below is a second implementation of the machine. It runs the same programs, counts memory reads and writes, and also runs a countdown loop.
#include <stdio.h>
#include <stdint.h>
/* the accumulator machine of the animation: 16-bit words, I | opcode(3) | address(12) */
enum { HLT, LDA, STA, ADD, SUB, JMP, JZ, LDI };
static uint16_t mem[4096];
static int reads, writes;
static uint16_t rd(uint16_t a) { reads++; return mem[a]; }
static void wr(uint16_t a, uint16_t v) { writes++; mem[a] = v; }
static void run(const char *name, int verbose) {
uint16_t pc = 0, ir, ac = 0, mar;
int ni = 0;
reads = writes = 0;
printf("%s\n", name);
for (;;) {
mar = pc;
ir = rd(mar); /* fetch: MAR <- PC, MDR <- M[MAR], IR <- MDR */
pc++; /* PC <- PC + 1 */
int ind = ir >> 15, op = (ir >> 12) & 7;
uint16_t addr = ir & 0xFFF;
ni++;
if (verbose) printf(" executing %04X at %03X (PC is now %03X)\n", ir, mar, pc);
if (op == HLT) break;
if (op == LDI) { ac = addr; continue; }
mar = addr;
if (ind) mar = rd(mar) & 0xFFF; /* indirect cycle: one more memory read */
switch (op) {
case LDA: ac = rd(mar); break;
case STA: wr(mar, ac); break;
case ADD: ac = (uint16_t)(ac + rd(mar)); break;
case SUB: ac = (uint16_t)(ac - rd(mar)); break;
case JMP: pc = mar; break;
case JZ: if (ac == 0) pc = mar; break;
}
}
printf(" AC = %u, %d instructions, %d memory reads, %d memory writes\n", ac, ni, reads, writes);
}
int main(void) {
/* direct: LDA 8; ADD 9; STA 10; HLT, with M[8] = 5 and M[9] = 7 */
mem[0] = 0x1008; mem[1] = 0x3009; mem[2] = 0x200A; mem[3] = 0x0000; mem[8] = 5; mem[9] = 7;
run("direct", 1);
printf(" M[10] = %u\n", mem[10]);
/* indirect: LDA (5); STA 11; HLT, with M[5] = 10 and M[10] = 42 */
for (int i = 0; i < 16; i++) mem[i] = 0;
mem[0] = 0x9005; mem[1] = 0x200B; mem[2] = 0x0000; mem[5] = 0x000A; mem[10] = 42;
run("indirect", 1);
printf(" M[11] = %u\n", mem[11]);
/* a loop: count down from 3, with M[21] = 1 */
for (int i = 0; i < 32; i++) mem[i] = 0;
mem[0] = 0x7003; mem[1] = 0x2014; mem[2] = 0x1014; mem[3] = 0x6008; mem[4] = 0x4015; mem[5] = 0x2014; mem[6] = 0x5002; mem[8] = 0x0000; mem[21] = 1;
run("loop", 0);
return 0;
}direct
executing 1008 at 000 (PC is now 001)
executing 3009 at 001 (PC is now 002)
executing 200A at 002 (PC is now 003)
executing 0000 at 003 (PC is now 004)
AC = 12, 4 instructions, 6 memory reads, 1 memory writes
M[10] = 12
indirect
executing 9005 at 000 (PC is now 001)
executing 200B at 001 (PC is now 002)
executing 0000 at 002 (PC is now 003)
AC = 42, 3 instructions, 5 memory reads, 1 memory writes
M[11] = 42
loop
AC = 0, 20 instructions, 27 memory reads, 4 memory writesReading the output. In the direct program the four fetches plus two operand reads make 6 reads, and the one STA is the 1 write. In the indirect program LDA (5) has three reads (fetch, address, operand) and the whole program has 5 reads. The countdown loop runs 20 instructions with 27 reads and 4 writes, 31 memory references in total.
EX 2Which register holds what?
EasyDuring ADD 9 (the second instruction of the first program): after the fetch, IR holds the encoded instruction 3009 and PC holds 002 (the next instruction). MAR holds 009 while the operand is read, MDR holds 7 (the operand just read), and AC holds 5 before the add and 12 after. The program counter never holds the address of the instruction being executed: it has already moved on.
EX 3Memory references and clocks per instruction
MediumFrom the animations (one clock per micro-operation): LDA 8, ADD 9 and STA 10 each take clocks and make 2 memory references (one fetch plus one operand access). HLT takes clocks and 1 reference. The indirect LDA (5) takes clocks and 3 references. The first program therefore needs clocks for 4 instructions after the start, so the average is 7.5 clocks per instruction (the generator confirms these counts from the animation).
EX 4PC after the fetch
MediumA byte-addressable memory holds a 4-byte instruction at address 1000. After its fetch, PC = 1004. If the instruction is an unconditional jump to 2000, PC becomes 2000 during its execute phase. If it is a conditional branch that is not taken, PC stays 1004. If an interrupt occurs after this instruction, the 1004 (or 2000) is what is saved, so the handler returns to the right place.
EX 5Counting memory accesses for a loop
GATE levelThe countdown loop of the program (three iterations of five instructions, plus setup and exit) executes 20 instructions: each is fetched once (20 reads); LDA, SUB read an operand (the LDA runs 4 times, SUB 3 times, so 7 operand reads); STA writes (once in the setup, three times in the loop: 4 writes). Total reads and writes 4, as the program reports. Always count instruction executions, not instruction addresses: a loop body is fetched once per iteration.
EX 6RTL of an instruction
GATE levelWrite the micro-operations of a conditional jump JZ addr on this machine: after the fetch and decode, ; then if the accumulator is zero, . If AC is not zero nothing else happens and the next fetch reads the following instruction. A subroutine call would additionally push the old PC (the return address) before loading the target. The animations show the same structure for ADD: , , .
Cheat box
Cheat box
- Fetch: MAR PC; MDR M[MAR]; IR MDR; PC PC + 1. Then decode, (indirect), execute, interrupt check.
- After the fetch PC points to the next instruction. A jump overwrites PC.
- Memory references: 1 (fetch) + 1 per direct memory operand + 1 more for indirect. Register and immediate operands add none.
- Indirect addressing adds one memory read and a few micro-operations.
- Von Neumann: one memory for instructions and data. Harvard: two.
- Execution time = instruction count CPI clock period.
- Registers: PC (next address), MAR (memory address), MDR (memory data), IR (current instruction), AC.
Traps and GATE patterns
Connections
Builds on
Unlocks
Across subjects
Within this subject
Journeys that pass through here
The shape of an instruction (its fields) and the choice of operands are the topic of instruction set architecture and addressing modes. The registers and buses that carry out these micro-operations are the datapath, and the unit that produces the control signals for each step is a hardwired or microprogrammed control unit, itself a state machine. Pipelining overlaps the fetch of the next instruction with the execution of the current one, and interrupts are the extra check at the end of the cycle.
PYQs
6 previous year questions from your book. I re-solved each one myself (3 by running or simulating, 3 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the following instruction sequence where registers R1, R2 and R3 are general purpose and MEMORY [X] denotes the content at the memory location X . Instruction Semantics Instruction Size (bytes) MOV R1,(5000) R1 ← MEMORY[5000] 4 MOV R2,(R3) R2 ←MEMORY[R3] 4 ADDR2, R1 R2 ← R1 + R2 2 MOV (R3), R2 MEMORY[R3]← R2 4 INC R3 R3 ← R3 + 1 2 DEC R1 R1 ← R1 - 1 2 BNZ 1004 Branch if not zero to the given absolute address 2 HALT Stop 1 Assume that the content of the memory location 5000 is 10 , and the content of the register R3 is 3000 . The content of each of the memory locations from 3000 to 3010 is 50 . The instruction sequence starts from the memory location 1000. All the numbers are in decimal format. Assume that the memory is byte addressable. After the execution of the program, the content of memory location 3010 is
The following are some events that occur after a device controller issues an interrupt while the process L is under execution. (P) The processor pushes the process status of L onto the control stack. (Q) The processor finishes the execution of the current instruction. (R) The processor executes the interrupt service routine. (S) The processor pops the process status of L from the control stack. (T) The processor loads the new PC value based on the interrupt. Which one of the following is the correct order in which these events above occur?
- (a)QPTRS
- (b)PTRSQ
- (c)TRPQS
- (d)QTPRS Computer Organization and Architecture GATE CSE – NAT 2016 SET- 2 (1-MARKS)
Consider the following program segment. Here R1, R2 and R3 are the general purpose registers. Instruction Operation Instruction Size (no. of words) MOV R1,(3000) R1 ← M3000] 2 LOOP: MOV R2,(R3) R2←M[R3] 1 ADD R2,R1 R2 ← R1 + R2 1 MOV (R3),R2 M[R3] ←R2 1 INC R3 R3←R3+1 1 DEC R1 R1 ← R1 - 1 1 BNZLOOP Branch on not zero 2 HALT Stop 1 Assume that the content of memory location 3000 is 10 and the content of the register R3 is 2000. The content of each of the memory locations from 2000 to 2010 is 100. The program is loaded from the memory location 1000. All the numbers are in decimal. Assume that the memory is word addressable. The number of memory references for accessing the data in executing the program completely is
- (a)10
- (b)11
- (c)20
- (d)21
Consider a three-word machine instruction: ADD A [R0], @B The first operand (destination) "A [R0]" uses indexed addressing mode with R0 as the index register. The second operand (source) "@B" uses indirect addressing mode. A and B are memory addresses residing at the second and the third words, respectively. The first word of the instruction specifies the opcode, the index register designation, and the source and destination addressing modes. Computer Organization and Architecture During execution of the ADD instruction, the two operands are added and stored in the destination (first operand). The number of memory cycles needed during the execution cycle of the instruction is:
- (a)3
- (b)4
- (c)5
- (d)6
Consider the following data path diagram Consider an instruction: R0 ← R1 + R2. The following steps are used to execute it over the given data path. Assume that the PC is incremented appropriately. The subscripts r and w indicate read and write operations, respectively. 1. R2r TEMP1r, ALUadd, TEMP2w 2. R1r TEMP1w, 3. PCr, MARw, MEMr 4. TEMP2r, R0w 5. MDRr, IRw Which one of the following is the correct order of execution of the above steps?
- (a)2,1,4,5,3
- (b)1,2,4,3,5
- (c)3,5,2,1,4
- (d)3,5,1,2,4
Consider the following sequence of micro - operations. MBR ← PC MAR ← X PC ← Y Memory ← MBR Which one of the following is a possible operation performed by this sequence? Computer Organization and Architecture
- (a)Instruction fetch
- (b)Operand fetch
- (c)Conditional fetch
- (d)Initiation of interrupt service
Self-check
Question 1
An instruction occupies 2 bytes in a byte-addressable memory and is at address 300. What does the PC hold after its fetch, and what if the instruction is a taken jump to 500?
Show answerHide
After the fetch PC = 302. A taken jump replaces it with 500 in the execute phase.
Question 2
How many memory references does ADD (X) (memory indirect, one-word instruction) make, counting the instruction fetch?
Show answerHide
3: the fetch, the read of the word at X (which holds the operand address), and the read of the operand.
Question 3
A loop body of 5 instructions executes 100 times, with 3 of the 5 instructions each having one direct memory operand. How many memory references does the loop make in total (ignoring the setup)?
Show answerHide
Per iteration: 5 fetches + 3 operand references = 8. Total .
Question 4
Which register supplies the address on the address bus during the fetch, and which one holds the instruction after it?
Show answerHide
MAR drives the address bus (it was loaded from PC), and IR holds the instruction after the fetch (it was loaded from MDR).
Revision card
One-screen revision
- Cycle: fetch, decode, (indirect), execute, interrupt check. Fetch: MAR PC; MDR M[MAR]; IR MDR; PC PC + 1.
- PC = next instruction after the fetch; a jump overwrites it.
- Memory references: fetch + direct operand (1) + indirect extra (1).
- One clock per micro-operation here: direct LDA/ADD/STA 8 clocks, HLT 6, indirect LDA 10; books differ on overlapping transfers.
- Time = IC CPI period. Von Neumann = shared memory; Harvard = split.
References
- ·Hennessy and Patterson, Computer Organization and Design, Chapter 4 The Processor (an overview of instruction execution)
- ·Morris Mano, Computer System Architecture, 3rd ed., Chapter 5 Basic Computer Organization and Design (instruction cycle, register-transfer description)
- ·Hamacher, Vranesic, Zaky, Computer Organization, 5th ed., Chapter 7 Basic Processing Unit (fetching and executing instructions)
Verification
The animations are runs of a simulated accumulator machine (scripts/gen-coa-traces.py) that tests/coa-traces.test.ts re-runs with an independent implementation, checking final state, memory reads and writes, micro-operation counts and the PC rule. The C program is a second implementation of the same machine, compiled and run by npm run verify:c; the micro-operation counts per instruction are read back from the generated traces in scripts/enum-checks/coa_isa.py. The machine is a teaching design (modelled on the style of the textbook basic computers, but its encoding is our own), so details such as how many micro-operations share one clock differ between books and from real processors; those are flagged in the text. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand (long C programs were not re-read line by line: they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)