1

So I am going through some tutorials, and it seems they keep using "instructions" and "cycles" interchangeably, so now I am confused what is actually measured in Hertz (on the most basic level, without going into what the modern processors can do in parallel etc, trying to learn the basics here).

Say, the program is as follows: load two numbers, add them, store result. So there will be 4 cycles:

  1. load number A [fetch-decode-execute]
  2. load number B [fetch-decode-execute]
  3. add A and B [fetch-decode-execute]
  4. store result [fetch-decode-execute]

What is a cycle here, and what is an instruction?

There are 4 cycles, or 12 instructions, correct?

Say, it takes CPU 1 sec to run this program. What will be the CPU clock speed? 12 instructions/1 sec or 4 cycles/1 sec?

  • If the former one, then is the clock speed of the CPU 12 Hertz?

  • If the latter one, then is the clock speed of the CPU 4 Hertz?

Uylenburgh
  • 1,277
  • 4
  • 20
  • 46
  • 1
    You have written a program that contains 4 instructions. It sounds like you are assuming each instruction takes 3 clock cycles to run (though it is unlikely to be so simple on any advanced processor). So if it runs in 1 second, the clock speed is 12 cycles per second, aka 12 Hz. – Nate Eldredge Jun 25 '20 at 15:04
  • If you could quote a particular passage from one of the tutorials that's confusing you, someone might be able to help explain it more clearly. – Nate Eldredge Jun 25 '20 at 15:07
  • @NateEldredge so is "fetch" one _cycle_ or one _instruction_? I thought a "cycle" was referring to the "fetch-decode-execute". – Uylenburgh Jun 25 '20 at 15:32
  • this video, she mentions both "cycle" and "instruction" but I am confused which one refers to what https://youtu.be/FZGugFqdr60?list=PL8dPuuaLjXtNlUrzyH5r6jN9ulIgZBpdo&t=510 "The speed at which a CPU can carry out each step of "fetch-decode-execute" CYCLE is measured in Hertz" – Uylenburgh Jun 25 '20 at 15:34
  • 1
    I see. The word "cycle" is generic, just referring to any instance of a repetitive process. Depending on context, it could refer to a *clock* cycle (one clock tick) or a sequence of events that takes several clock ticks (e.g. a *fetch-decode-execute* cycle). It's more commonly used to mean "clock cycle" but that doesn't mean other usages are wrong if they are clarified. – Nate Eldredge Jun 25 '20 at 17:33
  • 1
    The *instructions* in your example are what you have numbered 1,2,3,4, e.g. "load number A". Each corresponds to a single line of assembly code, or a particular sequence of bytes of machine code, that have a particular effect on the state of the machine as seen by the programmer (e.g. contents of registers and memory). "Fetch, decode and execute" are sometimes called **stages** of the instruction's execution, but they are not themselves instructions as they can't happen in isolation. – Nate Eldredge Jun 25 '20 at 17:38
  • You might find https://en.wikipedia.org/wiki/Instruction_cycle to be helpful. – Nate Eldredge Jun 25 '20 at 17:40
  • If a fetch-decode-execute cycle is one cycle, then why the clock speed is not 4Hz but 12 Hz? – Uylenburgh Jun 25 '20 at 18:09
  • 2
    A fetch-decode-execute cycle is one **instruction cycle**, but three **clock cycles**. The clock speed measures the number of **clock cycles** per second. – Nate Eldredge Jun 25 '20 at 18:51

1 Answers1

1

From helpful comments by @Nate Eldredge:

"A fetch-decode-execute cycle is one instruction cycle, but three clock cycles.

The clock speed measures the number of clock cycles per second."

Thus, if the program is executed within 1 second, and it takes 12 clock cycles, the clock speed of that particular CPU is 12 Hz.

Uylenburgh
  • 1,277
  • 4
  • 20
  • 46