代写CS 211: Assignment 4 Building a Simple Processor in CircuitVerse代做Statistics统计

CS 211: Assignment 4

Building a Simple Processor in CircuitVerse

Introduction

This project guides you through the step-by-step construction of a simplified processor ar- chitecture inspired by the MIPS instruction set.  Unlike the complex and variable-length instructions of the x86 architecture (which we study in class), this processor follows a clean, RISC-style (Reduced Instruction Set Computer) design.

Key Features of This Design:

Fixed-length 16-bit instructions for predictable decoding.

Three instruction formats: R-type (register), I-type (immediate), and J-type (jump).

4-bit general-purpose registers for simplicity.

Stepwise development over three phases: starting with basic arithmetic and grad- ually adding control flow and branching.

Modular structure: built using subcircuits for ALU, Control Unit, Register File, and Program Counter.

This processor is intentionally simplified to reinforce fundamental processor concepts:  in- struction decoding, ALU operation, register file management, branching, and memory ac- cess. It mirrors the design philosophy of MIPS — a classic teaching architecture — but uses a smaller data width (4-bit registers and immediates) and a compact instruction memory.

Comparison with x86:

x86: CISC  (Complex Instruction  Set Computing) architecture, variable-length in- structions, many addressing modes.

This Project: RISC-style, fixed-length instructions, clean control flow, ideal for learn- ing core concepts.

Please use the pdf about MIPS single cycle implementation for reference.

Phase 1: Building an R-Type Instruction Processor

Objective

In this phase, we will design and implement a processor capable of executing basic R-type in- structions using a custom 16-bit instruction format.  The processor will follow the Fetch–De- code–Execute model and be built in CircuitVerse.

Instruction Format

R-type instructions are 16 bits wide and operate entirely on register operands.  The instruc- tion is broken down as follows:

Bits

Field

Description

Width

15–12

Opcode

Operation type (ADD, SUB, etc.)

4 bits

11–8

Rd

Destination register

4 bits

7–4

Rs1

Source register 1

4 bits

3–0

Rs2

Source register 2

4 bits

Example: ADD R0, R1, R2 → Rd  =  R0,  Rs1  =  R1,  Rs2  =  R2 Supported Instructions (Phase 1)

Opcode (bin)

Mnemonic

Operation

0000

ADD

Rd Rs1 + Rs2

0001

SUB

Rd Rs1 - Rs2

0010

AND

Rd Rs1 AND Rs2

0011

OR

Rd Rs1 OR Rs2

0100

SLT

Rd (Rs1 < Rs2) ?  1 :  0

Processor Design:  Fetch—Decode—Execute Cycle

1. Fetch:

•  The Program Counter (PC) outputs a 4-bit address.

•  This address is used to retrieve the 16-bit instruction from Instruction Memory (RAM).

2. Decode:

• A 16-bit splitter breaks the instruction into Opcode, Rd, Rs1, and Rs2 fields.

•  These fields are routed to the Control Unit and Register File.

3. Execute:

• Values from Rs1 and Rs2 are fetched from the register file.

•  The ALU performs the operation as specified by the Opcode.

•  The result is written back to Rd.

•  The PC is incremented to fetch the next instruction.

Implementation Steps in CircuitVerse

Step 1. Instruction Memory (ROM)

•  Use a 16x16-bit RAM or ROM block.

• 4-bit address input comes from the PC.

•  Outputs a 16-bit instruction.

Step 2. Program Counter (PC)

• 4-bit register to store the current instruction address.

•  Connect to a 4-bit adder that increments the PC by 1 each clock cycle.

• Add a clock and reset input.

Step 3. Instruction Decoder

•  Use a 16-bit splitter.

•  Output 4-bit signals for Opcode, Rd, Rs1, and Rs2.

Step 4. Register File (4 registers: R0—R3)

•  Create 4 registers, each 4 bits wide.

•  Use two 2:4 decoders to select Rs1 and Rs2 (read ports).

•  Use 4:1 multiplexers to read from Rs1 and Rs2.

• Another 2:4 decoder selects Rd (write port) for writing the result.

• Add write-enable logic from the Control Unit.

Step 5. Arithmetic Logic Unit (ALU)

•  Inputs: Rs1 and Rs2 values.

•  Output: Result sent to Rd.

•  Operation is selected using the 4-bit Opcode.

•  Support ADD, SUB, AND, OR, and SLT.

Step 6. Control Unit (Combinational Logic)

•  Input: 4-bit Opcode.

•  Outputs:

ALU control signals.

Register file write-enable signal.

•  Implement using logic gates or multiplexers.

Step 7. Main Processor Circuit

•  Integrate PC, RAM, Decoder, Register File, ALU, and Control Unit.

•  Ensure all components are correctly synchronized using the system clock.

•  Use output pins or LEDs to visualize register contents and ALU output.

Test Program (RAM Contents)

Instruction

Binary Description

LOADI  R1, 3

0110 0001 0000 0011 (Preset value in register)

LOADI  R2, 5

0110 0010 0000 0101 (Preset value in register)

ADD  R0, R1, R2

0000  0000 0001 0010 R0 = R1 + R2

SUB  R3, R2, R1

0001  0011 0010 0001 R3 =  R2 - R1

AND  R0, R1, R2

0010  0000 0001 0010       R0  =  R1 AND R2

SLT  R1, R1, R2

0100  0001  0001 0010 R1 =   (R1 < R2) ?   1   : 0

Expected Behavior

•  The PC should increment automatically every cycle.

• ALU should perform the correct operation according to the Opcode.

•  The result of each instruction should be written to the Rd register.

• All register updates should reflect the expected instruction behavior.

Checklist Before Proceeding to Phase 2

R-type instructions load and execute correctly from RAM.

ALU performs correct operations for ADD, SUB, AND, OR, SLT.

PC increments properly each clock cycle.

Write-back to Rd is functional.

Test outputs match expected behavior.

Phase 2: Adding I-Type Instruction Support

Overview

Phase 2 extends the processor developed in Phase 1 to support I-type instructions.  Unlike R-type instructions, which use two register operands, I-type instructions use a constant 4-bit immediate value in place of the second operand. These instructions enable:

•  Loading constants into registers.

•  Performing arithmetic using an immediate value.

•  Implementing simple conditional branching (control flow).

I-Type Instruction Format

Bits

Field

Description

Width

15–12

11–8

7–4

3–0

Opcode

Rd or Rs

Rs or

Imm4

Operation code (e.g., LOADI)

Register used for destination (LOADI, ADDI) or condition (BEQZ, BNEZ)

Optional source register (used in ADDI only)

4-bit unsigned immediate constant

4 bits

4 bits

4 bits

4 bits

Note: Rs is only relevant for ADDI, BEQZ, and BNEZ. It is ignored for LOADI.

Supported I-Type Instructions

Opcode (Binary)

Mnemonic

Operation

0110

LOADI

Rd Imm4

0111

ADDI

Rd Rs + Imm4

1000

BEQZ

If (Rs == 0) then PC PC + Imm4

1001

BNEZ

If (Rs 0) then PC PC + Imm4

Processor Modifications for I-Type Support

To implement I-type instruction functionality, the following hardware changes and enhance- ments are required:

Step 1. Immediate Extractor

•  Extend the instruction decoder to extract bits 3–0 (Imm4).

•  Route this 4-bit immediate to a new input line on the ALU-side MUX.

•  Label clearly to avoid confusion with Rs2.

Step 2. ALU Input B Multiplexer (ALUSrc)

•  Insert a 2:1 multiplexer before ALU input B.

•  Input 0: Rs2 value (for R-type instructions).

•  Input 1: Imm4 value (for I-type instructions).

•  Controlled by a new signal: ALUSrc.

•  ALUSrc  =  0 → R-type; ALUSrc  =  1 → I-type.

Step 3. Update Control Unit

•  Recognize new opcodes:   LOADI  (0110),  ADDI  (0111),  BEQZ  (1000),  BNEZ (1001).

•  For each I-type opcode, generate appropriate control signals:

ALUSrc  =  1 for LOADI and ADDI.

RegWrite  =  1 for LOADI and ADDI.

RegWrite  =  0 for BEQZ and BNEZ.

Branch  =  1 only for BEQZ and BNEZ.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图