Key3 (C1) | Key2 (C0) | Operation |
---|---|---|
Pressed | Pressed | Display A+B |
Pressed | Unpressed | Display A-B |
Unpressed | Pressed | Display the absolute value of B |
Unpressed | Unpressed | Display the absolute value of A |
Restrictions
Operation | A | A | A1 | S1 | A2 | B | B | B1 | B2 | S2 | B3 | C | Sum Binary |
Sum Signed Decimal |
A + B | 0001 | 1 | 00001 | 0 | 00001 | 0010 | 2 | 00010 | 11101 | 1 | 00010 | 0 | 00011 | 3 |
A + B | 0011 | 3 | . | . | . | 1111 | -1 | . | . | . | . | . | . | . |
A + B | 1011 | -5 | . | . | . | 1110 | -2 | . | . | . | . | . | . | . |
A - B | 0001 | 1 | . | . | . | 0010 | 2 | . | . | . | . | . | . | . |
A - B | 1111 | -1 | . | . | . | 0001 | 1 | . | . | . | . | . | . | . |
| B| | dc | . | . | . | . | 1101 | -3 | . | . | . | . | . | . | . |
|B| | dc | . | . | . | . | 0011 | 3 | . | . | . | . | . | . | . |
Demonstrate the operation of your final calculator design to the lab GSI. Be sure that the following cases work before demonstrating.
1 + (-7) = -6Post-Lab (40 Points)
0 - 7 = -7
-1 + 1 = 0
7 - (-8) = 15
-8 + (- 8) = -16
|7| = 7
|-8| = 8
assign bob=(mary==1'b1) ? 2'b01 : 2'b10;This is basically the same as saying
if(mary==1'b1)This operator can be thought of as a MUX.
bob=2'b01;
else
bob=2'b10;
Consider the following coding example (parameter is a way to declare a constant).
module display(letter,seven);This uses the ?: operator to assign values to the seven-segment display depending upon the value of "letter".
input [1:0] letter;
output [6:0] seven;
parameter F=7'b1000111;
parameter S=7'b1011011;
parameter r=7'b0000101;
parameter L=7'b0001110;
assign seven= (letter==2'b00 ? F:
(letter==2'b01 ? S:
(letter==2'b10 ? r:
L)));
endmodule
Important: Quartus appears to occasionally be very sensitive to a lack of spaces around the ? operator.