Absolute value of a 16-bit 2's-complement value is not a very complex arithmetic operation. Here's a little chunk of Verilog code that computes all possible values:
module demoabs; reg signed [15:0] a, b; initial begin a = -32768; repeat (65536) begin b = ((a < 0) ? -a : a); $display("abs(%x) = %x", a, b); #1 a = a + 1; end end endmodule
The real work is just b = ((a < 0) ? -a : a);. The catch is that in this project, I want you to design a synthesizable, purely combinatorial, circuit for a 16-bit 2's complement absolute value without using Verilog word-level operators like < for less than comparison or - for negation. You also must exhaustively test your design.
So, let's talk about absolute value. There are sneaky ways, such as those documented here, to compute absolute value without a conditional comparison and branch. Of course, that doesn't really help much here because you're not allowed to use the Verilog - nor + operators in making your combinatorial circuit. It is worth noting that I would allow you to use >> (shift) and ^ (XOR) because they are bitwise operators, not really word-level arithmetic operations.
The basic point is, it's up to you what algorithm you use... and that choice will determine what other modules you might need to create as helpers.
One last point: demoabs, and any absolute value you create, will get one one value "wrong." Huh? Well, what is the absolute value of -32768 (aka, hexadecimal 8000)? The answer, of course, is 32768 -- but that value isn't representable in a 16-bit signed integer. Don't worry about that. All the methods will generate the same mathematically-wrong-but-we'll-call-it-right answer: abs(-32678) is -32678.
Your project is about writing a Verilog module called abs, but there are actually two other chunks of Verilog code you need in order to test it. The three required modules of Verilog code are:
$display("All cases tested; %d correct, %d failed", correct, failed);
Place all your verilog code for the above in one file called abs.v. That's the file you need to submit.
Naturally, I also expect you to run that file through a Verilog compiler either using our CGI interface or Icarus Verilog directly:
iverilog -o abs abs.v
And to run the simulation to test it:
vvp abs
Which will hopefully result in it printing just:
All cases tested; 65536 correct, 0 failed
If not, and you can't figure-out how to fix it, as Ricky Ricardo would say, you got some splainin to do. ;-)
You should be submitting an implementor's notes document with your project. Just a couple of quick comments about that....
Your implementor's notes certainly should describe the logic used to implement your abs module. That can be done as text. I am not requiring you to provide a schematic of your abs module... it's rather simple and the schematic wouldn't really be very useful. However, practice creating schematics is certainly a good thing (i.e., a skill you will appreciate in this course) and it wouldn't hurt to include a schematic.
Although I would encourage you to think about generating a VCD file and using gtkwave to visualize it, I don't think there's much point in doing that for a simple combinatorial circuit like abs. If you do find it useful, you may include a screen grab from gtkwave in your implementor's notes.
The recommended due date for this assignment is before class, Monday, February 4, 2019. This submission window will close when class begins on Wednesday, February 6, 2019. You may submit as many times as you wish, but only the last submission that you make before class begins on Wednesday, February 6, 2019 will be counted toward your course grade.
Note that you can ensure that you get at least half credit for this project by simply submitting a tar of an "implementor's notes" document explaining that your project doesn't work because you have not done it yet. Given that, perhaps you should start by immediately making and submitting your implementor's notes document? (I would!)
For each project, you will be submitting a tarball (i.e., a file with the name ending in .tar or .tgz) that contains all things relevant to your work on the project. Minimally, each project tarball includes the source code for the project and a semi-formal "implementors notes" document as a PDF named notes.pdf. It also may include test cases, sample output, a make file, etc., but should not include any files that are built by your Makefile (e.g., no binary executables). For this particular project, name the Verilog source file abs.v.
Submit your tarball below. The file can be either an ordinary .tar file created using tar cvf file.tar yourprojectfiles or a compressed .tgz file file created using tar zcvf file.tgz yourprojectfiles. Be careful about using * as a shorthand in listing yourprojectfiles on the command line, because if the output tar file is listed in the expansion, the result can be an infinite file (which is not ok).