使用 2 个 4:2:1 MUX 以及常数 0 和 1 构建全加器

发布于 2024-10-21 03:51:41 字数 109 浏览 2 评论 0原文

计算机结构中的一个问题,

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

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

A question in computer structures,

Build a full adder using 2 4:2:1 MUXes and the constants 0 and 1. Use minimum amount of constants.

Obviously this question is solvable using not gates too, but I am interested in the question without them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

得不到的就毁灭 2024-10-28 03:51:41

如果您的意思是四输入多路复用器,您可以执行以下操作(添加 abc):

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

我不知道如何无需其他门即可获得sum。一种选择是(使用“与”和“或”):

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

使用“异或”(可能很明显):

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

以下是为什么不能使用两个多路复用器执行此操作的概述:

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

If you mean a four-input mux, you can do (to add a, b, and c):

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

I'm not sure how to get sum without some other gate. One option is (with AND and OR):

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

With XOR (probably obvious):

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

Here's a sketch of why you can't do it with two muxes:

Since you have two muxes and two outputs, each mux must produce one output; thus, you need to compute sum from carry or compute carry from sum. You can't compute sum with just the three inputs without a NOT gate, and so you need to compute carry first. You can do that; then you need to get sum from the inputs and carry. Since the inputs are symmetric, the mux for sum can have its controls be either two inputs or one input and carry. The first case fails for the same reason that you can't compute sum first. Looking at the truth table and all possible combinations of carry and one input (call it a), there is no way to compute sum uniquely for the case where carry and a are the same using only one variable or constant as the input to each data input of the sum mux.

梦萦几度 2024-10-28 03:51:41

我只是编写了一个简单的 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;
        }
    }
}

I just wrote a simple little C# program to check every possible input combination, and it fails to find a solution. So, unless I made some kind of program error, there is no solution to this problem.

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;
        }
    }
}
咆哮 2024-10-28 03:51:41
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

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

By taking A, as the selection line to two 2*1 muxs we have in the first mux in input number 0 B XOR Cin in input number 1 B XNOR Cin -> this mux for S
in the second mux in input number 0 we have B AND Cin in input number 1 we have B OR Cin
-> this for Cout .

断爱 2024-10-28 03:51:41

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

A Full adder in 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文