computer architecture project documentation - open source
TRANSCRIPT
-
8/2/2019 Computer Architecture Project Documentation - Open Source
1/22
New Era University
College of Engineering and Technology
Computer Science Department
Computer Architecture Lecture
Project
Microprocessor Design and Simulation
Rating
Submitted by: Date of Submission:
Leandro M. Santos
Rodel R. Aguinaldo
Nieljun Acebes
John Ethelbert Terrado
Gerard Kristoffer C. Sabado
March 6, 2012
Submitted to:
Prof. Gaucho Agregado
-
8/2/2019 Computer Architecture Project Documentation - Open Source
2/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
1
Table of Contents
Zero Operand Microprocessor (Cipher) 2
One Operand Microprocessor (Primo) 3
Notes on one operand instructions 4Two Operand Microprocessor (Ritornare) 5
Three Operand Microprocessor (Ciel) 5
Addressing Modes 6
Main Memory 8
Constructing an instruction in the main memory: 11
Stack Memory 18
Initialization of the processor components during
simulation
18
Source Codes 22
ACC 23
ALU 23
AR 25
CU 26
IR 49
MAR 50
MBR 51
MM52
PC 55
Stack 56
Cipher 57
Primo 58
Ritornare 59
Ciel 60
UML Class Diagrams 63
-
8/2/2019 Computer Architecture Project Documentation - Open Source
3/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
2
Cipher (Zero Operand Processor)
Diagram of Zero Operand Microprocessor
Assembly Meaning Description
POP R1 R1 = Stack[top element] Takes the top most element of the stack and sends it to the register R1.Stackpointer is then decremented by 1.
Note: R1 may be replaced by any register such as R2.
PUSH R1 Stack[top element] = R1 Copies the data from the R1 and sends it on top of the stack. Stack pointer is
then incremented by 1.
Note: R1 may be replaced by any register such as R2 and ACC.
ADR ACC = R1 + R2 Adds the value of R1 and R2 and sends it to Accumulator
DIF ACC = R1 - R2 Subtracts the value of R1 to R2 and sends it to Accumulator
MUL ACC = R1 * R2 Multiplies the value of R1 and R2 and sends it to Accumulator
DIV ACC = R1 / R2 Divides the value of R1 to R2 and sends it to Accumulator
INCR ACC = R1 + 1 Increments the value at register R1 and sends it to Accumulator
DECR ACC = R1 - 1 Decrements the value at register R1 and sends it to Accumulator
-
8/2/2019 Computer Architecture Project Documentation - Open Source
4/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
3
Primo (One Operand Processor)
Diagram of One, Two and Three Operand Microprocessor
Assembly Meaning Description
READ [2000] R1 = [2000] Reads the data in address [2000] and copies it to register R1.COPY R1 R1 = R2 Copies the value from R2 and send it to R1
Note: COPY command is used exclusively for R1 to R2 and R2 to R1
transferring of data.
WRITE [2000] [2000] = ACC Reads the data in the Accumulator and sends it to address [2000].
Note: WRITE is exclusively used for sending data from ACC to Main Memory
ADR [4000] ACC = R1 + R2
[4000] = ACC
Adds the value of register R1 and R2 and sends it to address [4000].
Note: the parameter of ADR can be changed into a register such as R1 and R2
DIF [4000] ACC = R1 + R2
[4000] = ACC
Subtracts the value of register R1 and R2 and sends it to address [4000].
Note: the parameter of DIF can be changed into a register such as R1 and R2
MUL [4000] ACC = R1 * R2
[4000] = ACC
Multiplies the value of register R1 by R2 and sends it to address [4000].
Note: the parameter of MUL can be changed into a register such as R1 and
R2
DIV [4000] ACC = R1 / R2
[4000] = ACC
Divides the value of register R1 by R2 and sends it to address [4000].
Note: the parameter of DIV can be changed into a register such as R1 and R2
INCR R1 ACC = R1 + 1
R1 = ACC
Increments the value of register R1 by 1. R1 can be changed in to R2 or an
address from the main memory.
DECR R1 ACC = R1 - 1
R1 =ACC
Decrements the value of register R1 by 1. R1 can be changed in to R2 or an
address from the main memory.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
5/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
4
Notes on one operand instructions
The one, two and three operand microprocessor shares the same diagram.
Take note that in one operand instructions, the Register or address next to ADR, DIF, MUL, DIV are
specifying the storage of the final result of the computation of R1 and R2. Example: If I used DIV R2
command and the R1 and R2 has the following value: R1: 5 R2: 1, the value ofR2 will be R2 = R1 / R2
R2:5.
Take note that INCR command increments the value by 1 and it involves placing the value specified in
the operand to increment it by 1. Example: INCR [40], the command increments the value of address
[40] by one, so if address [40] has the value of10..
R1 = [40] R1: 10
R1+=1 R1: 11
ACC = R1 ACC: 11
[40] = ACC [40]: 11
Final values:
ACC: 11
R1: 11
[40]: 11
The same is true with DECR command
-
8/2/2019 Computer Architecture Project Documentation - Open Source
6/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
5
Ritornare (Two Operand Processor)
Ciel (Three Operand Processor)
Assembly Meaning Description
READ [2000], [4000] [2000] = [4000] Reads the data in address [4000] and copies it to address [2000].
Note: the parameters of read could be change to accommodate register to
register, memory to register data transfer. EX. READ [2000], R1 or READ R2,
R1
ADR [4000], [3000] [4000] = [4000] + [3000] Adds the value of address [4000] and [3000] then the result is stored at
address [4000].
Note: the parameters can be changed into R1 or R2.
DIF [4000], [3000] [4000] = [4000] - [3000] Subtracts the value of address [4000] to [3000] then the result is stored at
address [4000].
Note: the parameters can be changed into R1 or R2.
MUL R2, [2000] R2 = R2 * [2000] Multiples the value of register R2 by [2000] then the result is stored at
register R2.
Note: the parameters can be changed into R1 or R2.DIV R1, [2000] R1 = R1 / [2000] Divides the value of address R1 by [2000] then the result is stored at register
R1.
Note: the parameters can be changed into R1 or R2.
Assembly Meaning Description
READ [4000], [1000], I [4000]: [20]
[1000]: [50][20] = [50]
Reads the data in address [1000] and copies it to address
[4000] using indirect memory addressing mode.Note: The last parameter can be changed to specify the type
of addressing mode.
D Direct if direct is set, its executed the same way as the
two operand operation
I Indirect as shown in the example, the address contained
in the address of the operands will be used and the two
operand operation will occur afterwards.
O+[value] Offset when registers is used as operands the
value is fetch using the operand as base address and the value
provided as the offset address. Two operand operations
follow afterwards.
ADR [4000], [3000], I [4000]: [20]
[1000]: [50]
[20] = [20] + [50]
Adds the value of address [4000] and [3000], the result is
stored in address [4000].
Note: The last parameter can be changed to specify the type
of addressing mode.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
7/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
6
Addressing Modes:
Keep in mind that ADR, DIF, MUL, DIV shares the same series of operation but differs at mathematical
operation. All of these commands are capable of memory addressing mode similar to the READ
command. During different addressing modes, registers are not affected. Only memory addresses arealtered during the execution of instruction. An error will occur if both operands are register and an
addressing mode Offset or indirect is set. Several examples will be illustrated to show how the different
addressing modes work.
EX: ADR [40], [20], O+10
The command indicates that an offset of 10 addresses must be applied during the execution of
command. By applying the offset the command will have this equivalent two operand command:
ADR [50], [30] notice that both the operands address is increased by 10 as indicated by offset of 10.
After the offset is applied, the same procedure as two operands executes.
If the offset value was set to zero, the effect will be as if the instruction executed is a two operand direct
addressing mode operation.
Assuming address [40] contains the value 80 and address [20] contains the value 50.
[40]: 80
[20]: 50
EX: ADR [40], [20], I
This command indicates that Indirect addressing mode should be applied. Referring to the assumption
above lets say the value of address [40] is read which gives us the value 80. However, since indirect
addressing mode is indicated, we have to treat the value 80, which we read from address [40] as
another address so we will have now the address [80] to replace the first operand which is [40]. The
same will happen to address [20] since it is an address, it will be replaced by address [50] because it
holds the value 50. The same procedure as the two operands operation will occur. Thus giving us the
equivalent command of:
ADR [80], [50]
Thus we can say that a two operand command: ADR [80], [50] will do the same things as the three
operand command ADR [40], [20], I.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
8/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
7
Keep in mind that when using direct as addressing mode it will treat the command as two operands
instruction. Using the previous statements, we can conclude that using the assumed values of address
[40] and [20] above, the following commands are all equivalent instructions.
ADR [80], [50] ADR [40], [20], I ADR [80], [50], D ADR [80], [50], O+0
-
8/2/2019 Computer Architecture Project Documentation - Open Source
9/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
8
Main Memory:
The main memory was given its own class during the program simulation of the microprocessors. The
main memory served as the storage of instructions for Zero, One, Two and Three operand instructions.
It is also used to store values processed by each instruction. Zero operand is an exception, Zero operanduses stack to store and retrieve value for computations. Here is an example illustration of a portion of
the main memory:
D/I O/V OT OPR OT OPR AM AV
Address 0 1 2 3 4 5 6 7 index
0 3 2 1 5 1 1 1 0
1 2 1 1 6 1 17 0 0
2 4 9 0 0 0 0 0 0
3 0 15 0 0 0 0 0 0
4 1 5 1 1 0 0 0 0
5 0 1 0 0 0 0 0 0
Legend:
D/IDataorInstruction the value in this index determines if the contents of the address is a Zero,
One, Two or Three operand instruction or it contains data.
O/VOperationorValue the value in this index is treated differently depending on the value ofD/I. If
D/I is set to zero the number at this index is treated as a value. If the value of D/I is an instruction the
value of this index is scanned and corresponding operation is executed.
OTOperandType - the value at this index determines if the operand is a register, accumulator or an
address.
OPROperand the value at this index is treated differently based on the value of the preceding OT.
Take note that OT at index [2] is the operand type for first operand and OPR at index [3] is for first
operand as well. OT at index [4] and OPR at index [5] are for second operand.
AMAddressingMode the value determines what addressing mode is to be used. The value in this
index is usually ignored except when the value ofD/I is set to 3.
AVAddressingValue the value in this index is used only by offset addressing mode. It determines
how many address should be added to the base address.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
10/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
9
List of flags for each index of a memory address
D/I O/V OT OPR* AM
Flags Meaning Flags Meaning Flags Meaning Flags Meaning Flags Meaning
0 value 0 READ 0 Register 0 R1 0 Direct
1 one operand 1 ADR 1 Address 1 R2 1 Indirect
2 two operand 2 DIF 2 Accumulator 2 Offset
3 three operand 3 MUL
4 zero operand 4 DIV
5 COPY
6 WRITE
7 INCR
8 DECR
9 POP
10 PUSH
*if the OT is set to register, these are the possible values for OPR.
In most cases the value ofAV (Addressing value) is ignored except when the AM (addressing mode) is
set to offset.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
11/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
10
The table below will give you the assembly commands (O/V) available for each
type of microprocessor in tabular form.
The next table will show which parts of a memory address are being read by
each type of microprocessor:
* As mentioned earlier, we read the value in AV only during the offset addressing mode which is used by
three operand instructions.
Number of Operands
COMMANDS ZERO ONE TWO THREE
READ
ADR
DIF
MUL
DIV
WRITE
COPY
INCR
DECR
POPPUSH
LEGEND
Available
Unavailable
Index in a memory cell
No. of
OperandsD/I O/V OT OPR OT OPR AM AV
ZERO
ONE
TWO
THREE *
LEGEND
Being Read
Ignored during decoding
-
8/2/2019 Computer Architecture Project Documentation - Open Source
12/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
11
Constructing an instruction in the main memory:
Below is a table with the default instructions with translation to assembly code, in
the main memory. It will serve as a guide in placing your own instruction.
Address Instruction Assembly code
0 1 0 1 79 0 0 0 0 READ [79]
1 1 5 0 1 0 0 0 0 COPY R2
2 1 0 1 73 0 0 0 0 READ [73]
3 1 1 1 90 0 0 0 0 ADR [90]
4 1 2 0 1 0 0 0 0 DIF R2
5 1 1 0 1 0 0 0 0 ADR R2
6 1 4 0 1 0 0 0 0 DIV R2
7 1 7 1 78 0 0 0 0 INCR [78]
8 1 8 0 1 0 0 0 0 DECR R2
9 1 6 1 79 0 0 0 0 WRITE [79]
10 1 3 1 78 0 0 0 0 MUL [78]
11 2 0 1 69 1 79 0 0 READ [69], [79]
12 2 0 0 0 1 75 0 0 READ R1, [75]
13 2 2 0 0 1 0 0 0 READ R2, R1
14 2 0 1 78 0 0 0 0 READ [78], R1
15 2 1 1 74 1 75 0 0 ADR [74], [75]
16 2 1 0 0 1 70 0 0 ADR R1, [70]
17 2 1 0 1 0 0 0 0 ADR R2, R1
18 2 1 1 74 0 1 0 0 ADR [74], R2
19 2 2 1 74 1 75 0 0 DIF [74], [75]
20 2 2 0 0 1 70 0 0 DIF R1, [70]
21 2 2 0 1 0 0 0 0 DIF R2, R1
22 2 2 1 74 0 1 0 0 DIF [74], R2
23 2 3 1 75 1 74 0 0 MUL [75], [74]
24 2 3 0 1 1 70 0 0 MUL R2, [70]
25 2 3 0 1 0 0 0 0 MUL R2, R1
26 2 3 1 74 0 0 0 0 MUL [74], R1
27 2 4 1 75 1 74 0 0 DIV [75], [74]
28 2 4 0 1 1 70 0 0 DIV R2, [70]
29 2 4 0 1 0 0 0 0 DIV R2, R1
30 2 4 1 74 0 0 0 0 DIV [74], R1
31 3 0 1 69 1 75 0 0 READ [69], [75], D
32 3 0 1 85 1 86 1 0 READ [85], [86], I
33 3 0 1 69 1 73 2 5 READ [69], [73], O+5
-
8/2/2019 Computer Architecture Project Documentation - Open Source
13/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
12
34 3 0 0 0 1 87 1 0 READ R1, [87], I
35 3 0 0 1 1 72 2 2 READ R2, [72], O+2
36 3 0 0 1 1 69 0 0 READ R2, [69], D
37 3 0 1 90 0 0 1 0 READ [90], R1, I
38 3 0 1 73 0 0 2 4 READ [73], R1, O+4
39 3 0 1 69 0 1 0 0 READ [69], R2, D
40 3 0 0 1 0 0 0 0 READ R2, R1, D
41 3 3 1 78 1 70 0 0 MUL [78], [70], D
42 3 3 1 79 0 0 0 0 MUL [79], R1, D
43 3 3 0 0 1 72 0 0 MUL R1, [72], D
44 3 3 0 1 0 0 0 0 MUL R2, R1, D
45 3 3 1 88 1 84 1 0 MUL [88], [84], I
46 3 3 1 84 0 0 1 0 MUL [84], R1, I
47 3 3 0 1 1 80 1 0 MUL R2, [80], I
48 3 3 1 69 1 70 2 2 MUL [69], [70], O+2
49 3 3 1 74 0 0 2 2 MUL [74], R1, O+2
50 3 3 0 1 1 72 2 2 MUL R2, [72], O+2
51 3 4 1 78 1 70 0 0 DIV [78], [70], D
52 3 4 1 79 0 0 0 0 DIV [79], R1, D
53 3 4 0 0 1 72 0 0 DIV R1, [72], D
54 3 4 0 1 0 0 0 0 DIV R2, R1, D
55 3 4 1 88 1 84 1 0 DIV [88], [84], I
56 3 4 1 84 0 0 1 0 DIV [84], R1, I
57 3 4 0 1 1 82 1 0 DIV R2, [82], I
58 3 4 1 69 1 70 2 2 DIV [69], [70], O+2
59 3 4 1 74 0 0 2 2 DIV [74], R1, O+2
60 3 4 0 1 1 72 2 2 DIV R2, [72], O+2
61 4 9 0 0 0 0 0 0 POP R1
62 4 9 0 1 0 0 0 0 POP R2
63 4 2 0 0 0 0 0 0 DIF
64 4 3 0 0 0 0 0 0 MUL
65 4 8 0 0 0 0 0 0 DECR
66 4 10 0 0 0 0 0 0 PUSH R1
67 4 7 0 1 0 0 0 0 INCR
68 4 10 2 0 0 0 0 0 PUSH ACC
-
8/2/2019 Computer Architecture Project Documentation - Open Source
14/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
13
Zero operand instruction
Zero operand instructions are created in a tricky manner. Some commands use up to forth index in the
memory cell but most uses only 2 indexes. Commands such as POP and PUSH read the values up to forth
index. See the following examples:
The shaded parts are the indexes that are being read by the decoder.
4 3 0 0 0 0 0 0Sample zero operand MUL instruction
MUL
Notice that in zero operand instruction, it only considers the first two values in the index. Since the MUL
command of zero operand requires no parameter (operand) it is sufficient.
4 7 0 1 0 0 0 0Sample zero operand INCR instruction
INCR
In this zero operand instruction, it only considers the first two values in the index. The INCR command of
zero operand requires no parameter (operand). It will always increment the value at register R1
regardless of the values that follows the first two indexes.
4 10 2 0 0 0 0 0Sample zero operand PUSH instruction
PUSH ACC
In PUSH zero operand instruction, it only considers the first three values in the index. Since the PUSH
command of zero operand requires one parameter. In this case we used ACC. Another PUSH command
requires up to 4 indexes of values, in this case the PUSH command will use the value from a register
such as R1 and R2 look at another example instruction below.
4 10 0 0 0 0 0 0Sample zero operand PUSH instruction
PUSH R1
It used for indexes to decode the instruction. Since the 3 rd index will indicate that it will use register and
the forth value will indicate what register is to be used by PUSH command.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
15/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
14
4 9 0 1 0 0 0 0Sample zero operand POP instruction
POP R2
In here POP command uses a register to POP a value from stack. It will require us to use three indexes.
In this case, the form is a little odd compared to the other operands. It uses the first two indexes to
determine the number of operands and the command to be performed. The fourth index checks which
register to be used during POP.
Notice how the decoder deliberately skipped the third index. It was made like this since the POP
command will always have a register as its operand. See the command list above to review the rules in
the commands.
One operand instruction:
In one operand instruction the values that are taken in to consideration are the shaded parts.
1 0 1 79 0 0 0 0Sample one operand instruction
The first value indicates that it is a one operand instruction because of the value 1. The next value which
is 0 indicates the operation which is READ. The next value which is 1 indicates that the first operand is
an address from the memory. The value that follows it which is 79 indicates that location of the address
mentioned in the previous value. Translating it to assembly code we get:
READ [79]
The rest of the values which consist of 0, 0, 0, 0 are all ignored since this is a one operand instruction.
Any value placed in there doesnt affect the instruction.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
16/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
15
Two Operand Instructions:
2 1 1 74 0 1 0 0Sample two operand instruction
The value in the first cell which is 2 indicates it is two operand instructions. The next value 1 tells us thatit is an ADR operation. The next value 1 indicates that the first operand is an address from the main
memory. The value 74 tells us the address of the first operand. The next value which is 0 indicates that
the second operand is a register. The next value 1 says it is register R2. The rest of the value which is 0
and 0 are ignored as seen in the previous tables.
Three Operand instructions:
D/I O/V OT OPR OT OPR AM AV
Address 0 1 2 3 4 5 6 7 index
0 3 2 1 5 1 1 1 0
Using a portion of memory shown above we will translate this into assembly code and describe its
function.
Using the flags above we get the equivalent Assembly code:
DIF [5], [1], I
Description:
The instruction subtracts the value ofaddress [5] to the value of address [1] using indirect addressing
mode.
The main memory is provided with default instructions for simulation, but it is possible to alter the
memory contents to create your own assembly commands provided that the rules are followed. The
illustration above demonstrates how an instruction and a value are indistinguishable in the memory.
There is a flag (which is the value at index D/I) that determines the difference of an instruction and
value.
During memory write which is executed by the MBR, the MBR scans if the address contains either a
value or an instruction. On the event that an address contains instruction, the memory write is aborted.
For further details refer to the source code.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
17/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
16
The default main memory has address starting from 00-90. But it is possible to extend the size by adding
an array of values since the main memory is simulated by two dimensional array.
The following address are reserved for each instruction for the sake convenience but can be altered if
necessary:
00 - 10 contains One operand instructions
11- 30 contains Two operand instructions
31 60 contains Three operand instructions
61 - 68 contains Zero operand instructions.
69 79 contains values from numbers 0 10
80 90 contains addresses from 69 79
Take note that the values at 80 90 is actually used to referenced another memory address (as you can
see they point to address which contains values) but these address can also be treated as actual values.
As mentioned in the different addressing mode they can also be treated as values used for
computations.
This is the default contents of the main memory:
00| [1] [0] [1] [79] [0] [0] [0] [0]
01| [1] [5] [0] [1] [0] [0] [0] [0]
02| [1] [0] [1] [73] [0] [0] [0] [0]
03| [1] [1] [1] [90] [0] [0] [0] [0]
04| [1] [2] [0] [1] [0] [0] [0] [0]
05| [1] [1] [0] [1] [0] [0] [0] [0]
06| [1] [4] [0] [1] [0] [0] [0] [0]
07| [1] [7] [1] [78] [0] [0] [0] [0]
08| [1] [8] [0] [1] [0] [0] [0] [0]
09| [1] [6] [1] [79] [0] [0] [0] [0]
10| [1] [3] [1] [78] [0] [0] [0] [0]
11| [2] [0] [1] [69] [1] [79] [0] [0]
12| [2] [0] [0] [0] [1] [75] [0] [0]
13| [2] [0] [0] [1] [0] [0] [0] [0]
14| [2] [0] [1] [78] [0] [0] [0] [0]
15| [2] [1] [1] [74] [1] [75] [0] [0]
16| [2] [1] [0] [0] [1] [70] [0] [0]
17| [2] [1] [0] [1] [0] [0] [0] [0]
18| [2] [1] [1] [74] [0] [1] [0] [0]
19| [2] [2] [1] [74] [1] [75] [0] [0]
20| [2] [2] [0] [0] [1] [70] [0] [0]
21| [2] [2] [0] [1] [0] [0] [0] [0]
22| [2] [2] [1] [74] [0] [1] [0] [0]
23| [2] [3] [1] [75] [1] [74] [0] [0]
24| [2] [3] [0] [1] [1] [70] [0] [0]
25| [2] [3] [0] [1] [0] [0] [0] [0]
26| [2] [3] [1] [74] [0] [0] [0] [0]
27| [2] [4] [1] [75] [1] [74] [0] [0]
28| [2] [4] [0] [1] [1] [70] [0] [0]
29| [2] [4] [0] [1] [0] [0] [0] [0]
30| [2] [4] [1] [74] [0] [0] [0] [0]
31| [3] [0] [1] [69] [1] [75] [0] [0]
32| [3] [0] [1] [85] [1] [86] [1] [0]
-
8/2/2019 Computer Architecture Project Documentation - Open Source
18/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
17
33| [3] [0] [1] [69] [1] [73] [2] [5]
34| [3] [0] [0] [0] [1] [87] [1] [0]
35| [3] [0] [0] [1] [1] [72] [2] [2]
36| [3] [0] [0] [1] [1] [69] [0] [0]
37| [3] [0] [1] [90] [0] [0] [1] [0]
38| [3] [0] [1] [73] [0] [0] [2] [4]
39| [3] [0] [1] [69] [0] [1] [0] [0]
40| [3] [0] [0] [1] [0] [0] [0] [0]
41| [3] [3] [1] [78] [1] [70] [0] [0]
42| [3] [3] [1] [79] [0] [0] [0] [0]
43| [3] [3] [0] [0] [1] [72] [0] [0]
44| [3] [3] [0] [1] [0] [0] [0] [0]
45| [3] [3] [1] [88] [1] [84] [1] [0]
46| [3] [3] [1] [84] [0] [0] [1] [0]
47| [3] [3] [0] [1] [1] [80] [1] [0]
48| [3] [3] [1] [69] [1] [70] [2] [2]
49| [3] [3] [1] [74] [0] [0] [2] [2]
50| [3] [3] [0] [1] [1] [72] [2] [2]
51| [3] [4] [1] [78] [1] [70] [0] [0]
52| [3] [4] [1] [79] [0] [0] [0] [0]
53| [3] [4] [0] [0] [1] [72] [0] [0]
54| [3] [4] [0] [1] [0] [0] [0] [0]
55| [3] [4] [1] [88] [1] [84] [1] [0]
56| [3] [4] [1] [84] [0] [0] [1] [0]
57| [3] [4] [0] [1] [1] [82] [1] [0]
58| [3] [4] [1] [69] [1] [70] [2] [2]59| [3] [4] [1] [74] [0] [0] [2] [2]
60| [3] [4] [0] [1] [1] [72] [2] [2]
61| [4] [9] [0] [0] [0] [0] [0] [0]
62| [4] [9] [0] [1] [0] [0] [0] [0]
63| [4] [2] [0] [0] [0] [0] [0] [0]
64| [4] [3] [0] [0] [0] [0] [0] [0]
65| [4] [8] [0] [0] [0] [0] [0] [0]
66| [4] [10] [0] [0] [0] [0] [0] [0]
67| [4] [7] [0] [1] [0] [0] [0] [0]
68| [4] [10] [2] [0] [0] [0] [0] [0]
69| [0] [0] [0] [0] [0] [0] [0] [0]
70| [0] [1] [0] [0] [0] [0] [0] [0]
71| [0] [2] [0] [0] [0] [0] [0] [0]
72| [0] [3] [0] [0] [0] [0] [0] [0]
73| [0] [4] [0] [0] [0] [0] [0] [0]
74| [0] [5] [0] [0] [0] [0] [0] [0]
75| [0] [6] [0] [0] [0] [0] [0] [0]76| [0] [7] [0] [0] [0] [0] [0] [0]
77| [0] [8] [0] [0] [0] [0] [0] [0]
78| [0] [9] [0] [0] [0] [0] [0] [0]
79| [0] [10] [0] [0] [0] [0] [0] [0]
80| [0] [69] [0] [0] [0] [0] [0] [0]
81| [0] [70] [0] [0] [0] [0] [0] [0]
82| [0] [71] [0] [0] [0] [0] [0] [0]
83| [0] [72] [0] [0] [0] [0] [0] [0]
84| [0] [73] [0] [0] [0] [0] [0] [0]
85| [0] [74] [0] [0] [0] [0] [0] [0]
86| [0] [75] [0] [0] [0] [0] [0] [0]
87| [0] [76] [0] [0] [0] [0] [0] [0]
88| [0] [77] [0] [0] [0] [0] [0] [0]
89| [0] [78] [0] [0] [0] [0] [0] [0]
90| [0] [79] [0] [0] [0] [0] [0] [0]
-
8/2/2019 Computer Architecture Project Documentation - Open Source
19/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
18
Stack Memory:
Stack memory is a special type of memory used by zero operand instruction. Unlike the main memory
which is implemented using two dimensional arrays the stack memory was implemented using linked
list. Stack memory is dynamically expanding which means its size can change in contrast to the arraywhich cannot. POP and PUSH commands alters the size of the stack memory.
These are the default values of stack memory:
13| 24
12| 9
11| 15
10| 10
09| 9
08| 8
07| 7
06| 6
05| 5
04| 4
03| 3
02| 2
01| 1
00| 0
0 at stack address [0] being the first value inserted and 24 at stack address [13] being the last value
inserted.
Initialization of the processor components during simulation:
During the simulation, components of the microprocessors are defined in a class. Each class requires an
object to be created in order to use its functions. However, some classes require another object of a
class as parameters during construction which are defined in the constructor.
Here are the list of classes and what they do:
ACC represents the Accumulator. It serves as the storage of temporary result in ALU
ALU represents the Algorithmic Logic Unit. It handles all the mathematical computations during the
simulation.
AR (ALU register) represents a register being used by ALU as operands during mathematical
computations.
CU represents the Control Unit. It sends signals to different components of the microprocessor in order
to perform the instruction correctly. Data transfers between processor components and processing of
-
8/2/2019 Computer Architecture Project Documentation - Open Source
20/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
19
ALU are handled by this class. A decoder is included in this class which translates the instruction being
executed.
IR represents the instruction register. It holds the address of the current instruction being executed
from the main memory.
MAR represents the Memory Address Register. It holds the address of an instruction or data that needs
to be fetched from the main memory.
MBR represents the Memory Buffer Register. It holds data coming from the main memory and sends
distributes it to the other components of the microprocessor
MM or Main memory represents the storage of data and instruction.
Stack represents a stack which is used in stack operations.
Take a look at the constructors of these classes:
ALU(AR r1, AR r2, ACC acc)CU(PC pc, IR ir, MAR mar, ALU alu, MBR mbr, ACC acc, Stack stack)MBR(MM mem)
Notice that these classes take other components of the processor as its parameters. It was designed that
way to ensure that all the necessary components of processor are created before creating another
component whose task requires the presence of other component.
Let us take ALU as an example: ALU for mathematical operations requires 2 operands in the form of
registers and an ACC which is a special register to store results of computations of ALU.
Illustration ofALUs constructor
Notice that the ALU is like a piece of the puzzle, with two ends fitting to an ACC object and two AR
objects. Imagine if we created an object from ALU without creating an ACC and a method was called to
add R1 and R2 where will the resultant value go? An error would occur ifthats the case.
-
8/2/2019 Computer Architecture Project Documentation - Open Source
21/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
20
Another example is the MBR. If we created MBR without the presence of MM, the MBR wont be able to
know where to fetch the instruction being pointed out by MAR.
Illustration ofMBRs constructor
Similar to an ALU object, MBR requires yet another object which in this case is MM object before an
MBR object is created.
Now for the CU object the graphical representation of the constructor should look like this.
Illustration ofCUs constructor
-
8/2/2019 Computer Architecture Project Documentation - Open Source
22/22
CS241 Computer Architecture LEC
Tuesday 8:00am-10:00am
21
Notice that the constructor of the ALU and MBR gives the CU the connection it needs to interact with
MM, ACC and two AR. The very reason the constructors of MBR and ALU require the other components
of the process is because they are an integral part of the larger design, which in this case is the CU.
As mentioned earlier the CU provides connections between components of microprocessor, so the IR,
PC, MAR, MBR, Stack and ALU can also interact with one another because of CU.
It is also worth mentioning that the CU has another constructor which looks like this.
CU(PC pc, IR ir, MAR mar, ALU alu, MBR mbr, ACC acc)
Notice that the constructor is missing the Stack. This is actually a constructor which can operate one,
two and three Operand instructions. The constructor shown above (which includes Stack in its
parameters) is capable of handling zero, one, two and three operands.