Adding Load and Store Instruction - muneeb-mbytes/computerArchitectureCourse GitHub Wiki
Load and Store Instructions:
This instruction has I format:
The op field is used to identify the type of instruction.
• The rs field is the source register.
• The rt field is either the source or destination register, depending on the instruction.
• The immed field is zero-extended if it is a logical operation. Otherwise, it is signextended.
Load Instruction:
In a load instruction, data is retrieved from memory and stored in a register specified by the instruction. The calculated memory address is used to fetch data from memory.
lw $rt, immed($rs)
Store Instruction:
In a store instruction, data from a register specified by the instruction is stored in memory. The calculated memory address is used to determine where the data should be stored in memory.
sw $rt, immed($rs)
Example: lw $s0, 24($t3)
-
The memory address is computed by sign-extending the 16-bit immediate to 32-bits, which is added to the contents of $rs.
-
In lw, $rt represents the register that will be assigned the memory value. In sw, $rt represents the register whose value will be stored in memory.
Adding "lw" instruction
The additional thing that is needed to do for load word is to take the data from data memory and put it back in register file at appropriate address. First of all, line going to wd write data of the register file will be broken and made as output of a multiplexer.
Here the two options which one will be coming from input ad and the output rd which are given as inputs to a multiplexer. So this multiplexer when you give control as 1 then it will send this to the register file and when the control is 0 it sends this to the register file so it will resemble that for add, subtract, AND, OR instructions the control has to be 0 and for load instruction control has to be 1.
The second part of the picture is to give the correct write address. See, for add/subtract instruction write address is coming from the bit number 11 to 15 and for this it will come from bit number 16 to 20, for load instruction it is rt which is to be used here. For add subtract it is the rd which decides the right destination now it is rt which will do it.
So again changes have to me made here by introducing a multiplexer because it is either bit 11 to 15 which goes there or bit number 16 to 20 which goes there. The choice from bit 16 t0 20 which will be taken for load instruction, and the choice from 11 to 15 which is taken for add, subtract, AND, OR, slt instructions.
Adding "sw" instruction
- INS-INSTRUCTION MEMORY(Single Port)
- DM-DATA MEMORY(Single Port)
- ALU-Arithmetic Logic Unit(for load and store instruction)
- SX-Sign Extension
- The ALU receives inputs from various sources, including the register file and immediate values from instructions.
- For address calculation, a multiplexer is used to select between the register file output (for R-class instructions) and the sign-extended immediate value from the instruction (for load/store instructions).
- Before passing the immediate value to the ALU for address calculation, it undergoes sign extension to ensure it's treated as a signed value, extending the sign bit to fill the 32-bit output.
- Multiplexers are used to select the appropriate input paths based on the instruction type. For load/store instructions, the multiplexer selects the immediate value path, while for add/subtract instructions, it selects the register file output.
- The controller is responsible for controlling the multiplexers to ensure the correct data paths are selected based on the instruction being executed.
- Data from the register file needs to be connected to the data input of the memory component, typically for store operations. This data comes from the register specified by the instruction's third field (rt), and it's already available for connection.
- Once all connections are properly made and controlled by the controller, the datapath ensures that the correct operations are performed based on the instruction being executed.