How to execute a 11-digit instruction using different addressing modes in Python?
Here, we have an 11 bit instruction which has first 2 bits for representing addressing mode, next 3 bits for the opcode and the last 6 bits are for the two operands, 3 bits each.
We will execute this 11 bit Instruction using four different addressing modes:-
- Direct mode: In this mode, the addresses of two operands are specified in the instruction. We can receive the actual data directly from the memory addresses.
- Indirect mode: In this mode, the addresses mentioned in the instruction are point to the effective addresses of the operands.
- Immediate mode: In this mode, the actual data is mentioned in the instruction itself.
- Register mode: In this mode, the instruction contains the addresses of the registers which contain the actual data.
We will use the first 2 bits for representing the four different addressing modes in this way:
For direct mode- 00 For indirect mode- 01 For immediate mode- 10 For register mode- 11
Next 3 bits are for representing opcode, so we can use 8 different operations maximum. We will define 6 operations and the other two will be reserve for future in this way:
000- Do nothing 001- Addition 010- Subtraction 011- Multiplication 100-Division 101-Transfer operand2 to operand1 110-Reserve for future 111-Reserve for future
The next 3 bits are for operand1 and the last 3 bits are for operand2, so the values of operands will be ranging from 0 to 7 in immediate mode.
For the direct, indirect and register mode we need to define a memory array and a register array. As we have only 3 bits for representing the addresses so the maximum number of elements in these arrays will be 8.
Here, the memory contains 8 data and the register contain 4 data. The concept discussed above will work in the following way:
Here, from left to right
Mode-01- Indirect mode
Operand2 – 100- 4
As it is the indirect mode, so these operands gives the addresses of the effective address of the data.
Means, the effective addresses are present in the memory location 0 and 4 , which are 2 and 7.
And the actual data is present in the memory location 2 and 7 which are 40 and 19.
So, the result will be the addition of 40 and 19.
Instruction mode: 00 Opcode: 001 operand1: 000 operand2: 001 RESULT 17 Instruction mode: 01 Opcode: 001 operand1: 000 operand2: 100 RESULT 59 Instruction mode: 10 Opcode: 001 operand1: 000 operand2: 001 RESULT 1 Instruction mode: 11 Opcode: 001 operand1: 000 operand2: 001 RESULT 37