Machine cycle

From C64-Wiki
Jump to navigationJump to search

A machine cycle (CPU cycle) is the time the processor takes to execute one machine language command.

During one machine cycle the processor executes at least two steps, fetch (data) and execute (command). The more complex a command is (more data to fetch), the more cycles it will take to execute. Reading data from the zeropage typically needs one cycle less as reading from an absolute address. Depending on the command, one or two more cycles will eventually be needed to modify the values and write them to the given address.

For example the command LDA $D020 takes 4 machine cycles:

fetch Opcode (LDA)

fetch $D020 low byte (20)

fetch $D020 high byte (D0)

fetch data from $d020 - load into accu

It has to be considered how long a specific command takes to execute when coding, so that the whole timing inside the program altogether and specially the screen output works. This is referred to as "cycle counting". Beginners in assembler programming often throw in NOP commands (takes two cycles) to achieve a stable timing.

Also see raster time for more info on CPU cycles.