【问题标题】:Build a full adder using 2 4:2:1 MUXes and the constants 0 and 1使用 2 个 4:2:1 MUX 和常数 0 和 1 构建一个全加器
【发布时间】:2011-03-10 16:15:33
【问题描述】:

计算机结构中的一道题,

使用 2 个 4:2:1 MUX 和常量 0 和 1 构建一个全加器。使用最少数量的常量。

显然这个问题也可以使用非门解决,但我对没有它们的问题感兴趣。

【问题讨论】:

  • 4:2:1 多路复用器是指具有四个输入、两个控制位和一个输出的东西吗?
  • 是的,4 个输入,2 个控制和 1 个输出。
  • 你确定你不能使用NOT门吗?
  • @Vadiklk - 投诉结果如何?

标签: computer-architecture


【解决方案1】:

如果您的意思是四输入多路复用器,您可以这样做(添加 abc):

carry = mux(/* controls */ a, b, /* inputs */ 0, c, c, 1);

如果没有其他门,我不确定如何获得sum。一种选择是(使用 AND 和 OR):

sum = mux(/* controls */ carry, a, /* inputs */ b|c, 0, 1, b&c);

使用 XOR(可能很明显):

sum = mux(/* controls */ a, b^c, /* inputs */ 0, 1, 1, 0);

下面是为什么你不能用两个多路复用器来做的草图:

由于您有两个多路复用器和两个输出,因此每个多路复用器必须产生一个输出;因此,您需要从carry 计算sum 或从sum 计算carry。没有非门,你不能只用三个输入计算sum,所以你需要先计算carry。你可以这样做;那么你需要从输入中获得sumcarry。由于输入是对称的,sum 的多路复用器可以将其控件设置为两个输入或一个输入和carry。第一种情况失败的原因与您无法首先计算 sum 的原因相同。查看真值表以及carry 和一个输入(称为a)的所有可能组合,对于carrya 仅使用相同的情况,无法唯一计算sum一个变量或常量作为sum mux 的每个数据输入的输入。

【讨论】:

  • 感谢您的尝试,但我可以只使用 2 个 MUX 来完成其中任何一个,但这正是问题所在。我需要更多 MUX 还是不需要门。
  • 查看最新编辑;我想我基本上记下了所有的组合。
  • 基本上你是说不可能?
  • @Vadiklk:我认为是这样,至少只有两个多路复用器,没有其他门。但是,对于测试,您可能想记下您可以做的事情(carry 使用一个多路复用器,sum 使用两个多路复用器或一个多路复用器和其他一些门)以获得至少部分功劳。
  • 谢谢,我 99% 确定这是不可能的,只是想确定一下。
【解决方案2】:

我刚刚编写了一个简单的小 C# 程序来检查每个可能的输入组合,但它无法找到解决方案。所以,除非我犯了某种程序错误,否则这个问题是没有办法解决的。

using System;

class Program
{
    static void Main(string[] args)
    {
        bool[] aValues = new bool[] { false, false, false, false, true, true, true, true };
        bool[] bValues = new bool[] { false, false, true, true, false, false, true, true };
        bool[] cValues = new bool[] { false, true, false, true, false, true, false, true };
        bool[] carryValues = new bool[] { false, false, false, true, false, true, true, true };
        bool[] constantFalse = new bool[] { false, false, false, false, false, false, false, false };
        bool[] constantTrue = new bool[] { true, true, true, true, true, true, true, true };

        bool[] sumValues = new bool[] { false, true, true, false, true, false, false, true };

        bool[][] allInputs = new bool[][] { aValues, bValues, cValues, carryValues, constantFalse, constantTrue };

        for (int controlOneIndex = 0; controlOneIndex < allInputs.Length; controlOneIndex++)
            for (int controlTwoIndex = 0; controlTwoIndex < allInputs.Length; controlTwoIndex++)
                for (int inputOneIndex = 0; inputOneIndex < allInputs.Length; inputOneIndex++)
                    for (int inputTwoIndex = 0; inputTwoIndex < allInputs.Length; inputTwoIndex++)
                        for (int inputThreeIndex = 0; inputThreeIndex < allInputs.Length; inputThreeIndex++)
                            for (int inputFourIndex = 0; inputFourIndex < allInputs.Length; inputFourIndex++)
                            {
                                for (int calculationIndex = 0; calculationIndex < sumValues.Length; calculationIndex++)
                                {
                                    if (MuxResult(allInputs[controlOneIndex][calculationIndex],
                                                allInputs[controlTwoIndex][calculationIndex],
                                                allInputs[inputOneIndex][calculationIndex],
                                                allInputs[inputTwoIndex][calculationIndex],
                                                allInputs[inputThreeIndex][calculationIndex],
                                                allInputs[inputFourIndex][calculationIndex]) != sumValues[calculationIndex])
                                    {
                                        goto tryNextValue;
                                    }
                                }
                                Console.WriteLine("Success: controls: {0} {1}   inputs: {2} {3} {4} {5}",
                                    controlOneIndex, controlTwoIndex, inputOneIndex, inputTwoIndex, inputThreeIndex, inputFourIndex);
                            tryNextValue: ;
                            }
        Console.WriteLine("done");
        Console.ReadLine();
    }

    private static bool MuxResult(bool controlOne, bool controlTwo, bool inputOne, bool inputTwo, bool inputThree, bool inputFour)
    {
        if (controlOne)
        {
            if (controlTwo)
                return inputFour;
            else
                return inputTwo;
        }
        else
        {
            if (controlTwo)
                return inputThree;
            else
                return inputOne;
        }
    }
}

【讨论】:

  • 抱歉,你迟到了 20 秒才得到“正确答案”,至少你应该投票。
【解决方案3】:
A B Cin S cout
0 0 0   0 0
0 0 1   1 0
0 1 0   1 0
0 1 1   0 1
1 0 0   1 0
1 0 1   0 1
1 1 0   0 1
1 1 1   1 1

通过将A 作为两个 2*1 多路复用器的选择线,我们在输入编号 0 中的第一个多路复用器中拥有 B XOR Cin 在输入编号 1 中 B XNOR Cin -> 这个多路复用器用于 S 在输入编号 0 的第二个多路复用器中,我们有 B AND Cin 在输入编号 1 中我们有 B OR Cin -> 这是Cout

【讨论】:

    【解决方案4】:

    VB 中的全加器

    Class fullAdder
    
        Private _A As Boolean
        Private _B As Boolean
        Private _Cin As Boolean
        Private _Sum As Boolean
        Private _Cout As Boolean
    
        Public Sub New()
            Me.A = False
            Me.B = False
            Me.Cin = False
        End Sub
    
        Public Sub SetInputs(a As Boolean, b As Boolean, cIn As Boolean)
            Me.A = a
            Me.B = b
            Me.Cin = cIn
        End Sub
    
        'Inputs           Outputs
        'A  B  Cin        Cout  S
        '0  0   0         0     0
        '1  0   0         0     1
        '0  1   0         0     1
        '1  1   0         1     0
        '0  0   1         0     1
        '1  0   1         1     0
        '0  1   1         1     0
        '1  1   1         1     1 
    
        Public Sub DoAdd()
            'debugIn()
            Dim ABxor As Boolean = Me.A Xor Me.B
            Me.Sum = ABxor Xor Me.Cin
            Dim ABxorAndCin As Boolean = ABxor And Me.Cin
            Dim ABand As Boolean = Me.A And Me.B
            Me.Cout = ABxorAndCin Or ABand
            'debugOut()
        End Sub
    
        Private Sub debugIn()
            Debug.WriteLine("'I {0} {1} {2}", Me.A, Me.B, Me.Cin)
        End Sub
    
        Private Sub debugOut()
            Debug.WriteLine("'O {0} {1}", Me.Cout, Me.Sum)
            Debug.WriteLine("")
        End Sub
    
        Public Property Sum() As Boolean
            Get
                Return Me._Sum
            End Get
            Set(ByVal value As Boolean)
                Me._Sum = value
            End Set
        End Property
    
        Public Property Cout() As Boolean
            Get
                Return Me._Cout
            End Get
            Set(ByVal value As Boolean)
                Me._Cout = value
            End Set
        End Property
    
        Public Property A() As Boolean
            Get
                Return Me._A
            End Get
            Set(ByVal value As Boolean)
                Me._A = value
            End Set
        End Property
    
        Public Property B() As Boolean
            Get
                Return Me._B
            End Get
            Set(ByVal value As Boolean)
                Me._B = value
            End Set
        End Property
    
        Public Property Cin() As Boolean
            Get
                Return Me._Cin
            End Get
            Set(ByVal value As Boolean)
                Me._Cin = value
            End Set
        End Property
    
    End Class
    

    【讨论】:

    • 你能用正确答案的人写的方式写吗?
    • 所以你想让我复制已经写好的代码?这只是一个全加器模拟。
    • 我不明白这在计算机结构中看起来如何。
    • 全加器的 Visual Basic 实现可能是有趣的琐事,但它对解决所提出的实际问题没有任何帮助。也许如果该实现演示了一对可以单独实现全加器的 MUX,或者如果它被用来证明这样的事情是不可能的,那么它就会成为话题。如果是这样,那么应该说明事实或方法。但是 OP 大概已经知道如何实现全加器,并且没有表示需要这样做,除非实现只使用两个 MUX。
    • 我需要一个仅使用 2 个多路复用器和 0 和 1 的全加器实现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 2022-11-22
    • 1970-01-01
    • 2020-04-09
    • 2011-02-23
    • 1970-01-01
    相关资源
    最近更新 更多