码迷,mamicode.com
首页 > 其他好文 > 详细

SAP computer之program counter

时间:2015-06-18 19:12:27      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:

  Program counter

  The program is stored in memory with the first instruction at binary address 0000, the second instruction at address 0001, the third at address 0010 and so on.  The program counter, which is part of the control unit, counts from 0000 to 1111. Its job is to send to the memory the address of next instruction. 

  The program counter is reset to 0000 before computer run. When the computer run begins, the program counter sends address 0000 to the memory. The program counter is then incremented to get 0001. After the first instruction is fetched and executed, the program counter sends address 0001 to the memory. Again the program counter is incremented. After the second isntruction is fetched and executed, the program counter sends address 0010 to the memory. In this way, the program counter is keeping track of the next instruction to be fetched and executed.

  The program counter is like someone pointing at a list of instruction, saying do this first, do this second, etc. This is why the program counter is sometimes called a pointer; it points to an address in memory where something important is being stored.

 

 1 library IEEE;
 2 use ieee.std_logic_1164.all;
 3 use ieee.std_logic_unsigned.all;
 4 
 5 entity PC is
 6 port 
 7 (    
 8     ep    : in  std_logic;                     --! Active high output enable from PC, or tri-state
 9     clr    : in  std_logic;                     --! Active high asynchronous clear
10     clk    : in  std_logic;                     --! Falling edge clock
11     cp    : in  std_logic;                     --! Active high enable PC to count
12     q     : out std_logic_vector(3 downto 0)   --! 4-bit PC output
13 );    
14 end PC ;
15 
16 architecture beh of PC is
17 
18 signal count : std_logic_vector(3 downto 0);
19 
20 begin
21 
22 process (clr,ep,cp,clk,count)
23 begin
24     if clr = 1 then
25         q <= "0000";
26         count <= "0000";
27     elsif cp = 1 then
28          if (clkevent and clk = 0) then
29             if count < "1111" then count <= count + 1;
30             else count <= "0000";
31             end if;
32         end if; 
33      end if;
34     
35     if ep = 0 then 
36         q <= "ZZZZ";
37     else        
38         q <= count;
39     end if;
40 
41 end process; 
42 
43 end beh;

 

SAP computer之program counter

标签:

原文地址:http://www.cnblogs.com/mengdie/p/4586511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!