Skip to content
Fetch-Decode-Execute Loop
step 1/5

Reading — step 1 of 5

Read

~2 min readExecution

Fetch-Decode-Execute Loop

Putting it together:

python

The loop is straightforward; the per-instruction logic is the real work. Get one instruction right; the rest are templates.

Edge cases:

  • Misaligned pc (set jal to odd address): exception.
  • Memory bounds: catch Python IndexError; raise as exception.
  • Division by zero (M extension): defined behavior (returns -1 for signed div).

System instructions:

  • ECALL: software interrupt. In our toy, dispatch syscall by a7.
  • EBREAK: debugger trap. Pause for inspection.
  • FENCE: memory ordering. No-op for single-core.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…