0

I have to design and implement a 4-bit processor for a course in uni using Xilinx, Virtex 6, VHDL. 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|

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.

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.

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). 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.

Here is a schematic of the processor:

enter image description here

Ilya
  • 5,377
  • 2
  • 18
  • 33
  • It seems to me that all the test inputs are positive, and the result is necessarily positive, so there's no need to represent negative numbers. It's much more likely that the inputs and outputs are intended to be unsigned 4-bit values. – Stephen Canon Dec 30 '15 at 15:40

1 Answers1

0

The trick might be to compute the opposite value: |X/2 - Y| = |Y - X/2|.

As X/2 is 3 bits, you can now complement it to do the substraction.

Ilya
  • 5,377
  • 2
  • 18
  • 33