简体   繁体   English

4位2补码减法的提示

[英]Tip for 4-bit 2's complement subtraction

I have to design and implement a 4-bit processor for a course in uni using Xilinx, Virtex 6, VHDL. 我必须使用Xilinx,Virtex 6,VHDL为单门课程设计和实现4位处理器。 I don't really know what those all mean i'm only a first year student. 我真的不知道这些都意味着我只是一年级的学生。 These were the instructions we received for the program. 这些是我们收到的程序说明。

We need to be able to compute the following: 我们需要能够计算以下内容:

|X/2 - Y| | X / 2-Y |

So the absolute value of X/2-Y, and we have to do it for X=9 and Y=12, and X=13 and Y=1. 因此,X / 2-Y的绝对值是X = 9和Y = 12,X = 13和Y = 1的绝对值。

I know that subtracting is addition with the negative version of a number (2's complement), and division by 2 is a right shift of the bits. 我知道减法是对数字的负数(2的补数)进行加法运算,而被2除是位的右移。

What I can't figure out is how do I represent 9, 12 and 13 as 4-bit numbers if we have to use 2's complement (since we are subtracting). 我不知道如何在必须使用2的补码的情况下将9、12和13表示为4位数字(因为我们要减去)。 I think it has something to do with the fact we need to take the absolute value but I can't figure it out. 我认为这与我们需要取绝对值有关,但我无法弄清楚。 I'm not asking for the wiring of the processor, but I'm hoping for some tips towards solving the problem of doing that operation with 4 bits only. 我不是在要求处理器的接线,而是希望有一些技巧来解决仅用4位进行该操作的问题。

Here is a schematic of the processor: 这是处理器的示意图:

在此处输入图片说明

The trick might be to compute the opposite value: |X/2 - Y| 技巧可能是计算相反的值:| X / 2-Y | = |Y - X/2|. = | Y-X / 2 |。

As X/2 is 3 bits, you can now complement it to do the substraction. 由于X / 2是3位,因此您现在可以对其进行补码以进行减法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM