CA Session 7 Summary - muneeb-mbytes/computerArchitectureCourse GitHub Wiki
Arithmetic and Logic Instructions in MIPS Processor Design
add
Syntax: add $d, $s, $t
Description: Adds the contents of registers $s and $t and stores the result in register $d.
Operation: $d = $s + $t
Example: add $t0, $t1, $t2 // If $t1 contains 5 and $t2 contains 10, $t0 will be set to 15.
sub
Syntax: sub $d, $s, $t
Description: Subtracts the contents of register $t from register $s and stores the result in register $d.
Operation: $d = $s - $t
Example: sub $t0, $t1, $t2 // If $t1 contains 15 and $t2 contains 5, $t0 will be set to 10.
and
Syntax: and $d, $s, $t
Description: Performs a bitwise AND operation between the contents of registers $s and $t and stores the result in register $d.
Operation: $d = $s & $t
Example: and $t0, $t1, $t2 // If $t1 contains 1010 and $t2 contains 1100, $t0 will be set to 1000
or
Syntax: or $d, $s, $t
Description: Performs a bitwise OR operation between the contents of registers $s and $t and stores the result in register $d.
Operation: $d = $s | $t
Example: or $t0, $t1, $t2 // If $t1 contains 0b1010 and $t2 contains 0b1100, $t0 will be set to 0b1110.
slt
Syntax: slt $d, $s, $t
Description: Sets register $d to 1 if the contents of register $s is less than the contents of register $t, otherwise sets $d to 0.
Operation: $d = ($s < $t) ? 1 : 0
Example: slt $t0, $t1, $t2 // If $t1 contains 5 and $t2 contains 10, $t0 will be set to 1.
Memory Reference Instructions in MIPS Processor Design:
lw
Syntax: lw $t, offset($s)
Description: Loads a word from memory at the address formed by adding the offset to the contents of register $s and stores it in register $t.
Operation: $t = Memory[$s + offset]
Example: lw $t0, 4($t1) // Loads the word from the memory address [$t1 + 4] into $t0.
sw
Syntax: sw $t, offset($s)
Description: Stores the contents of register $t into memory at the address formed by adding the offset to the contents of register $s.
Operation: Memory[$s + offset] = $t
Example: sw $t0, 4($t1) // Stores the contents of $t0 into the memory address [$t1 + 4]
Control Flow Instruction in MIPS Processor Design
beq
Syntax: beq $s, $t, label
Description: Compares the contents of registers $s and $t. If they are equal, the program counter is set to the address specified by the label (branching to that label)
Operation: if ($s == $t) PC = label
Example: beq $t0, $t1, Loop // If $t0 is equal to $t1, the program will jump to the instruction at the label Loop.
Processor design Implementation
- **Fetch (Collect):**The processor looks up the next instruction in memory using a special register called the Program Counter (PC).
For example fetched machine code is
001000 10011 01010 0000000000000100
Flow Diagram for Fetch:
- Decode (Analyze): Once the instruction is fetched, the processor figures out what operation needs to be done and what data is involved:
- Opcode (001000): This identifies the operation as addi (add immediate).
- rs (10011): This represents the source register
- rt (01010): This represents the destination register,
- immediate (0000000000000100): This is the constant value 4 in signed extension format.
Flow Diagram for Decode:
- Read Operands (Read the Opcode): The processor retrieves the data it needs to perform the operation, either from other registers or from memory
- The processor reads the value from the source register let it be $s3.
- The immediate value 4 is readily available from the instruction itself.
Flow Diagram for Read Operands:
- Execute (Run Operation): The processor performs the actual operation based on theinstruction. This could be adding numbers, comparing values, or moving data around. Here it is add immediate.
- The processor sends the value from $s3 and the immediate value 4 to the Arithmetic Logic Unit(ALU).
- The ALU performs the addition: value in $s3 + 4.
Flow Diagram for Execute:
Datapath and Controller
Datapath:
- This is the hardware responsible for performing all the required operations.
- It includes components such as the Arithmetic Logic Unit (ALU), registers, and internal buses.
- The datapath executes the actual data processing tasks, performing computations and data transfers.
Controller:
This component manages the operations of the datapath by providing necessary instructions based on the executing program. It handles tasks such as switching, operation selection, and coordinating data movement between ALU components and other parts of the datapath.
Communication Between Datapath and Controller
The interaction between the datapath and the controller involves two types of signals:
Control Signals:
- These are sent from the controller to the datapath. They direct the datapath on what operations to perform, which operations to select, and how to move data between different components.
Status Signals:
- These are sent from the datapath back to the controller. Status signals provide feedback to the controller about the current state of the datapath. This information helps the controller make informed decisions about subsequent actions.
Building Blocks in Processor Design:
The fundamental units work together to execute instructions, manage data flow, and control the operation of the processor. These building blocks can be broadly categorized into two types:
- Combinational elements
- Sequential elements.
Combinational Circuits:
A combinational circuit is an electronic circuit in which the output depends on the present combination of inputs. Combinational circuits are used in digital electronics, such as computers, to perform operations on data. Examples are all the gates, multiplexers, decoders, ALU, array multipliers, Half adder, Full Adder, Parallel binary adder, Subtractor.
Sequential Circuits:
Sequential circuits are digital circuits that store and use the previous state information to determine their next state. Sequential circuits depend on the current inputs as well as the prior state that is stored in memory components, in contrast to combinational circuits, which solely depend on the current input values to produce outputs. Examples are flip flops, counters, registers, register files, memories.
Clocked vs Unclocked Sequential Circuits:
Synchronous(Clocked) circuits:
- Digital circuits that use clock signals to determine operation timing.
- State changes only on the rising or falling edge of the clock signal.
- Output determined by current inputs and previous state stored in flip-flops.
- Essential component in digital systems design.
A synchronous D flip-flop stores the data input (D) only when the clock signal (CLK) changes. This makes the output (Q) change in sync with the clock, providing stable and predictable operation. It is commonly used in digital systems for data storage, shift registers, and counters because it ensures data changes happen in a controlled way.
Asynchronous(Unclocked) circuits:
Asynchronous circuits, also known as un-clocked circuits, are digital circuits that do not depend on a clock signal to coordinate or synchronize the timing of their operations.
- An asynchronous D flip-flop can change its state anytime, not just with the clock signal. It has additional inputs like preset (PRE) and clear (CLR) to set or reset the output (Q) immediately.
- This is useful for instant responses, such as resetting a circuit, because it can change unpredictably, it requires careful design to avoid timing issues.
Clock and Timings
Consider two flip flops connected in series. There is combinational logic between two flip flops, which is consisting of some delay. Ideally data is read by first flipflop at first positive edge, then transferred to second at second edge. Now depending upon what delay the combinational circuit have the output at the second edge is determined. So, depending upon the delay we can have faster clock or slower clock or given a clock we can have a constraint on combinational circuit delay. Therefore, this is the clock and timing relationship
- D signal should be stable some time before active edge of the clock this time is called the set up time .
- D signal should be stable some time after active edge of the clock this time is called the hold time .
- If this requirement are violated it can take previous or next value this may lead to metastablity condition.
Components in Processor Design:
Program Counter (PC):
- Role: The Program Counter keeps track of the address of the next instruction tobe executed.
- Action: It sends the address to the Instruction Memory.
Instruction Memory:
- Role: This memory holds the instructions that the CPU needs to execute.
- Action: Once it receives the address from the Program Counter, it fetches the instruction stored at that address and sends it to the Register (Reg).
Reg (Registers):
- Role: Registers are small storage locations within the CPU used to quickly access data and instructions.
- Action: It receives the instruction from the Instruction Memory. Depending on the instruction, it either sends data to the Arithmetic Logic Unit (ALU) or directly to the Data Memory.
ALU (Arithmetic Logic Unit):
- Role: The ALU performs arithmetic and logical operations.
- Action: When it receives data from the Registers, it processes the data (e.g.,performs a calculation) and then sends the result back to the Registers.
Data Memory:
- Role: This memory holds the data that the CPU needs to process or has processed.
- Action: Data can be sent to and from the Registers. For example, an instructionmight tell the CPU to load data from Data Memory to a Register or store data from a Register into Data Memory