FDE Cycle Tracer
Write a function trace_pc(program, steps) that simulates the Program Counter (PC) stepping through a simplified list of instructions.
programis a list of instruction strings. Most instructions just mean "do some work, then move to the next instruction" (PC increases by 1). An instruction that starts with"JUMP", e.g."JUMP 0", instead sets PC directly to the given address.stepsis how many fetch steps to simulate.- Return a list of the PC value at the start of each step (i.e. before that step's instruction is carried out), matching exactly how the lesson's own trace table records PC.
Read the number of instructions, then that many instruction lines, then the number of steps, from input. Print the resulting trace as space-separated integers.
Example: program ["LOAD A", "ADD B", "JUMP 0"], 5 steps → the PC visits 0, 1, 2, then the JUMP sends it back to 0, and the cycle repeats → 0 1 2 0 1.
main.py
Loading editor…
Console
Run your code to see output here.