Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:02:36+00:00 2026-06-12T22:02:36+00:00

Here is my problem: I need to design a 16 bit left/right logical/arithmetic shift

  • 0

Here is my problem: I need to design a 16 bit left/right logical/arithmetic shift component using combinational logic from scratch (except using std_logic_vector and std_logic).

Here is what I have:

library ieee;
use ieee.std_logic_1164.all;

entity Shift16 is
    port
    (
        -- Input ports
        I       : in std_logic_vector(15 downto 0);
        Shift   : in std_logic_vector(3 downto 0);

        -- Sel(1) == 0 -> Logical ; Sel(0) == Left
        Sel : in std_logic_vector(1 downto 0);

        -- Output ports
        O       : out std_logic_vector(15 downto 0)
    );
end Shift16;

architecture Struct of Shift16 is
component Mux16to1 is
    port (I :   in std_logic_vector(15 downto 0);
            S   :   in std_logic_vector(3 downto 0);
            O   :   out std_logic);
end component;

component Mux2to1_16 is
    port
    ( A, B : in  std_logic_vector(15 downto 0); S : in  std_logic;
      Q : out std_logic_vector(15 downto 0) );
end component;

signal OLeft, ORight : std_logic_vector(15 downto 0);

signal PadVal   : std_logic;

type gen_signal is array (15 downto 0) of std_logic_vector(15 downto 0);

signal leftPad, rightPad : gen_signal;

begin

    process (I, Sel)
    begin
        if (Sel(0) = '0') then -- logical
            PadVal <= '0';
        else 
            PadVal <= I(15); -- aritmetic
        end if;

        for j in 15 downto 0 loop
            for k in j downto 0 loop
                leftPad(j, k) <= I(15-j);
                rightPad(j, k) <= PadVal;
            end loop;

            for k in 15 downto j+1 loop 
                leftPad(j, k) <= PadVal;
                rightPad(j, k) <= I(15-j);
            end loop;
        end loop;
    end process;



    muxarr_left_shift: for index in 15 downto 0 generate
    begin  
        mux: Mux16to1 port map (leftPad(index), Shift, OLeft(index));
    end generate;

    muxarr_right_shift: for index in 15 downto 0 generate
    begin
        mux: Mux16to1 port map (rightPad(index), Shift, ORight(index));
    end generate;   

    OutputMux: Mux2to1_16 port map (ORight, OLeft, Sel(1), O);

end Struct;

The Mux components are exactly what they seem like, just my custom version.

My original idea was to use 16 16-to-1 Muxs and wire them up so the shift amount is the select on each one. This would be very fast, but for some reason the code does not compile.

I think I also over complicated this and I am not sure what I can do to do better..

The compiling error is: Error (10382): VHDL error at Shl16.vhd(52): index of object of array type gen_signal must have 1 dimensions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:02:38+00:00Added an answer on June 12, 2026 at 10:02 pm

    I think you should change:

        for j in 15 downto 0 loop
            for k in j downto 0 loop
                leftPad(j, k) <= I(15-j);
                rightPad(j, k) <= PadVal;
            end loop;
    
            for k in 15 downto j+1 loop 
                leftPad(j, k) <= PadVal;
                rightPad(j, k) <= I(15-j);
            end loop;
        end loop;
    

    to

        for j in 15 downto 0 loop
            for k in j downto 0 loop
                leftPad(j)(k) <= I(15-j);
                rightPad(j)(k) <= PadVal;
            end loop;
    
            for k in 15 downto j+1 loop
                leftPad(j)(k) <= PadVal;
                rightPad(j)(k) <= I(15-j);
            end loop;
        end loop;
    

    because your type declaration.

    type gen_signal is array (15 downto 0) of std_logic_vector(15 downto 0);
    

    P/s: If you wanna keep assignment in loop, please change type to :

    type gen_signal is array (15 downto 0, 15 downto 0) of std_logic;
    

    But i don’t think it’s suitable for your portmap. So,you should use above method. I checked first method with Questasim 10.0b.

    P/S (again): I read carefully your code and found:

    process (I, Sel)
    

    Sensitive list may not suitable for loop except you wanna latch. I think you should split to 2 process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem... For school project I need to write parallel application using
I need a little push in the right direction. Here's my problem: I have
My problem : I need to create draggable widgets (here it's a jslider for
I have a slightly complex problem here. I need to show to the client
Here's the problem, I need to validate the form before submitting in the next
I have an interesting SQL problem that I need help with. Here is the
I need help with CMD scripts. Here is my problem: I have list of
Ok, so here's the problem I have to solve. I need to write a
Well i need some help here i don't know how to solve this problem.
This is my first post here. I have a problem. I need to take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.