Professional Documents
Culture Documents
Discussion D4.5
Shift and Add-3 Algorithm
S1. Shift the binary number left one bit.
22. If 8 shifts have taken place, the BCD number is in the
Hundreds, Tens, and Units column.
33. If the binary value in any of the BCD columns is 5 or greater,
add 3 to that value in that BCD column.
44. Go to 1.
0 B7 B6 B5 B4 B3 B2 B1 B0
Binary-to-BCD C1
Converter C2
0 C3
C6 C4
C7 C5
P9 P8 P7 P6 P5 P4 P3 P2 P1 P0
0 B7 B6 B5 B4 B3 B2 B1 B0
1 1 1 1 1 1 1 1
Binary-to-BCD C1
Converter 1 0 1 0
C2
1 0 0 0
RTL Solution 0 C3
1 1 0 0 0 1
C6 C4
1 0 0 1 0 0 1 1 1 1
C7 C5
1 0 0 1 0 1 0 1 0 1
P9 P8 P7 P6 P5 P4 P3 P2 P1 P0
end binbcd6; C1
1 0 1 0
C2
architecture binbcd6_arch of binbcd6 is 1 0 0 0
begin 0 C3
bcd1: process(B) 1 1 0 0 0 1 1
tens units
6 3
Operation Tens Units Binary
B 5 4 3 2 1 0
HEX 3 F
binbcd6.vhd (cont.) Start 1 1 1 1 1 1
Shift 1 1 1 1 1 1 1
Shift 2 1 1 1 1 1 1
Shift 3 1 1 1 1 1 1
begin Add 3 1 0 1 0 1 1 1
Shift 4 1 0 1 0 1 1 1
for i in 0 to 12 loop
Add 3 1 1 0 0 0 1 1
z(i) := '0'; Shift 5 1 1 0 0 0 1 1
end loop; Shift 6 1 1 0 0 0 1 1
C2
P <= z(12 downto 6); 1 0 0 0
P7 P6 P5 P4 P3 P2 P1 P0
tens units
6 3
Hex 3F
binbcd6.vhd 6-bit binary input
Shift 2 1 1 1 1 1 1
C2
Shift 3 1 1 1 1 1 1
Add 3 1 0 1 0 1 1 1 1 0 0 0
Shift 4 1 0 1 0 1 1 1
0 C3
Add 3 1 1 0 0 0 1 1
Shift 5 1 1 0 0 0 1 1 1 1 0 0 0 1 1
Shift 6 1 1 0 0 0 1 1
P7 P6 P5 P4 P3 P2 P1 P0
BCD 6 3
P 7 4 3 0
z 13 10 9 6 5 0 tens units
6 3
BCD output
8-Bit Binary-to-BCD Converter binbcd8.vhd
0 B7 B6 B5 B4 B3 B2 B1 B0
1 1 1 1 1 1 1 1
Operation Hundreds Tens Units Binary
B 7 4 3 0 C1
HEX F F 1 0 1 0
Start 1 1 1 1 1 1 1 1
Shift 1 C2
1 1 1 1 1 1 1 1
Shift 2 1 1 1 1 1 1 1 1 1 0 0 0
Shift 3 1 1 1 1 1 1 1 1
0 C3
Add 3 1 0 1 0 1 1 1 1 1
1 1 0 0 0 1
Shift 4 1 0 1 0 1 1 1 1 1
Add 3 1 1 0 0 0 1 1 1 1 C6 C4
Shift 5 1 1 0 0 0 1 1 1 1 1 0 0 1 0 0 1 1 1 1
Shift 6 1 1 0 0 0 1 1 1 1
Add 3 1 0 0 1 0 0 1 1 1 1 C7 C5
Shift 7 1 0 0 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 0 1
Add 3 1 0 0 1 0 1 0 1 0 1
P9 P8 P7 P6 P5 P4 P3 P2 P1 P0
Shift 8 1 0 0 1 0 1 0 1 0 1
BCD 2 5 5
hunds tens units
P 9 8 7 4 3 0
2 5 5
z 17 16 15 12 11 8 7 4 3 0
BCD output
16-bit binary input
C1
16-bit C2
Binary-to-BCD 0 C3
Converter C14 C4
C15 C5
0 C16 C6
C24 C17 C7
C25 C18 C8
0 C26 C19 C9
P19 P18 P17 P16 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0
C1
binbcd16.vhd C2
0 C3
C14 C4
C15 C5
use IEEE.std_logic_1164.all;
C25 C18 C8
use IEEE.std_logic_unsigned.all;
0 C26 C19 C9
); P19 P18 P17 P16 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0
begin
for i in 0 to 34 loop
binbcd16.vhd (cont.) C1
C2
z(i) := '0'; 0 C3
0 C16 C6
z(23 downto 20) := z(23 downto 20) + 3; C33 C29 C22 C12
if z(27 downto 24) > 4 then P19 P18 P17 P16 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0
z(27 downto 24) := z(27 downto 24) + 3; ten thousands thousands hundreds
BCD output
tens units
end if;
if z(31 downto 28) > 4 then
z(31 downto 28) := z(31 downto 28) + 3;
end if;
z(34 downto 1) := z(33 downto 0);
end loop;
P <= z(34 downto 16);
end process bcd1;
end binbcd16_arch;
16-bit binary input
C1
binbcd16.vhd C2
C3
0
C14 C4
C15 C5
0 C16 C6
C24 C17 C7
C25 C18 C8
0 C26 C19 C9
P19 P18 P17 P16 P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0