Вы находитесь на странице: 1из 2

CSC321: Microprocessor and Assembly Language – Fall 2020

Assignment-2 Programming [CLO-C4]


Deadline: Oct 15, 2020 11:59 pm Max. Marks: 30
----------------------------------------------------------------------------------------------------------------------------------
Implement following programs in JAVA/Any Programming Language
CPU Simulator

Students are required to simulate a simple CPU that would be executing a program brought inti
memory for execution. Memory is of 4096 words (can be implemented as an array of short
ints).

This program (CPU Simulator) would be flexible in that it must be able to execute any program
(consisting any number of 16-bits instructions and any number of variables/data)
CPU will contain the following registers
1. AC
2. PC
3. IRMAR
4. MBR

CPU will use following methods when running program


1. Fetch()
With the help of PC, Value will be fetched and stored in IR
2. Decode()
Contents of IR (i.e. 16 bit instruction) will be decoded---getting operation code and
Address from where value(operand) will be taken.
3. GetOperands()
With the help of address Operand will be fetched from memory
4. Execute() )
Having op-code and operation, Operation will be performed.

Program will run and displays like this for every statement
Executing statement #1
Statement is Load
Executed….

Executing statement # 2
Statement is Add
Executed….
Terminating program
Result is
AC=------, PC=-------

TESTING
Test your CPU against the following programs

LOAD C 0001 0000 0000 0000 0100


ADD B 0011 0000 0000 0000 0101
STORE A 0010 0000 0000 0000 0110
EXIT 0111 0000 0000 0000 0000
C =5 0000 0000 0000 0000 0101
B=6 0000 0000 0000 0000 0110
A=0 0000 0000 0000 0000 0000

Show state of the CPU (Means all register’s value) when program terminates

Also Test your CPU for the following expression


Z=W+(X-Y)

Assembly level is like this


LOAD X
SUBT Y
ADD W
STORE Z
EXIT Convert to
X=5 machine
Y=4
W=9
Z=0

Answer the followings

a) With 4-bit OP-Code, how many operations are possible? If we want to design a CPU that would
be able to execute 256 operations…. what would be done at machine level?
b) Operand is taken from memory…by 12-bit address …. what do you think are the other places,
operands can be stored?