/SUBLEQ_Processor

This repository contains the Verilog code for a basic SUBLEQ processor

Primary LanguageVerilog

SUBLEQ Processor

This repository contains the Verilog code for a basic SUBLEQ processor, as well as some supporting modules. The SUBLEQ (Subtract and branch if Less-than or Equal to Zero) instruction set is a simple, one-instruction set architecture (OISA) that performs the subtraction of two operands, and branches to a specified address if the result is less than or equal to zero.

File Descriptions

  • CU_microcode.mem: This file contains the microcode for the Control Unit (CU) of the SUBLEQ processor. It defines the sequence of operations that the processor should execute for each instruction.

  • buffer_block_v01.v: This file contains the code for a simple buffer module that can be used to temporarily block or unblock data.

  • data_register_v01.v: This file contains the code for a basic data register module that can be used to store and retrieve data.

  • counter_register_v01.v: This file contains the code for a counter register module that can be used to store and increment/decrement a value.

  • subtractor_block_v01.v: This file contains the code for a subtractor module that can be used to perform subtraction between two operands.

  • SUBLEQ_v01.v: This is the main SUBLEQ processor module, which combines the CU, data registers, counter registers, and subtractor module to execute the SUBLEQ instruction set.

How the SUBLEQ Processor Works

The SUBLEQ processor consists of a Control Unit (CU), data registers, counter registers, and a subtractor module. The CU controls the flow of data and operations within the processor using a microcode stored in the CU_microcode.mem file.

The data registers (implemented in data_register_v01.v) are used to store operands for the SUBLEQ instruction. There are two data registers, referred to as DATA_REG_A and DATA_REG_B, which can be loaded with values from memory or other sources.

The counter registers (implemented in counter_register_v01.v) are used to store a counter value and can be incremented or decremented as needed. There is one counter register, referred to as the Program Counter (PC), which is used to store the address of the next instruction to be executed.

The subtractor module (implemented in subtractor_block_v01.v) performs the subtraction of DATA_REG_A and DATA_REG_B, and sets a flag (LEQ_FLAG) to 1 if the result is less than or equal to zero.

The CU uses the microcode to control the flow of data and operations within the processor, including loading values into the data and counter registers, performing the subtraction operation, and branching to a new instruction based on the value of the LEQ_FLAG.

How to use

To use the SUBLEQ processor, you will need to load the instructions and data into memory. The instructions are in the form of the SUBLEQ(A,B,C) instruction, where A, B, and C are addresses in memory. The instruction should be stored in memory as follows:

  • memory[x] = address_of_B
  • memory[x+1] = address_of_A
  • memory[x+2] = address_C

The SUBLEQ instruction will perform the following operations:

  1. Subtract the value stored at address B from the value stored at address A.
  2. If the result of the subtraction is less than or equal to zero, branch to the address specified in C.
  3. If the result is greater than zero, increment the instruction pointer (PC) and continue execution with the next instruction.