Skip to content

Simple CPU Assembly Language

Assembly Language is a type of programming language used to directly interact with a certain CPU model. We are going to look at an assembly language for a very simple (and fictional) CPU.

This CPU will have 16 storage locations, known as registers, labelled r0 through r15. It will also have an Arithmetic Logic Unit, which is responsible for processing each instruction. You can visualize this as follows:

Simple CPU Registers

The assembly language for this CPU has four commands:

set destination, value

Assigns a value to the specified destination register.

Example

set r1, 7
sets the value of r1 to 7.


add destination, source1, source2

Adds the values of two registers, and stores the result in the specified destination register.

Example

add r1, r2, r3
adds the values in r2 and r3 and puts the result into r1.


sub destination, source1, source2

Subtracts the values of two registers, and stores the result in the specified destination register.

Example

sub r1, r2, r3
subtract r2 - r3 and puts the result into r1.


mul destination, source1, source2

Multiplies the values of two registers, and stores the result in the specified destination register.

Example

mul r1, r2, r3
multiplies the values in r2 and r3 and puts the result into r1.