Member-only story

How Does a Microprocessor Run a Program?

How instructions are fetched, decoded and executed in a RISC processor

Erik Engheim
9 min readDec 1, 2022

Once assembly code has been turned into machine code, it can be loaded into computer memory and executed. In this article, I will use the Calcutron-33 example code, but the basic of the operations are the same for any RISC-like microprocessor such as a RISC-V or Arm-based processor.

In this section, I will break down all the steps involved in executing a machine code instruction. The first step is to write an assembly code program. Here is an example of a simple program which loads the numbers 42 and 23 stored in memory, adds them to produce 65 and store the result in another memory location.

LOAD x1, first
LOAD x2, second
ADD x3, x1, x2
STOR x3, result
HLT

first:
DAT 42

second:
DAT 23

result:
DAT 0

This program must be converted to machine code before it can be loaded into memory and executed. If you have downloaded the Calcutron-33 source code you can find this example program under examples/memadder.ct33. With the Calcutron-33 tools installed, you can use the cutron asm command to produce machine code.

❯ cutron asm memadder.ct33
5105
5206
1312
7307
0000
0042
0023
0000

--

--

Erik Engheim
Erik Engheim

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

No responses yet