0% found this document useful (0 votes)
6 views10 pages

Presentation 10

Uploaded by

maryamjfr4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Presentation 10

Uploaded by

maryamjfr4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

‫ادامه فصل دوم‬

‫نگاهی به زبان توصیف سخت افزار ‪VHDL‬‬


‫حلقه ‪: LOOP‬‬
‫فرم کلی‪: Loop‬‬
‫‪ Loop‬روش تکرار]‪ :‬برچسب[‬
‫عبارت‪1‬‬
‫عبارت‪2‬‬
‫عبارت ‪n‬‬
‫;]برچسب[ ‪End loop‬‬
‫سه فرم ‪: loop‬‬
‫‪For…loop‬‬
‫‪While… loop‬‬
‫‪ Loop‬ساده‬
‫سمیرا سعیدی نیمسال دوم ‪1399-1398‬‬ ‫‪2‬‬
‫حلقه ‪: for…loop‬‬

‫‪ Loop‬محدوده عمل‪] for i‬برچسب[‬


‫عبارت ‪1‬‬
‫عبارت ‪2‬‬
‫عبارت ‪3‬‬
‫;]برچسب[ ‪End loop‬‬

‫سمیرا سعیدی نیمسال دوم ‪1399-1398‬‬ ‫‪3‬‬


‫مثال) برنامه ای بنویسید که عناصر دو آرایه چهار عنصری ‪ a‬و‪ b‬را با هم مقایسه‬
‫کند‪،‬و در صورتی که نظیر به نظیرعناصر دو آرایه با هم برابر بودند خروجی ‪m‬‬
‫را ‪ 1‬کند‪.‬‬

‫سمیرا سعیدی نیمسال دوم ‪1399-1398‬‬ ‫‪4‬‬


Entity comp4 is
Port( a,b: in bit_vector (3downto 0);
m: out bit);
End;
Architecture behaviour of comp4 is
Signal equals:bit_vector(3 downto 0);
Begin
Process(a,b)
Begin
For i in 3 downto 0 loop
Equals(i)<=a(i) xnor b(i);
End loop;
End process;
m<=equals(3) and equals(2) and equals(1) and equals(0);
End behaviour;

1399-1398 ‫سمیرا سعیدی نیمسال دوم‬ 5


range,reverse_range,Length ‫کاربرد صفات‬

For I in integer range 3 downto 0 loop;

Signal a:bit_vector(3 downto 0 );


For I in a’range loop;

For I in a’reverse_range loop;


For I in 0 to 3 loop;

For I in 0 to a’Length-1 loop;

1399-1398 ‫سمیرا سعیدی نیمسال دوم‬ 6


for…loop ‫ درحلقه‬Exit ‫عبارت‬
Process (a)
variable int_a:integer;
begin
int_a:=a;
for I in 0 to 50 loop
if (int_a <=0) then
exit;
else
int_a:=int_a -1;
end if;
end loop;
end pocess;

exit[‫[ ]برچسب‬when‫]شرط‬

1399-1398 ‫سمیرا سعیدی نیمسال دوم‬ 7


for…loop ‫ در حلقه‬Next ‫عبارت‬
Process (a,b)
begin
for i in 0 to 50 loop
if (done (i) =true) then
next;
else
done (i) :=true;
end if;
q(i) <=a(i) AND b(i) ;
end loop;
End process;

next[‫[ ]برچسب‬when‫]شرط‬

1399-1398 ‫سمیرا سعیدی نیمسال دوم‬ 8


While…loop ‫حلقه‬
Process
begin
while (‫ (شرط‬loop
.‫عبارات پشت سر هم اجرا می شوند‬
end loop;
end process;
‫مثال‬
Process
variable clock : bit:=‘0’;
Begin
while error_flag=‘0’ loop
Clock := NOT clock after 50 ns;
end loop;
End process

1399-1398 ‫سمیرا سعیدی نیمسال دوم‬ 9


‫ ساده‬loop ‫حلقه‬
exit ‫استفاده از‬
Process
-------
begin
---------
loop
------
exit;

end loop;
------------
End process

1399-1398 ‫سمیرا سعیدی نیمسال دوم‬ 10

You might also like