Documente Academic
Documente Profesional
Documente Cultură
Rating
Submitted by: Leandro M. Santos Rodel R. Aguinaldo Nieljun Acebes John Ethelbert Terrado Gerard Kristoffer C. Sabado Submitted to: Prof. Gaucho Agregado
Table of Contents
Zero Operand Microprocessor (Cipher) One Operand Microprocessor (Primo) Notes on one operand instructions Two Operand Microprocessor (Ritornare) Three Operand Microprocessor (Ciel) Addressing Modes Main Memory Constructing an instruction in the main memory: Stack Memory Initialization of the processor components during simulation Source Codes ACC ALU AR CU IR MAR MBR MM PC Stack Cipher Primo Ritornare Ciel UML Class Diagrams 2 3 4 5 5 6 8 11 18 18 22 23 23 25 26 49 50 51 52 55 56 57 58 59 60 63
Assembly POP R1
PUSH R1
Stack[top element] = R1
Description Takes the top most element of the stack and sends it to the register R1.Stack pointer is then decremented by 1. Note: R1 may be replaced by any register such as R2. 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. Adds the value of R1 and R2 and sends it to Accumulator Subtracts the value of R1 to R2 and sends it to Accumulator Multiplies the value of R1 and R2 and sends it to Accumulator Divides the value of R1 to R2 and sends it to Accumulator Increments the value at register R1 and sends it to Accumulator Decrements the value at register R1 and sends it to Accumulator
Meaning R1 = [2000] R1 = R2
[2000] = ACC ACC = R1 + R2 [4000] = ACC ACC = R1 + R2 [4000] = ACC ACC = R1 * R2 [4000] = ACC ACC = R1 / R2 [4000] = ACC ACC = R1 + 1 R1 = ACC ACC = R1 - 1 R1 =ACC
Description Reads the data in address [2000] and copies it to register R1. 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. 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 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 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 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 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 Increments the value of register R1 by 1. R1 can be changed in to R2 or an address from the main memory. Decrements the value of register R1 by 1. R1 can be changed in to R2 or an address from the main memory.
R2 = R2 * [2000]
R1 = R1 / [2000]
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 are altered 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.
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
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 operand uses stack to store and retrieve value for computations. Here is an example illustration of a portion of the main memory: D/I 0 3 2 4 0 1 0 O/V 1 2 1 9 15 5 1 OT 2 1 1 0 0 1 0 OPR 3 5 6 0 0 1 0 OT 4 1 1 0 0 0 0 OPR 5 1 17 0 0 0 0 AM 6 1 0 0 0 0 0 AV 7 0 0 0 0 0 0
Address 0 1 2 3 4 5
index
Legend:
D/I Data or Instruction 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/V Operation or Value the value in this index is treated differently depending on the value of D/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. OT Operand Type - the value at this index determines if the operand is a register, accumulator or an address. OPR Operand 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. AM Addressing Mode the value determines what addressing mode is to be used. The value in this index is usually ignored except when the value of D/I is set to 3. AV Addressing Value the value in this index is used only by offset addressing mode. It determines how many address should be added to the base address.
*if the OT is set to register, these are the possible values for OPR. In most cases the value of AV (Addressing value) is ignored except when the AM (addressing mode) is set to offset.
The table below will give you the assembly commands (O/V) available for each type of microprocessor in tabular form.
COMMANDS READ ADR DIF MUL DIV WRITE COPY INCR DECR POP PUSH LEGEND Available Unavailable Number of Operands ZERO ONE TWO THREE
The next table will show which parts of a memory address are being read by each type of microprocessor:
Index in a memory cell No. of Operands ZERO ONE TWO THREE D/I O/V OT OPR OT OPR AM AV
LEGEND Being Read Ignored during decoding * As mentioned earlier, we read the value in AV only during the offset addressing mode which is used by three operand instructions.
10
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 4 9 4 9 4 2 4 3 4 8 4 10 4 7 4 10
0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 2
0 1 1 90 73 69 1 78 79 0 1 88 84 1 69 74 1 78 79 0 1 88 84 1 69 74 1 0 1 0 0 0 0 1 0
1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 0 1 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0
87 72 69 0 0 1 0 70 0 72 0 84 0 80 70 0 72 70 0 72 0 84 0 82 70 0 72 0 0 0 0 0 0 0 0
1 2 0 1 2 0 0 0 0 0 0 1 1 1 2 2 2 0 0 0 0 1 1 1 2 2 2 0 0 0 0 0 0 0 0
0 2 0 0 4 0 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0
READ R1, [87], I READ R2, [72], O+2 READ R2, [69], D READ [90], R1, I READ [73], R1, O+4 READ [69], R2, D READ R2, R1, D MUL [78], [70], D MUL [79], R1, D MUL R1, [72], D MUL R2, R1, D MUL [88], [84], I MUL [84], R1, I MUL R2, [80], I MUL [69], [70], O+2 MUL [74], R1, O+2 MUL R2, [72], O+2 DIV [78], [70], D DIV [79], R1, D DIV R1, [72], D DIV R2, R1, D DIV [88], [84], I DIV [84], R1, I DIV R2, [82], I DIV [69], [70], O+2 DIV [74], R1, O+2 DIV R2, [72], O+2 POP R1 POP R2 DIF MUL DECR PUSH R1 INCR PUSH ACC
12
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 0
Sample 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 0
Sample 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 0
Sample zero operand PUSH instruction
PUSH R1 It used for indexes to decode the instruction. Since the 3rd index will indicate that it will use register and the forth value will indicate what register is to be used by PUSH command.
13
4 9 0 1 0 0 0 0
Sample 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.
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.
14
The value in the first cell which is 2 indicates it is two operand instructions. The next value 1 tells us that it 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.
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 of address [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.
15
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| 01| 02| 03| 04| 05| 06| 07| 08| 09| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [2] [3] [3] [0] [5] [0] [1] [2] [1] [4] [7] [8] [6] [3] [0] [0] [0] [0] [1] [1] [1] [1] [2] [2] [2] [2] [3] [3] [3] [3] [4] [4] [4] [4] [0] [0] [1] [0] [1] [1] [0] [0] [0] [1] [0] [1] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [1] [79] [1] [73] [90] [1] [1] [1] [78] [1] [79] [78] [69] [0] [1] [78] [74] [0] [1] [74] [74] [0] [1] [74] [75] [1] [1] [74] [75] [1] [1] [74] [69] [85] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [1] [1] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [79] [75] [0] [0] [75] [70] [0] [1] [75] [70] [0] [1] [74] [70] [0] [0] [74] [70] [0] [0] [75] [86] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [1] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
16
33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| 83| 84| 85| 86| 87| 88| 89| 90|
[3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [4] [4] [4] [4] [4] [4] [4] [4] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
[0] [0] [0] [0] [0] [0] [0] [0] [3] [3] [3] [3] [3] [3] [3] [3] [3] [3] [4] [4] [4] [4] [4] [4] [4] [4] [4] [4] [9] [9] [2] [3] [8] [10] [7] [10] [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78] [79]
[1] [0] [0] [0] [1] [1] [1] [0] [1] [1] [0] [0] [1] [1] [0] [1] [1] [0] [1] [1] [0] [0] [1] [1] [0] [1] [1] [0] [0] [0] [0] [0] [0] [0] [0] [2] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
[69] [0] [1] [1] [90] [73] [69] [1] [78] [79] [0] [1] [88] [84] [1] [69] [74] [1] [78] [79] [0] [1] [88] [84] [1] [69] [74] [1] [0] [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
[1] [1] [1] [1] [0] [0] [0] [0] [1] [0] [1] [0] [1] [0] [1] [1] [0] [1] [1] [0] [1] [0] [1] [0] [1] [1] [0] [1] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
[73] [87] [72] [69] [0] [0] [1] [0] [70] [0] [72] [0] [84] [0] [80] [70] [0] [72] [70] [0] [72] [0] [84] [0] [82] [70] [0] [72] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
[2] [1] [2] [0] [1] [2] [0] [0] [0] [0] [0] [0] [1] [1] [1] [2] [2] [2] [0] [0] [0] [0] [1] [1] [1] [2] [2] [2] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
[5] [0] [2] [0] [0] [4] [0] [0] [0] [0] [0] [0] [0] [0] [0] [2] [2] [2] [0] [0] [0] [0] [0] [0] [0] [2] [2] [2] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
17
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 array which cannot. POP and PUSH commands alters the size of the stack memory.
0 at stack address [0] being the first value inserted and 24 at stack address [13] being the last value inserted.
18
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.
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 if thats the case.
19
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.
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.
20
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.
21