Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Help with creating a very small CPU

 
Thread Tools Search this Thread
Old 02-17-2009, 08:19 PM   #1
Default Help with creating a very small CPU


Disclaimer: I'm fairly new to VHDL

I am trying to do operations on my accumulator using different bits of
the instruction register. For instance, bit 2 will clear A and bit 3
will increment A. I want these operations to be able to happen in one
cycle with one instruction in order (e.g. Clear A, then increment).
This piece of code is what I came up with but it will only do one of
the operations, not both. I could break these down into different
clock cycles, but I'm hoping there is a way to do it in one. Any
ideas?

process (clk) begin
if rising_edge (clk) then
if en_execute = '1' then
if IR(2) = '1' then --clear accumulator
A <= "00000000";
end if;

if IR(3) = '1' then --increment accumulator
A <= A + 1;
end if;
end if;
end if;
end process;


TweedleDee
  Reply With Quote
Old 02-17-2009, 08:26 PM   #2
kennheinrich@sympatico.ca
 
Posts: n/a
Default Re: Help with creating a very small CPU
On Feb 17, 3:19*pm, TweedleDee <iliveinatrailerp...@yahoo.com> wrote:
> Disclaimer: I'm fairly new to VHDL
>
> I am trying to do operations on my accumulator using different bits of
> the instruction register. *For instance, bit 2 will clear A and bit 3
> will increment A. *I want these operations to be able to happen in one
> cycle with one instruction in order (e.g. Clear A, then increment).
> This piece of code is what I came up with but it will only do one of
> the operations, not both. *I could break these down into different
> clock cycles, but I'm hoping there is a way to do it in one. *Any
> ideas?
>
> process (clk) begin
> * * if rising_edge (clk) then
> * * * if en_execute = '1' then
> * * * * *if IR(2) = '1' then * *--clear accumulator
> * * * * * * A <= "00000000";
> * * * * *end if;
>
> * * * * *if IR(3) = '1' then * *--increment accumulator
> * * * * * * A <= A + 1;
> * * * * *end if;
> * * * end if;
> * * end if;
> end process;



Variables can be used to hold intermediate results, so everything
happens in one clock cycle:

process (clk)
variable tmpA : T; -- T is whatever type A is
begin
if rising_edge (clk) then
if en_execute = '1' then
tmpA := A; -- starting off fresh!
if IR(2) = '1' then --clear accumulator
tmpA <= "00000000"; -- use tmpA!
end if;

if IR(3) = '1' then --increment accumulator
tmpA <= tmpA + 1; -- use tmpA!
end if;
A <= tmpA; -- all done!

end if;
end if;
end process;

Of course, if you want to dynamically change the order you'll need
more bits and more complicated decoding.

HTH,

- Kenn


kennheinrich@sympatico.ca
  Reply With Quote
Old 02-17-2009, 08:32 PM   #3
kennheinrich@sympatico.ca
 
Posts: n/a
Default Re: Help with creating a very small CPU
On Feb 17, 3:26*pm, kennheinr...@sympatico.ca wrote:
> On Feb 17, 3:19*pm, TweedleDee <iliveinatrailerp...@yahoo.com> wrote:
>
>
>
> > Disclaimer: I'm fairly new to VHDL

>
> > I am trying to do operations on my accumulator using different bits of
> > the instruction register. *For instance, bit 2 will clear A and bit 3
> > will increment A. *I want these operations to be able to happen in one
> > cycle with one instruction in order (e.g. Clear A, then increment).
> > This piece of code is what I came up with but it will only do one of
> > the operations, not both. *I could break these down into different
> > clock cycles, but I'm hoping there is a way to do it in one. *Any
> > ideas?

>
> > process (clk) begin
> > * * if rising_edge (clk) then
> > * * * if en_execute = '1' then
> > * * * * *if IR(2) = '1' then * *--clear accumulator
> > * * * * * * A <= "00000000";
> > * * * * *end if;

>
> > * * * * *if IR(3) = '1' then * *--increment accumulator
> > * * * * * * A <= A + 1;
> > * * * * *end if;
> > * * * end if;
> > * * end if;
> > end process;

>
> Variables can be used to hold intermediate results, so everything
> happens in one clock cycle:
>
> process (clk)
> * variable tmpA : T; -- T is whatever type A is
> begin
> * * *if rising_edge (clk) then
> * * * *if en_execute = '1' then
> * * * * * tmpA := A; -- starting off fresh!
> * * * * * if IR(2) = '1' then * *--clear accumulator
> * * * * * * *tmpA <= "00000000"; -- use tmpA!
> * * * * * end if;
>
> * * * * * if IR(3) = '1' then * *--increment accumulator
> * * * * * * *tmpA <= tmpA + 1; -- use tmpA!
> * * * * * end if;
> * * * * A <= tmpA; -- all done!
>
> * * * *end if;
> * * *end if;
> *end process;
>
> Of course, if you want to dynamically change the order you'll need
> more bits and more complicated decoding.
>
> HTH,
>
> *- Kenn


Oops, forgot to finish the edits! Variables are always assigned using
the ":=" instead of the "<=" operator, so change the above to read:

tmpA := "00000000"; -- use tmpA!

tmpA := tmpA + 1; -- use tmpA!


- Kenn


kennheinrich@sympatico.ca
  Reply With Quote
Old 02-17-2009, 08:44 PM   #4
TweedleDee
 
Posts: n/a
Default Re: Help with creating a very small CPU
Excellent! Thank you! I'll give a try.


TweedleDee
  Reply With Quote
Old 02-17-2009, 10:24 PM   #5
Mike Treseler
 
Posts: n/a
Default Re: Help with creating a very small CPU
wrote:

> if IR(2) = '1' then --clear accumulator
> tmpA <= "00000000"; -- use tmpA!

^^ ^^^
:= assign

> if IR(3) = '1' then --increment accumulator
> tmpA <= tmpA + 1; -- use tmpA!

^^
:=


Mike Treseler
  Reply With Quote
Old 02-19-2009, 08:18 AM   #6
Pieter Hulshoff
 
Posts: n/a
Default Re: Help with creating a very small CPU
TweedleDee wrote:
> I am trying to do operations on my accumulator using different bits of
> the instruction register. For instance, bit 2 will clear A and bit 3
> will increment A. I want these operations to be able to happen in one
> cycle with one instruction in order (e.g. Clear A, then increment).
> This piece of code is what I came up with but it will only do one of
> the operations, not both. I could break these down into different
> clock cycles, but I'm hoping there is a way to do it in one. Any
> ideas?
>
> process (clk) begin
> if rising_edge (clk) then
> if en_execute = '1' then
> if IR(2) = '1' then --clear accumulator
> A <= "00000000";
> end if;
>
> if IR(3) = '1' then --increment accumulator
> A <= A + 1;
> end if;
> end if;
> end if;
> end process;



IF ir(2) = '1' AND ir(3) = '1' THEN
a <= "00000001";
ELSIF ir(2) = '1' THEN
a <= "00000000";
ELSIF ir(3) = '1' THEN
a <= a + 1;
END IF;

or

CASE ir(3 DOWNTO 2) IS
WHEN "01" => a <= "00000000";
WHEN "10" => a <= a + 1;
WHEN "11" => a <= "00000001";
WHEN OTHERS => NULL;
END CASE;

Kind regards,

Pieter Hulshoff


Pieter Hulshoff
  Reply With Quote
Old 02-19-2009, 10:12 AM   #7
jacko
 
Posts: n/a
Default Re: Help with creating a very small CPU
On 17 Feb, 20:19, TweedleDee <iliveinatrailerp...@yahoo.com> wrote:
> Disclaimer: I'm fairly new to VHDL
>
> I am trying to do operations on my accumulator using different bits of
> the instruction register. *For instance, bit 2 will clear A and bit 3
> will increment A. *I want these operations to be able to happen in one
> cycle with one instruction in order (e.g. Clear A, then increment).
> This piece of code is what I came up with but it will only do one of
> the operations, not both. *I could break these down into different
> clock cycles, but I'm hoping there is a way to do it in one. *Any
> ideas?
>
> process (clk) begin
> * * if rising_edge (clk) then
> * * * if en_execute = '1' then
> * * * * *if IR(2) = '1' then * *--clear accumulator
> * * * * * * A <= "00000000";
> * * * * *end if;
>
> * * * * *if IR(3) = '1' then * *--increment accumulator
> * * * * * * A <= A + 1;
> * * * * *end if;
> * * * end if;
> * * end if;
> end process;


Do bare in mind that such a thing may expand to many cascaded logic
operations bypassed by a two way multiplexer, cascaded together. Such
an arrangement may reduce the Fmax of the CPU significantly. A full
expansion of the logic functions may lead to quite a large CPU, but
faster. You may find a pipeline at each stage (or IR bit) keeps the
size small (register in mux LUT cell), so no real extra logic appart
from delay line for bits of IR. Significant differences in execution
time of logic operations, can limit design Fmax to lowest speed of all
ops. Making the slowest op take 2 pipeline clocks can often boost
performance.

cheers jacko

http://nibz.googlecode.com VHDL microprocessor. *****<570 Altera
LEs***** (16 bit), 20MHz in C5 grade MAXIIZ, 40 I/O pins (programmable
direction), Clocked Counter...


jacko
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
DVD Data only writes a small amount, and then freezes. xx75vulcan@juno.com DVD Video 0 03-17-2006 03:54 AM
Small crack in a DVD, will it get worse? dvd_newbie DVD Video 31 07-18-2005 05:46 PM
Small cracks in the transparent center of DVDs? Rose DVD Video 0 04-06-2004 12:17 AM
Wanting to start small computer business Rob A+ Certification 4 02-24-2004 04:13 PM
Re: How common are small surface defects on blank DVD-R media? Will Dumes DVD Video 1 07-27-2003 08:07 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46