CPU Design And Simulation Computer Science Essay


This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

The report first exemplifies the aim and objective of the CPU assignment. First I will explain what computer instruction, operand are and how they are added and executed. In this report I will explain the designing CPU SIMULATOR, part contain of developing the algorithm for the simulator and developing it using C++ and later the simulator is experienced by executing set of instructions. After testing and debug I will conclude this assignment with references.


To design an 8-bit CPU simulator that can perform basic operations can take input and execute them and will be able to perform following operations.

The main aim of this assignment is to write a code in C++ to simulate the 8-bit CPU.

Define a instruction set for the 8-bit CPU simulation.

Describe the Simulator Algorithm and

Code in C++ for 8-bit CPU Simulator.


A CPU is made of combination of gates and flip-flops to carry out mathematical operations, all the arithmetic operation of a microprocessor taken place in the ALU (Arithmetic Logic Unit). Control Unit send signals to perform an operation. The data on which operation are performed will come from external input or memory. Then the input is operated in appropriate manner with the contents of the accumulator and the output will placed in the accumulator. From accumulator output will be transferred to memory or to an output unit.

In genral computer BUS plays an important role to transfaring data within computer components or between computers. There are mainly three kinds of bus Address Bus which is used to transfer addresses from Central Processing Unit to Main Memory and Input-output devices. Data bus is bi-directional bus which transfer data between CPU , Memory and Peripheral devices. All the computer computer components talks to CPU and memory using Data bus. CPU uses control bus to control peripheral devices or the external device to send synchronization message to the CPU.

Overall Central Processing Unit (CPU) is a general-purpose instruction set which operates on instructions and data which are obtained by the processor from memory or input/output devices.

Instruction Set

To design a CPU first thing we need to keep in mind is instruction that needs to support. Finally, now come to the core of computing: the programs how and what to direct central processing unit to control and finally find the result is instruction set.There are mainly two type of instruction sets CISC (Complex instruction set computer) and RISC (reduced instruction set computers).

CISC are compact register which can support complex, powerful and large instruction set. RISC is numerous registers which can support simple hard-wired machine code and Limited instruction set but still works on many processers that are arranged in parallel and are able to execute simple instruction concurrently.

Instruction set design:

The main four basic component instruction contains are:

Operation Code (OP-CODE): is a machine language instruction which control what type of action the computer should take, e.g. add, sub, load, and store. In our 8-bit CPU design the most important 3-bits might be the op-code giving 8 possible operations and other given parameter addressing mode and operand. Every op-code must be unique with each other.

On the above example 3 bit is use for OPCODE which is 2^3=8 is used for instruction set. Operation Code is a Code that instructs the computer to execute the instruction. In our Simulator will able to instruct following instructions.




ADD N or ADD [N]


SUB N or SUB [N]


LDA N or LDA [N]


STA N or STA [N]





the 7 instruction we required at least 3 bit of the instruction (as 2^3 =8, meaning up to 8 instruction can be represented)

The operational code for the instruction is as follows












Branch & compare




Source Operand reference: must specify in instruction, Operand can be passed directly which is called direct instruction or through the address, which contains the value to be use which is called indirect addressing.

Result Reference: The result of the operation is placed in some place that is called result reference. This also can be direct or indirect depends on whether the value supplied directly or indirectly through an address reference.

Next instruction Reference: This show how and where another instruction could be finding.

The Algorithm for the CPU Simulator:

First to design the CPU Simulator we need to do the develop the algorithm for all duty that CPU needs to do either enter instruction or execute instruction, etc.

A user can give instruction as per displayed on the screen the program counter (PC) will start from the location 0. User first need to select operational code (op-code), then the addressing mode (AMOD) and then the operand.

Basic Algorithm:

Below is the basic algorithm for user to follow:

1.Start the program counter (PC) location 0

2. Display the options to choose for the OPCODE

1. Add

2. Subtract

3. Load

4. Store

5. Branch

6. Branch and Compare

7. Stop

3. Get user option


If 0 is chosen Add 32 (Binary 0010 0000 => Add) to Code memory index PC

Then, go to AMOD


If 1 is chosen Add 64 (Binary 0100 0000 => subtract) to Code memory index PC,

Then, go to AMOD


If 2 is chosen Add 96 (Binary 0110 0000 => Load) to Code memory index PC

Then go to AMOD


If 3 is chosen Add 112 (Binary 0111 0000 =>Store) to Code memory index PC

Then go to AMOD


If 4 is chosen Add 128 (Binary 0111 0000 =>Branch) to Code memory index PC

Then go to AMOD

BRANCH and Compare

If 5 is chosen Add 160(Binary 1011 0000 =>Branch and compare) to Code memory index PC

Then go to AMOD


If 6 is chosen Add 176 (Binary 1011 0000 =>Stop) to Code memory index PC

Exit .


4.Display user Addressing Mode

0. Indirect

1. Direct

5. Get the Input option.


If 0 chosen Add 0 (Binary 0000 0000=> Indirect to connect of code memory Index PC


If 1 chosen Add 1 (Binary 0001 0000=> Indirect to connect of code memory Index PC

5.Display result and the message

Press y to continue or n to exit.

If y is chosen press go to top.

If n is chosen end program.

6.If y is pressed return to step 1 else exit.

System Algorithm

Once the user input now its time for system Algorithm to job how to use the instruction and her is the algorithm how it wors:

1. Store the value of Program counter in Memory Address Register ([MAR]  [PC])

2. Decode the instruction value in MBR and place the opcode in IR

3. If op-code is Add (000) and mode is direct

Add operand to Accumulator


Add operand to memory buffer

4.If op-code is Subtract (001) and mode is direct

Subtract operand from Accumulator


Subtract data address contents from Accumulator

5.If op-code is Load (010) and mode is direct

Load accumulator with Operand


Load data address into Accumulator

6.If op-code is Store (011) and mode is direct

Store Accumulator in data memory.


Store Accumulator in data memory location Specified by value in data memory address.

7.If op-code is Branch (100)

Branch to program memory Location

8.If op-code is Branch and Compare(101)

Compare accumulator with data and branch to program Memory location if the values are equal

7.If op-code is Load (110) Stop execution

RTL description

[A]  [A] + N; Add operand to Accumulator

[A][A]+[M(N)]; Add operand to memory buffer as indirect addressing

[A][A]-N ; Subtract operand from Accumulator

[A][A]-[M(N)]; Subtract data address contents from Accumulator

[A]  N; Load accumulator with Operand

[A][M(N)] ; Load data address into Accumulator

[M (N)]  [N]; Store Accumulator in data memory.

[MN(N)][A]; Store Accumulator in data memory location Specified by value in data memory address.

[PC]  N; Branch to program memory Location

[A] = N!, [PC]  N; Compare accumulator with data and branch to program Memory location if the values are equal

[PC]  STOP; Stop execution


The 8-bit CPU Simulator is developed in C++. Because C++ is an object oriented programming language designed mainly for system programming. There is two classes define separately. Class "input" is use to fetch the input from the user and other Class "CpuSim" which have its register and this class helps execute the instruction provided.


The code is written and compiled in Borland Dev-C++ and given name CpuSim.cpp and the CpuSim.exe file is provided in CD with this project.


When we execute the exe file the black command line window is seen the main screen is in the screenshot.

Now CPU Simulator is ready to work and in running state.

User can enter the value of option given to start the CpuSim.


Now the CpuSim is ready and can tested entering instruction and executing them. Here is some example instruction which we can use to test the simulator.

1. Load DIRECT 4


3. Store DIRECT 0

4. Subtract DIRECT 3

5.Store INDIRECT 5


These instruction will load 4 to Accumulator register Acc, add 3 to Acc and save the result in data memory location 0 again substract 3 from Accumulator register Acc and load in data memory location 5.

To load user need to select 3.

Screen ask for the Addressing mode choose 1 for direct.

Now Screan will ask for operand enter 4.

Now operand is loded in Accumulator.

To add user need to select 1

Screen ask for the Addressing mode choose 1 for direct

Now screen will ask for operand enter 3.

Now we can see the Accumullator is changed to 7

To store user need to select op-code 4

Screen ask for the Addressing mode choose 1 for direct

Now screen will ask for memory location enter 0.

Now we can see the memory location 0 is changed to 7

To substract user need to select opcode option 2

Screen ask for the Addressing mode choose 1 for direct

Now screen will ask for operand enter 3.

Now we can see the Accumullator is changed to 4

To store user need to select op-code 4

Screen ask for the Addressing mode choose 0 for Indirect

Now screen will ask for memory location enter 5.

Now we can see the memory location 5 is changed to 4

All the above screen shots and the example shows that the instruction given to do some task to CPU is working properly.


The main aim of this assignment is, to design, builds and tests a simple, easy to use

8-bit CPU simulator was successfully tested.

The 8-bit instruction set taking instruction from the user process the instruction in cup and give result in the output. It displays the registry and memory status. This is just initial construction of CPU SIMLATOR in C++, we are just using 8 bit CPU with 3 bits for operational code 1 bit for Addressing mode and 4-bits are used for operand. On the report not only simulating CPU it also defines the important concepts of CPU design and how it works in different forms.

Writing Services

Essay Writing

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.