Papilio multiply

Problem

The goal is to multiply two four bit numbers in hardware. The goal is to build a little bit of a CPU that was originally a separate chip called a math co-processor or ALU. The goal is to demonstrate it's operation on a papilio with a logic start mega wing. This project was inspired by Fig. 8.19 page 465, of Chapter 8 (Algorithmic State Machines) of the text book "Digital Principles and Design" by Donald D. Bivone First Edition copyright 2003.

Conceive

This problem can be done with simple VHDL code. It can be done with Intellectual Property (IP) of the major FPGA vendors. Or it can be done from scratch using an Algorithmic State Machine (ASM) which is started through an OpCode which the CPU finds in it's instruction register, two 4 bit shift registers, a 4 bit adder, a flipflop and a counter.

The goal is to build an intuition/confidence that one is actually design part of a CPU. Specifically a CPU's shift registers, latch and adder are the shared resources used. The ASM circuit is actually using these shared resources to create a multiplication operation.

The goal is to write the VHDL with tests for each module, then put it all together with a VHDL test and finally implement in a papilio using 8 switches on the logic start mega wing to input two 4 bit numbers and display 8 bits of the results on the logic start LEDs.

Design

This project depends upon a lot of little circuits working. The goal was to start with the Wikibook designs, and then add to them, or modify them.

How going to use LogicStart MegaWing

Main VHDL Code Outline

LED Flash Circuit

Design a circuit to sit inbetween 8 wires turning 8 LED’s off and on.

Have 3 inputs … ABC … 8 LED’s

Input “A” turns off and on the first four LED’s. If the LED is off (representing a zero) it stays off. If the LED is on (representing a 1), then it turns off or on depending on the value of A. At least one of the 4 LEDs will always be on.

The other two inputs are more complicated. They control the other 4 LEDs. This circuit does not control whether the LED is on or off. This circuit controls whether they are solid or flashing. There are five states of these 4 LEDs:

• Solid solid solid solid
• Solid solid solid flashing
• Solid solid flashing flashing
• Solid flashing flashing flashing
• flashing flashing flashing flashing

So there is a total of 5 states. The two inputs B,C are used as follows. As long as B is high, step to the next state until at the last state. Otherwise stay in the current state.

Stay at the last state until input C is high, and then start over. The value of B doesn’t matter when at the last state or when transitioning to the first state.

The Flashing desired is this:

• if originally a 0 … then off on off … off on off … two offs then on (repeat)
• if originally a 1 … then on off on … on off on … two ons then off(repeat)
7 Seg Display Control

The seven segment display will light up to show the input numbers or the product. This is determined by the SD_Toggle signal. If displaying the multiplier and multiplicand, then the first two displays will show the first number, while the last two will display the second. If the product is to be shown, then the first display will be blank, the second will be blank if the product is less than 100, the third will be blank if the product is less than 10, and the fourth will show the ones place.

Binary to BCD

To simplify the process of decoding the output, this module will translate the binary code into binary coded decimal. It will also read the toggle, so that it will either output two five-bit strings for the multiplier and multiplicand or a single ten-bit string for the product.

In designing the circuit that controls the LEDs showing the 4 least significant bits (lsb), we first focused on building the state machine. We actually needed 3 inputs: one input signaling that the register has been cleared and received the multiplier(first state), one input signaling the shift, and one input holding the value of the least significant bit of the partial sum stored in the register.

To ensure that the state machine is working, we decided to light all 4 LEDs once the clear signal is on, and turn them off to simulate the shift. Then we decided to add the flashing desired. It turned out to be the most challenging part:

• We first added the modules we built from other projects. We customized the .coe file to match one LED. The LED will just turned off. We decided to test the file on its own, and despite enabling only one LED, all will lit up with solid light. The goal was to see if we could customize the .coe file to match the pattern for 0 or 1 being concatenated.
• Then, we decided to blink the LEDS. We tested the code to blink the LEDs by itself and it worked. Then we add it as a module. First, it turned the LED off. There was no blinking. We decided to make it a process but it seems we cannot have a 'rising_edge(clk)' twice when designing a circuit. You can only use 'if' in a process, so we added the counter in different parts of our main process with no success. The signal that was supposed to blink the LEDs is never assigned so the compiler will give a constant value of 0. Therefore, it just turns off the LEDs. We decided then to blink the LEDs from the module. It did not work either. We finally tried to have as bidirectional ports the LEDs in the module and in the main vhdl code, it showed the LEDs having multiple drivers.

You will find below the code to blink the LEDs (We have two different patterns to represent 0 or 1). We also have the ASM for the flash-led circuit. We are using switches to simulate our three inputs. The "concatenated" bit did not work out so well with the switch but we needed to test it somehow and it can be implemented.

Implement

Simple VHDL code using IEEE Arith.ALL
```library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity SWITCH_LED is
Port ( SWITCH : in  STD_LOGIC_VECTOR(7 downto 0);
LED    : out STD_LOGIC_VECTOR(7 downto 0));
end SWITCH_LED;

architecture Behavioral of SWITCH_LED is
signal x : STD_LOGIC_VECTOR(3 downto 0);
signal y : STD_LOGIC_VECTOR(3 downto 0);
-- signal carry : STD_LOGIC_VECTOR(3 downto 0);
signal result : STD_LOGIC_VECTOR(7 downto 0);
begin

x <= SWITCH(3 downto 0);
y <= SWITCH(7 downto 4);
result <= x * y;
LED <= result ;

end Behavioral;

```

You can also find out how to build a 4-state Mealy ASM here

VHDL code for multiplication on seven seg using IEEE Arith.ALL
``` library IEEE;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity SWITCH_LED is
Port (anodes  :   inout STD_LOGIC_VECTOR(3 downto 0);
switch :   in STD_LOGIC_VECTOR(7 downto 0);
JOY_SELECT : in STD_LOGIC;
clk : IN  std_logic;
segment : out STD_LOGIC_VECTOR(6 downto 0));
end SWITCH_LED;

architecture Behavioral of SWITCH_LED is
signal counter: STD_LOGIC_VECTOR(30 downto 0);
signal s  : STD_LOGIC_VECTOR(1 downto 0);
signal aen :    STD_LOGIC_VECTOR(3 downto 0);
signal display  :    STD_LOGIC_VECTOR(3 downto 0);
signal x :    STD_LOGIC_VECTOR(3 downto 0);
signal y :    STD_LOGIC_VECTOR(3 downto 0);
signal product :   STD_LOGIC_VECTOR(7 downto 0);
begin
s <= counter(18 downto 17);
aen <= "1111";
process(clk, counter)
begin
if rising_edge(clk) then
counter <= counter + 1;
end if;
end process;
process(s, counter)
begin
CASE s is
when "00" => display <= counter(29 downto 26);
when "01" => display <= counter(25 downto 22);
when "10" => display <= counter(21 downto 18);
when others => display <= counter(17 downto 14);
end CASE;
end process;
process(s, aen, anodes, product)
begin
anodes <= "1111";

if aen(conv_integer(s)) = '1' then
anodes(conv_integer(s)) <= '0';

CASE anodes is
When "1101" =>
CASE  switch(7 downto 4) IS
WHEN "0000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "0001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "0010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "0011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "0100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "0101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "0110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "0111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "1000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "1001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "1010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "1011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "1100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "1101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "1110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "1111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN OTHERS =>
segment(0) <='1';
segment(1) <='1';
segment(2) <='1';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
END CASE;
When "1110" =>
if switch(7 downto 4) > "1001" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
else
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
end if;
When "0111" =>
CASE  switch(3 downto 0) IS
WHEN "0000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "0001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "0010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "0011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "0100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "0101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "0110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "0111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "1000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "1001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "1010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "1011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "1100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "1101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "1110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "1111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN OTHERS =>
segment(0) <='1';
segment(1) <='1';
segment(2) <='1';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
END CASE;
When "1011" =>
if switch(3 downto 0) > "1001" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
else
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
end if;
When OTHERS =>
segment(0) <='1';
segment(1) <='1';
segment(2) <='1';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';

end case;
end if;
if JOY_SELECT ='0' then
x <= switch(7 downto 4);
y <= switch(3 downto 0);
product <= x * y;
CASE anodes is
When "0111" =>
CASE  product IS
WHEN "00000000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "00000001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00000010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "00000011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "00000100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00000101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00000110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00000111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00001000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00001001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00001010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "00001011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00001100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "00001101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "00001110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00001111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00010000" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00010001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00010010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00010011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00010100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "00010101" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00010110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "00010111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "00011000" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00011001" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00011010" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00011011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00011100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00011101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00011110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "00011111" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00100000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "00100001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "00100010" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00100011" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00100100" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00100101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00100110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00100111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00101000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "00101001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00101010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "00101011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "00101100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00101101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00101110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00101111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00110000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00110001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00110010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "00110011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00110100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "00110101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "00110110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00110111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00111000" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00111001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00111010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "00111011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "00111100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "00111101" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "00111110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "00111111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "01000000" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01000001" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01000011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01000100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01000101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01000110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "01000111" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01001000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "01001001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "01001010" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01001011" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01001100" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01001101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01001110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01001111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01010000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "01010001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01010010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "01010011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "01010100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01010101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01010110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01010111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01011000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01011001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01011010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "01011011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01011100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "01011101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "01011110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01011111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01100000" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01100001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01100010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01100011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01100100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "01100101" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01100110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "01100111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "01101000" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01101001" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01101010" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01101011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01101100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01101101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01101110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "01101111" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01110000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "01110001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "01110010" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01110011" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01110100" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01110101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01110110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01110111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01111000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "01111001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "01111010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "01111011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "01111100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01111101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "01111110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "01111111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10000000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10000001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10000010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "10000011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10000100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "10000101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "10000110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10000111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10001000" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10001001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10001010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10001011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10001100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "10001101" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10001110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "10001111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "10010000" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10010001" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10010010" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10010011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10010100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10010101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10010110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "10010111" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10011000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "10011001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "10011010" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10011011" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10011100" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10011101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10011110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10011111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10100000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "10100001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10100010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "10100011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "10100100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10100101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10100110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10100111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10101000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10101001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10101010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "10101011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10101100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "10101101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "10101110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10101111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10110000" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10110001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10110010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10110011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10110100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "10110101" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10110110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "10110111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "10111000" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10111001" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10111010" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10111011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "10111100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "10111101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "10111110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "10111111" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "11000000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "11000001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "11000010" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11000011" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11000100" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "11000101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "11000110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "11000111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11001000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "11001001" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "11001010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "11001011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "11001100" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11001101" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11001110" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "11001111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "11010000" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "11010001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11010010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "11010011" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "11010100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "11010101" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "11010110" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11010111" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11011000" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "11011001" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "11011010" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
WHEN "11011011" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11011100" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
WHEN "11011101" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
WHEN "11011110" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
WHEN "11011111" =>
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
WHEN "11100000" =>
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
WHEN "11100001" =>
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
--					WHEN "11100010" =>
--					segment(0) <='0';
--					segment(1) <='1';
--					segment(2) <='0';
--					segment(3) <='0';
--					segment(4) <='0';
--					segment(5) <='0';
--					segment(6) <='0';
--					WHEN "11100011" =>
--					segment(0) <='0';
--					segment(1) <='0';
--					segment(2) <='0';
--					segment(3) <='1';
--					segment(4) <='1';
--					segment(5) <='1';
--					segment(6) <='1';
--					WHEN "11100100" =>
--					segment(0) <='0';
--					segment(1) <='0';
--					segment(2) <='0';
--					segment(3) <='0';
--					segment(4) <='0';
--					segment(5) <='0';
--					segment(6) <='0';
--					WHEN "11100101" =>
--					segment(0) <='0';
--					segment(1) <='0';
--					segment(2) <='0';
--					segment(3) <='0';
--					segment(4) <='1';
--					segment(5) <='0';
--					segment(6) <='0';
When OTHERS =>
segment(0) <='1';
segment(1) <='1';
segment(2) <='1';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
end case;
When "1011" =>
if product  > "00001001" and product < "00010100" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
elsif product  > "00010011"  and product < "00011110" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
elsif product > "00011101"  and product < "00101000" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
elsif product > "00100111"  and product < "00110010" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
elsif product > "00110001"  and product < "00111100" then
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
elsif product > "00111011"  and product < "01000110" then
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
elsif product > "01000101"  and product < "01010000" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
elsif product > "01001111"  and product < "01011010" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
elsif product > "01011001"  and product < "01100100" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
elsif product > "01101101"  and product < "01111000" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
elsif product > "01110111"  and product < "10000010" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
elsif product > "10000001"  and product < "10001100" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='1';
segment(6) <='0';
elsif product > "10001011"  and product < "10010110" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
elsif product > "10010101"  and product < "10100000" then
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='1';
segment(5) <='0';
segment(6) <='0';
elsif product > "10011111"  and product < "10101010" then
segment(0) <='0';
segment(1) <='1';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
elsif product > "10101001"  and product < "10110100" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
elsif product > "10110011"  and product < "10111110" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='0';
--				elsif product > "10111101"  and product < "11001000 " then
--					segment(0) <='0';
--					segment(1) <='0';
--					segment(2) <='0';
--					segment(3) <='0';
--					segment(4) <='1';
--					segment(5) <='0';
--					segment(6) <='0';
elsif product > "11010001"  and product < "11011100" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
elsif product > "10111101"  and product < "11100010" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
else
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
end if;
When "1101" =>
if product  > "01100011" and product < "11001000" then
segment(0) <='1';
segment(1) <='0';
segment(2) <='0';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
elsif product  > "11000111" then
segment(0) <='0';
segment(1) <='0';
segment(2) <='1';
segment(3) <='0';
segment(4) <='0';
segment(5) <='1';
segment(6) <='0';
else
segment(0) <='0';
segment(1) <='0';
segment(2) <='0';
segment(3) <='0';
segment(4) <='0';
segment(5) <='0';
segment(6) <='1';
end if;
When OTHERS =>
segment(0) <='1';
segment(1) <='1';
segment(2) <='1';
segment(3) <='1';
segment(4) <='1';
segment(5) <='1';
segment(6) <='1';
end case;
end if;
end process;
end Behavioral;
```

LED Flash Circuit ASM
```library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;

entity LED_Flash_Circuit is
Port ( --bit0 : in  STD_LOGIC; -- will hold concatenated value
clk : in STD_LOGIC;
--flash_0 : out  STD_LOGIC; -- signal from shift register
--clear : in  STD_LOGIC; -- register is empty so light on LEDS is steady
SWITCH: in  STD_LOGIC_VECTOR (2 downto 0);  --will use it to change value of blank when testing
LED : out  STD_LOGIC_VECTOR (7 downto 4));
end LED_Flash_Circuit;

architecture Behavioral of LED_Flash_Circuit is

signal bit_0 : STD_LOGIC; --to simulate bit0 with SWITCH
signal bit1 :   STD_LOGIC; -- signal from shift register
signal state : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');
constant steady : STD_LOGIC_VECTOR(3 downto 0) := (others => '1'); -- to ensure I always get one and move to next state
constant state_start : STD_LOGIC_VECTOR(2 downto 0) := "000";
constant state_one_right : STD_LOGIC_VECTOR(2 downto 0) :="001";
constant state_two_right : STD_LOGIC_VECTOR(2 downto 0) := "010";
constant state_three_right : STD_LOGIC_VECTOR(2 downto 0) := "011";
constant state_four_right : STD_LOGIC_VECTOR(2 downto 0) := "100";
signal flash_0 : STD_LOGIC;
signal flash_1 : STD_LOGIC;
signal blank : STD_LOGIC; -- to hold clear since input cannot be changed

begin

process (clk,SWITCH)

begin

blank <= SWITCH(0);
bit_0 <= SWITCH(1);
bit1 <= SWITCH(2);

if rising_edge(clk) then
if blank = '1'   then

CASE state IS--

when state_start =>
case bit1 is
when '0' => state <= state_start;
when others =>state <= state_one_right;
end case;

when state_one_right =>
case bit1 is
when '1' => state <= state_one_right;
when others =>
LED (7 downto 5)<= "111";
LED(4) <= '0';

--if bit_0 = '0' then
--LED(4) <= flash_0;
--else
--LED(4) <= flash_1;
--end if;

state <= state_two_right;
end case;

when state_two_right =>
case bit1 is
when '0' => state <= state_two_right;
when others =>
LED(7 downto 6) <= "11";
LED(5) <= '0';

--if bit_0 = '0' then
--LED(4) <= flash_0;
--else
--LED(4) <= flash_1;
--end if;

state <= state_three_right;
end case;

when state_three_right =>
case bit1 is
when '1' => state <= state_three_right;
when others =>
LED(7) <= '1';
LED(6) <= '0';

--if bit_0 = '0' then
--LED(4) <= flash_0;
--else
--LED(4) <= flash_1;
--end if;

state <= state_four_right;
end case;

when state_four_right =>
case bit1 is
when '0' => state <= state_four_right;
when others =>
LED(7) <= '0';

--if bit_0 = '0' then
--LED(4) <= flash_0;
--else
--LED(4) <= flash_1;
--end if;

blank <= SWITCH(0);
end case;

when others =>
NULL;

end case;

else
blank <= SWITCH(0);
state <= "000";
end if;

end if;

end process;

end Behavioral;
```

```library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

Port ( clk : in  STD_LOGIC;
--SWITCH : in STD_LOGIC_VECTOR (2 downto 0)
--flashing_0: inout STD_LOGIC;
--flashing_1: inout STD_LOGIC);
LED : out STD_LOGIC_VECTOR (1 downto 0));

architecture Behavioral of Blink_LED is
signal counter1: std_logic_vector(24 downto 0);
signal counter2: std_logic_vector(24 downto 0);
signal CLK_1Hz_0: std_logic;
signal CLK_1Hz_1: std_logic;
--signal led_num: std_logic;
--signal concatenate: std_logic;
--signal ctrl: std_logic;
begin
--led_num <= SWITCH(0);
--concatenate <= SWITCH(1);
--ctrl <= SWITCH(2);
Prescaler: process(clk)
begin
if rising_edge(clk) then
if counter1 < 25000000 then
counter1 <= counter1 + 1;
else
CLK_1Hz_0 <= not CLK_1Hz_0;
counter1 <= (others => '0');
end if;

if counter2 < 950000 then
counter2 <= counter2 + 1;
else
CLK_1Hz_1 <= not CLK_1Hz_1;
counter2 <= (others => '0');
end if;
end if;
end process Prescaler;

flashing_0 <= CLK_1Hz_0;
flashing_1 <= CLK_1Hz_1;

end Behavioral;
```
Here are the videos of showing the execution of the codes above:

You can also find out how to build a 4-state Mealy ASM here

7 Seg Display Control
```--------------------------------------------------------------------------------
---- Howard Community College Spring 2015 ENES-245 ----
---- This file is part of the Final Project lab ----
---- Description: Control for the 7 Segment Display, made by Brichard ----
---- Date: 4/27/2015 ----
---- Current Status: Complete ----
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity SegDisplayControl is
Port( CLK : in STD_LOGIC;
Seg7_AN : out STD_LOGIC_VECTOR(3 downto 0);
Seg7 : out STD_LOGIC_VECTOR(6 downto 0)
);
end SegDisplayControl;

architecture Behavioral of SegDisplayControl is
COMPONENT AlgorithmicStateMachine
PORT( SD_Toggle : out STD_LOGIC);
END COMPONENT;

COMPONENT BinarytoDec
PORT(
product : OUT std_logic_vector(9 downto 0);
multiplicand : OUT std_logic_vector(4 downto 0);
multiplier : OUT std_logic_vector(4 downto 0)
);
END COMPONENT;

signal counter : unsigned(1 downto 0);
signal multiplied : std_logic_vector(4 downto 0) := "00000";
signal multiplies : std_logic_vector(4 downto 0) := "00000";
signal productive : std_logic_vector(9 downto 0) := "0000000000";
signal Toggle : STD_LOGIC;
begin

Inst_AlgorithmicStateMachine: AlgorithmicStateMachine PORT MAP(
SD_TOGGLE => Toggle
);
Inst_BinarytoDec: BinarytoDec PORT MAP(
product => productive,
multiplicand => multiplied,
multiplier => multiplies
);

count: process(CLK)
begin
if rising_edge(CLK) then
counter <= (counter+1);
end if;
end process;

annode: process(counter)
begin
CASE counter(1 downto 0) is
WHEN "00" =>
Seg7_AN(3 downto 0) <= "1110";
WHEN "01" =>
Seg7_AN(3 downto 0) <= "1101";
WHEN "10" =>
Seg7_AN(3 downto 0) <= "1011";
WHEN "11" =>
Seg7_AN(3 downto 0) <= "0111";
WHEN OTHERS =>
Seg7_AN(3 downto 0) <= "1111";
END CASE;
end process;

display: process( Toggle, counter(1 downto 0), productive, multiplies, multiplied )
begin
while ( Toggle = '1' ) loop
if counter(1 downto 0) = "00" then
if multiplied(4) = '1' then
Seg7(6 downto 0) <= "1111001";
else Seg7(6 downto 0) <= "1000000";
END if;
elsif counter(1 downto 0) = "01" then
CASE multiplied(3 downto 0) is
WHEN "0000" =>
Seg7(6 downto 0) <= "1000000";
WHEN "0001" =>
Seg7(6 downto 0) <= "1111001";
WHEN "0010" =>
Seg7(6 downto 0) <= "0100100";
WHEN "0011" =>
Seg7(6 downto 0) <= "0110000";
WHEN "0100" =>
Seg7(6 downto 0) <= "0011001";
WHEN "0101" =>
Seg7(6 downto 0) <= "0010010";
WHEN "0110" =>
Seg7(6 downto 0) <= "0000010";
WHEN "0111" =>
Seg7(6 downto 0) <= "1111000";
WHEN "1000" =>
Seg7(6 downto 0) <= "0000000";
WHEN "1001" =>
Seg7(6 downto 0) <= "0010000";
WHEN OTHERS =>
Seg7(6 downto 0) <= "1111111";
END CASE;
elsif counter(1 downto 0) = "10" then
if multiplies(1) >= '1' then
Seg7(6 downto 0) <= "1111001";
else Seg7(6 downto 0) <= "1000000";
END if;
elsif counter(1 downto 0) = "11" then
CASE multiplies(3 downto 0) is
WHEN "0000" =>
Seg7(6 downto 0) <= "1000000";
WHEN "0001" =>
Seg7(6 downto 0) <= "1111001";
WHEN "0010" =>
Seg7(6 downto 0) <= "0100100";
WHEN "0011" =>
Seg7(6 downto 0) <= "0110000";
WHEN "0100" =>
Seg7(6 downto 0) <= "0011001";
WHEN "0101" =>
Seg7(6 downto 0) <= "0010010";
WHEN "0110" =>
Seg7(6 downto 0) <= "0000010";
WHEN "0111" =>
Seg7(6 downto 0) <= "1111000";
WHEN "1000" =>
Seg7(6 downto 0) <= "0000000";
WHEN "1001" =>
Seg7(6 downto 0) <= "0010000";
WHEN OTHERS =>
Seg7(6 downto 0) <= "1111111";
END CASE;
end if;
end loop;
while ( Toggle = '0' ) loop
if counter(1 downto 0) = "00" then
Seg7(6 downto 0) <= "1111111";
elsif counter(1 downto 0) = "01" then
CASE productive(9 downto 8) is
WHEN "00" =>
Seg7(6 downto 0) <= "1111111";
WHEN "01" =>
Seg7(6 downto 0) <= "1111001";
WHEN "10" =>
Seg7(6 downto 0) <= "0100100";
WHEN OTHERS =>
Seg7(6 downto 0) <= "1111111";
END CASE;
elsif counter(1 downto 0) = "10" then
CASE productive(7 downto 4) IS
WHEN "0000" =>
if productive(9 downto 8) < 01 then
Seg7(6 downto 0) <= "1111111";
else Seg7(6 downto 0) <= "1000000";
end if;
WHEN "0001" =>
Seg7(6 downto 0) <= "1111001";
WHEN "0010" =>
Seg7(6 downto 0) <= "0100100";
WHEN "0011" =>
Seg7(6 downto 0) <= "0011001";
WHEN "0100" =>
Seg7(6 downto 0) <= "0011001";
WHEN "0101" =>
Seg7(6 downto 0) <= "0010010";
WHEN "0110" =>
Seg7(6 downto 0) <= "0000010";
WHEN "0111" =>
Seg7(6 downto 0) <= "1111000";
WHEN "1000" =>
Seg7(6 downto 0) <= "0000000";
WHEN "1001" =>
Seg7(6 downto 0) <= "0010000";
WHEN OTHERS =>
Seg7(6 downto 0) <= "1111111";
END CASE;
elsif counter(1 downto 0) = "11" then
CASE productive(3 downto 0) IS
WHEN "0000" =>
Seg7(6 downto 0) <= "1111111";
WHEN "0001" =>
Seg7(6 downto 0) <= "1111001";
WHEN "0010" =>
Seg7(6 downto 0) <= "0100100";
WHEN "0011" =>
Seg7(6 downto 0) <= "0011001";
WHEN "0100" =>
Seg7(6 downto 0) <= "0011001";
WHEN "0101" =>
Seg7(6 downto 0) <= "0010010";
WHEN "0110" =>
Seg7(6 downto 0) <= "0000010";
WHEN "0111" =>
Seg7(6 downto 0) <= "1111000";
WHEN "1000" =>
Seg7(6 downto 0) <= "0000000";
WHEN "1001" =>
Seg7(6 downto 0) <= "0010000";
WHEN OTHERS =>
Seg7(6 downto 0) <= "1111111";
END CASE;
end if;
end loop;
end process;

end Behavioral;
```
Binary to BCD
```--------------------------------------------------------------------------------
---- Howard Community College Spring 2015 ENES-245 ----
---- This file is part of the Final Project lab ----
---- Description: Binary to Binary Coded Decimal, made by Brichard ----
---- Date: 4/27/2015 ----
---- Current Status: Complete ----
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity BinarytoDec is
port( product : out std_logic_vector(9 downto 0);
multiplicand : out std_logic_vector(4 downto 0);
multiplier : out std_logic_vector(4 downto 0));
end BinarytoDec;

architecture Behavioral of BinarytoDec is
COMPONENT AlgorithmicStateMachine
PORT( SD_Toggle : out STD_LOGIC);
END COMPONENT;

COMPONENT SharedCPURegisters
PORT( regOut : out STD_LOGIC_VECTOR(7 downto 0) );
END COMPONENT;

signal toggle : std_logic;
signal number : std_logic_vector(7 downto 0);
begin
Inst_AlgorithmicStateMachine: AlgorithmicStateMachine PORT MAP(
SD_TOGGLE => toggle
);
Inst_SharedCPURegisters: SharedCPURegisters PORT MAP(
regOut(7 downto 0) => number(7 downto 0));

bin_to_bcd : process (number, toggle)
variable z : STD_LOGIC_VECTOR(17 downto 0);
begin
while (toggle = '1') loop
multiplicand(4) <= (number(7) and (number(6) or number(5)));
multiplicand(3) <= (number(7) and not (number(6) or number(5)));
multiplicand(2) <= (number(6) and ((not number(7)) or number(5)));
multiplicand(1) <= ((number(5) and not number(7)) or (number(7) and number(6) and not number(5)));
multiplicand(0) <= number(4);
multiplier(4) <= (number(3) and (number(2) or number(1)));
multiplier(3) <= (number(3) and not (number(2) or number(1)));
multiplier(2) <= (number(2) and ((not number(3)) or number(1)));
multiplier(1) <= ((number(1) and not number(3)) or (number(3) and number(2) and not number(1)));
multiplier(0) <= number(0);
end loop;
while (toggle = '0') loop
for i in 0 to 17 loop
z(i) := '0';
end loop;
z(10 downto 3) := number(7 downto 0);

for i in 0 to 4 loop
if z(11 downto 0) > 4 then
z(11 downto 0) := (z(11 downto 8) + 3);
end if;
if z(15 downto 12) > 4 then
z(15 downto 12) := (z(15 downto 12) + 3);
end if;
z(17 downto 1) := z(16 downto 0);
end loop;
product <= z(17 downto 8);
end loop;
end process bin_to_bcd;
end Behavioral;
```

Operate

Why this project

Trace History In the early 70's, personal computers and calculators were both born. Calculators focused in math, personal computers on games. Steve Wozniak was at the center of this working for both HP and Atari in these early years. Personal computers did not do math fast or easily while calculators did math.

Build Intuition Hardware that did math gradually became part of computers through co-processors. Now all personal computers have CPU's with circuits that do math. The goal of this project is to show how circuits (not programs) multiply.

How to digitally Multiply

Engineers begin adding comments to find a pattern in how multiplying is done which looks like shifting and adding. Exploring this further:

Comparing the middle to the left, two things happened: shifting right instead of left and splitting the shift/add steps into two separate steps. The enabled:

• observation of a three step pattern:
2. temp subtotal
3. shift right (don't have to count how many)
• dual use of the left four bits .. which start off totally red ... and the red is shifted out after it is no longer useful
• left most red bit determines whether add or don't add
• a ninth bit to the left has to be added in case the adding results in a carry or 5th most significant digit
How to use the Papilio with LogicStart MegaShield
1. press the joystick until the left most LED's are off and '---' is displayed
2. flick the eight switches to form two binary numbers
3. press the joystick and watch the adding and shifting
4. when a number is displayed, then the answer has been computed and is in binary in the LED's
The following presentation shows how to use the ASM to build the multiplier:

Demo

• Presentation
• Video of how multiplying works when using the IEEE VHDL arith.all library.
• Here is the demo of the multiplication using the papilio. we start with everything at zero, the four left most switches control the two leftmost digits(A value from 0 to 15 in decimal is displayed), and the four rightmost switches control the two rightmost digits(A value from 0-15 is also displayed here), once the combination is entered, the joystick is pressed, and the result from the multiplication is shown.

on only 3 digits because the maximum number we can have is 225 when all the switches are up.

Next Steps

Just one piece of this circuit has been built and then it was redesigned. The current design needs to be built.