Digital Fundamentals Lab 6 2's Complement / Digital Calculator

advertisement
Richland College
Digital Fundamentals
Engineering Technology
CETT 1425
Rev. 0 – B. Donham
Rev. 1 (7/2003)– J. Horne
Rev. 2 (1/2008) – J. Bradbury
Lab 6
2’s Complement / Digital Calculator
Name: _____________________________________________ Date: ________________________
Objectives:
•
To design and evaluate a Full Adder circuit.
•
To perform addition and subtraction, using 2’s complement, in a digital system.
Suggested Reading
Chapter 6, Digital Systems, Principals and Applications; Tocci
Equipment and Components
Circuit Simulator (MultiSIM or an equivalent)
Introduction
Digital computers and systems perform various arithmetic operations, including addition and
subtraction, on signed numbers represented in binary form. In order to perform a subtraction or operate
on negative numbers, the digital system must have a way to represent a signed number. The most
common method is to use a 2’s complement system, which includes a sign bit. The typical convention is
a ‘1’ in the most significant bit indicates a negative number and a ‘0’ represents a positive number. The
basic steps of taking the 2’s complement of a number are to invert each bit in the number and then add 1
to the inverted number. This results in the negative representation of the number.
0 0 1 0 0 binary representation of +4
1 1 0 1 1 invert each bit
0 0 0 0 1 add 1 to inverted number
1 1 1 0 0 2’s complement or binary representation of –4
The basic logic circuits used in for digital addition are a half-adder and a full-adder. The half-adder
performs the addition of 2 bits and produces a sum and carry bit output. The full-adder adds 2 bits plus
a carry bit. Connecting a series of full-adders can create a parallel binary adder.
Page 1 of 8
Procedure:
1.
The following is the truth table for a Full Adder. Write a sum-of-products expression for
Sum and Cout. Simplify each expression using a K-map or Boolean theorems.
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
Cin
0
1
0
1
0
1
0
1
Sum
0
1
1
0
1
0
0
1
Cout
0
0
0
1
0
1
1
1
Simplified Circuit Expressions
Sum = ____________________________________
Cout = ____________________________________
Page 2 of 8
2.
Using the simplified expressions, draw the schematic for a full-adder circuit.
Full Adder Circuit (schematic)
Page 3 of 8
3.
Start MultiSIM or an equivalent circuit simulator. Load the circuit on the following page,
which will be provided by your instructor or draw the schematic. This circuit is a simple
digital addition/subtraction calculator.
Inputs/Outputs:
Registers A & B are used to store the binary numbers for the arithmetic operations.
Register B [B] = switches 3 (Sign Bit), 2, 1, 0 (LSB) (D Flip-Flops)
Register A [A] = switches 7 (Sign Bit), 6, 5, 4 (LSB) (D Flip-Flops)
Addition:
Subtraction:
Switch ‘S’ set to 0V.
Switch ‘S’ set to +5V
Switch ‘C’ is the clear signal and clears registers A & B. Normally +5, momentary 0 clears
registers
Circuit Operation:
•
Set switch ‘S’ to add B to A (S = 0) or subtract B from A (S = +5).
•
Set switches ‘3’, ‘2’, ‘1’, ‘0’ to the binary numerical value to load into the B register
•
Set switches ‘7’, ‘6’, ‘5’, ‘4’ to the binary numerical value to load into the A register
•
Toggle switch ‘B’ to cause a rising edge to clock the binary number into the B register
•
Toggle switch ‘A’ to cause a rising edge to clock the binary number into the A register
•
Output LEDs will show the result of the arithmetic operation
NOTE: 2’s complement can only be performed on the B-Register. The 2’s
complement of the B register is taken when the Subtract function is selected.
Positive values should be selected with switches 3-0 (B) and 7-4 (A). If the
subtract operation is selected, the circuit will automatically calculate and
load the 2’s complement of B into the adder circuits.
Example: 5-3
Load 0101 into A and 0011 into B. When the subtract operation is selected,
the adder circuit will generate the 2’s complement of B.
Page 4 of 8
VCC
5V
B pos/neg
A
LAT CH
J4
J3
J2
J1
Key = A
Key = 7
Key = 6
J5
Key = 5
J6
Key = 4
LSB
Key = S
J13
U27
NOT
B
LAT CH
MSB
Key = B
U6
SET
U1
J11
U14
Q
D
Q
D
SET
~Q
U15
U5
RESET
CARRY
~Q
Key = 0
J7
U13 AND2
RESET
LSB
Key = 1
J8
AND2
U17
SET
Q
D
U16
~Q
Key = 2
J9
U10
Q
D
CARRY
~Q
AND2
A
RESET
OR2
CIN
AND2
U8
U3
U20
SET
Q
D
U19
~Q
J10
U21
U11
CARRY
Q
D
A
~Q
AND2
FULL_ADDER
SET
CIN
RESET
OR2
FULL_ADDER
U12
AND2
U23
Key = C
U4
D
U9
U24
SET
D
SET
Q
U22AND2
OR2
CARRY
A
Q
~Q
RESET
~Q
RESET
SUM
B
RESET
CLR
SUM
B
RESET
Key = 3
CIN
FULL_ADDER
SET
U18
SUM
B
U7
U2
B REG.
A
OR2
SUM
B
CIN
FULL_ADDER
AND2
Page 5 of 8
4.
Use the digital calculator to perform the following arithmetic operations. Calculate the
decimal value represented by the output LEDs (Show all of your work).
5.
Perform the following calculation recording the results in the table. Show how the decimal
value was calculated. (Show conversion steps from 5 to 0101.)
5+2
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
Sign
LSB
Decimal
Value
6. Perform the following calculation recording the results in the table. Show how the
decimal value was calculated. Remember, put 6 in the B register and set the sign switch for
logic high. Only B can be negated.
7-6
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
Sign
LSB
Decimal
Value
7. Perform the following calculation recording the results in the table. Show how the
decimal value was calculated. Only B can be negated.
5-7
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
Sign
LSB
Decimal
Value
Page 6 of 8
8. Perform the following calculation recording the results in the table. Show how the
decimal value was calculated. Only B can be negated.
4–4
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
Sign
LSB
Decimal
Value
9.
Perform the following calculation recording the results in the table. Show how
the decimal value was calculated. Only B can be negated.
4-3
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
Sign
LSB
Decimal
Value
10.
Perform the following calculation recording the results in the table. Show how
the decimal value was calculated.
1-7
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
Sign
LSB
Decimal
Value
11.
This calculator can also be used to add unsigned numbers. Assume that the A and
B registers as well as the result are unsigned numbers for this step. Perform the following
calculation recording the results in the table. Show how the decimal value was calculated.
6+7
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
MSB
LSB
Decimal
Value
Page 7 of 8
12.
Perform the following calculation recording the results in the table. Show how
the decimal value was calculated. Assume that the A and B registers as well as the output are
unsigned numbers.
12 + 8
B Reg Switches
A Reg Switches
3
7
2
1
0
6
5
4
Output LEDs
MSB
LSB
Decimal
Value
Did the output show the sum of 12 and 8 in binary? If NO explain why.
Review Questions:
Answer the following questions after the lab is completed.
1. What is the purpose of toggling switches A and B after switches 3-0 and 7-4 was set?
2. What is the largest positive SIGNED number that can be represented by this calculator?
3. What is the largest UNSIGNED number that can be represented by this calculator?
4. Subtraction in a 2’s complement system actually involves adding a positive and negative
number, which is in 2’s complement format. Evaluate the circuit shown on page 4 and
explain how the circuit is calculating the 2’s complement of the B register when the Subtract
function is selected.
Page 8 of 8
Download