找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4699|回复: 10
收起左侧

如何用Quartus做一个简单的CPU?VHDL语言实现

[复制链接]
ID:393004 发表于 2018-9-4 10:33 | 显示全部楼层 |阅读模式
50黑币
坛子里的各位大神帮帮忙哈,硬件课程设计的实验,quartus设计一个简单的cpu,要求用VHDL语言
因为之前没有学习过cpu相关知识,VHDL也刚开始接触,结果就是完全不知道怎么下手。。指令构造&内部结构分别是什么鬼、干嘛的,等等如此不明觉厉。。然鹅后天就要验机,走投无路只得请高人相助了。。
哪位大神要是有闲情逸致,下海出山秀秀操作吧
实验具体要求放在附件里,好心人&有缘人帮帮忙咯~如果大神实在觉得做的麻烦,指点我一下也可以了
感激不尽!!!

实验要求.docx

12.72 KB, 下载次数: 23

回复

使用道具 举报

ID:386367 发表于 2018-9-4 11:58 | 显示全部楼层
看到要求,只是要设计,不是真正的实作,这并不难。
难在是你时间不够,什麽都要重新学。
或许这本书可帮到你:[计算机系统要素:从零开始构建现代计算机].(尼萨)

评分

参与人数 1黑币 +30 收起 理由
admin + 30 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:393004 发表于 2018-9-4 12:41 | 显示全部楼层
tt123 发表于 2018-9-4 11:58
看到要求,只是要设计,不是真正的实作,这并不难。
难在是你时间不够,什麽都要重新学。
或许这本书可帮 ...

谢谢小哥哥~确实感觉时间很紧张了。。
要是方便的话,能不能具体讲解一下思路呢?
回复

使用道具 举报

ID:275479 发表于 2018-9-4 16:47 | 显示全部楼层
难了,做一个51吧,之前听说过,时间太紧了,做51需要下载IP核
回复

使用道具 举报

ID:393354 发表于 2018-9-4 16:53 | 显示全部楼层
难度大,时间紧
回复

使用道具 举报

ID:386367 发表于 2018-9-4 19:44 | 显示全部楼层
poltawa 发表于 2018-9-4 12:41
谢谢小哥哥~确实感觉时间很紧张了。。
要是方便的话,能不能具体讲解一下思路呢?

其实你附上的要求,就是思路。
你将每一点要求转化成"什麽"或者"怎样"的问题,然後顺序,一个一个回答就可。
大部份问题,百度一下就可以。

细看之下,原来还要实作,那不是短时间就能做出来的....
你可以叁考51的结构,实作几个简单的指令,如ADD,MOV ....


评分

参与人数 1黑币 +50 收起 理由
admin + 50 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:155507 发表于 2018-9-4 20:15 | 显示全部楼层
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.all;
  3. use IEEE.numeric_std.all;
  4. use work.States.all;

  5. entity cpu is
  6.    port(
  7.     reset :         in   STD_LOGIC;
  8.     sw0 :         in   STD_LOGIC;
  9.            start :         in   STD_LOGIC;
  10.         clk :         in   STD_LOGIC;
  11.         output1: out STd_logic_vector(6 downto 0);
  12.         output2: out STd_logic_vector(6 downto 0);
  13.         output3: out STd_logic_vector(6 downto 0);
  14.         output4: out STd_logic_vector(6 downto 0);
  15.         output5: out STd_logic_vector(6 downto 0);
  16.         output6: out STd_logic_vector(6 downto 0);
  17.         test0: out STd_logic;
  18.         test1: out STd_logic;
  19.         Z: out STd_logic
  20.        );
  21. end cpu;

  22. architecture behavioral of cpu is

  23. function convSEG (N : std_logic_vector(3 downto 0) ) return std_logic_vector is
  24. variable ans:std_logic_vector(6 downto 0);
  25. begin
  26. Case N is
  27. when "0000" => ans:="1000000";
  28. when "0001" => ans:="1111001";
  29. when "0010" => ans:="0100100";
  30. when "0011" => ans:="0110000";
  31. when "0100" => ans:="0011001";
  32. when "0101" => ans:="0010010";
  33. when "0110" => ans:="0000010";
  34. when "0111" => ans:="1111000";
  35. when "1000" => ans:="0000000";
  36. when "1001" => ans:="0010000";
  37. when "1010" => ans:="0001000";
  38. when "1011" => ans:="0000011";
  39. when "1100" => ans:="1000110";
  40. when "1101" => ans:="0100001";
  41. when "1110" => ans:="0000110";
  42. when "1111" => ans:="0001110";
  43. when others=> ans:="1111111";
  44. end case;
  45. return ans;
  46. end function convSEG;

  47. type MEMtype is array (0 to 2**16-1) of std_logic_vector(7 downto 0);
  48. constant ROM : MEMtype := (
  49. "00001011",
  50. "00000001",
  51. "00000000",
  52. "00100000",
  53. "00000011",
  54. "00000001",
  55. "00000000",
  56. "00100001",
  57. "00001000",
  58. "00000111",
  59. "00000000",
  60. "00010000",
  61. "00001100",
  62. "00000101",
  63. "00000000",
  64. "00010010",
  65. "00001001",
  66. "00000000",
  67. "00000000",
  68. "00000000",
  69. "00000000",
  70. "00000000",
  71. "00000000",
  72. "00000000",
  73. "00000000",
  74. "00000000",
  75. "00000000",
  76. "00000000",
  77. "00000000",
  78. "00000000",
  79. "00000000",
  80. "00000000",
  81. "00000101",
  82. "00001010",
  83. others => "00000000" );

  84. signal P_S : myState;  
  85. signal N_S : myState;
  86. signal AR_REGISTER  :STd_logic_vector(15 downto 0);
  87. signal AC_REGISTER  :STd_logic_vector(7 downto 0);
  88. signal IR_REGISTER  :STd_logic_vector(7 downto 0);
  89. signal PC_REGISTER  :STd_logic_vector(15 downto 0);
  90. signal R_REGISTER  :STd_logic_vector(7 downto 0);
  91. signal TR_REGISTER  :STd_logic_vector(7 downto 0);
  92. signal Z_FLAG  :STd_logic;
  93. signal DR_REGISTER  :STd_logic_vector(7 downto 0);
  94. signal RAM  :MEMtype;
  95. signal Delay_count : integer := 0;
  96. signal en : STd_logic := '0';
  97. signal temp : STd_logic_vector(1 downto 0);
  98. signal Mem_count : integer := 0;

  99. begin
  100.         --FSM structure process
  101.         process(clk , reset)
  102.         begin
  103.                 if (reset = '0') then
  104.                         P_S <= RESET1;
  105.                 elsif (rising_edge(clk)) then
  106.                         P_S <= N_S;
  107.                 end if;
  108.         end process;
  109.        
  110.         --FSM transport process
  111.         process(P_S , IR_REGISTER, Z_FLAG, start, en, Mem_count)
  112.         begin
  113.                 N_S <= P_S;
  114.                 case P_S is
  115.                         when RESET1 =>
  116.                                 N_S <= MEM_INIT;
  117.                                 temp  <= "00";
  118.                         when MEM_INIT =>
  119.                                 if (Mem_count = 2**16-1) then
  120.                                         N_S <= FINISH;
  121.                                  end if;
  122.                                 temp  <= "01";
  123.                         when FINISH =>
  124.                                 if (start = '0') then
  125.                                 N_S <= FETCH1;
  126.                                 end if;
  127.                                 temp  <= "10";
  128.                         when FETCH1 =>
  129.                                 if( en = '1' )then
  130.                                 N_S <= FETCH2;       
  131.                                 end if;
  132.                                 temp  <= "11";
  133.                         when FETCH2 =>
  134.                                 if( en = '1' )then
  135.                                 N_S <= FETCH3;                       
  136.                                 end if;
  137.                                 temp  <= "00";
  138.                         when FETCH3 =>
  139.                                 if( en = '1' )then
  140.                                 if (IR_REGISTER="00000000") then
  141.                                         N_S <= NOP1;
  142.                                 elsif (IR_REGISTER="00000001") then
  143.                                         N_S <= LDAC1;
  144.                                 elsif (IR_REGISTER="00000010") then
  145.                                         N_S <= STAC1;
  146.                                 elsif (IR_REGISTER="00000011") then
  147.                                         N_S <= MVAC1;
  148.                                 elsif (IR_REGISTER="00000100") then
  149.                                         N_S <= MOVR1;
  150.                                 elsif (IR_REGISTER="00000101") then
  151.                                         N_S <= JUMP1;
  152.                                 elsif (IR_REGISTER="00000110" AND Z_FLAG='1') then
  153.                                         N_S <= JMPZY1;
  154.                                 elsif (IR_REGISTER="00000110" AND Z_FLAG='0') then
  155.                                         N_S <= JMPZN1;
  156.                                 elsif (IR_REGISTER="00000111" AND Z_FLAG='0') then
  157.                                         N_S <= JPNZY1;
  158.                                 elsif (IR_REGISTER="00000111" AND Z_FLAG='1') then
  159.                                         N_S <= JPNZN1;
  160.                                 elsif (IR_REGISTER="00001000") then
  161.                                         N_S <= ADD1;
  162.                                 elsif (IR_REGISTER="00001001") then
  163.                                         N_S <= SUB1;
  164.                                 elsif (IR_REGISTER="00001010") then
  165.                                         N_S <= INAC1;
  166.                                 elsif (IR_REGISTER="00001011") then
  167.                                         N_S <= CLAC1;
  168.                                 elsif (IR_REGISTER="00001100") then
  169.                                         N_S <= AND1;
  170.                                 elsif (IR_REGISTER="00001101") then
  171.                                         N_S <= OR1;
  172.                                 elsif (IR_REGISTER="00001110") then
  173.                                         N_S <= XOR1;
  174.                                 elsif (IR_REGISTER="00001111") then
  175.                                         N_S <= NOT1;
  176.                                 end if;
  177.                                 end if;
  178.                                                
  179.                         when NOP1  =>
  180.                                 if( en = '1' )then
  181.                                 N_S <= FETCH1;
  182.                                 end if;
  183.                         when LDAC1  =>
  184.                                 if( en = '1' )then
  185.                                 N_S <= LDAC2;
  186.                                 end if;
  187.                         when LDAC2  =>
  188.                                 if( en = '1' )then
  189.                                 N_S <= LDAC3;
  190.                                 end if;
  191.                         when LDAC3  =>
  192.                                 if( en = '1' )then
  193.                                 N_S <= LDAC4;
  194.                                 end if;
  195.                         when LDAC4  =>
  196.                                 if( en = '1' )then
  197.                                 N_S <= LDAC5;
  198.                                 end if;
  199.                         when LDAC5  =>
  200.                                 if( en = '1' )then
  201.                                 N_S <= FETCH1;
  202.                                 end if;
  203.                         when STAC1  =>
  204.                                 if( en = '1' )then
  205.                                 N_S <= STAC2;
  206.                                 end if;
  207.                         when STAC2  =>
  208.                                 if( en = '1' )then
  209.                                 N_S <= STAC3;
  210.                                 end if;
  211.                         when STAC3  =>
  212.                                 if( en = '1' )then
  213.                                 N_S <= STAC4;
  214.                                 end if;
  215.                         when STAC4  =>
  216.                                 if( en = '1' )then
  217.                                 N_S <= STAC5;
  218.                                 end if;
  219.                         when STAC5  =>
  220.                                 if( en = '1' )then
  221.                                 N_S <= FETCH1;
  222.                                 end if;
  223.                         when MVAC1  =>
  224.                                 if( en = '1' )then
  225.                                 N_S <= FETCH1;
  226.                                 end if;
  227.                         when MOVR1  =>
  228.                                 if( en = '1' )then
  229.                                 N_S <= FETCH1;
  230.                                 end if;
  231.                         when JUMP1  =>
  232.                                 if( en = '1' )then
  233.                                 N_S <= JUMP2;
  234.                                 end if;
  235.                         when JUMP2  =>
  236.                                 if( en = '1' )then
  237.                                 N_S <= JUMP3;
  238.                                 end if;
  239.                         when JUMP3  =>
  240.                                 if( en = '1' )then
  241.                                 N_S <= FETCH1;
  242.                                 end if;
  243.                         when JMPZY1  =>
  244.                                 if( en = '1' )then
  245.                                 N_S <= JMPZY2;
  246.                                 end if;
  247.                         when JMPZY2  =>
  248.                                 if( en = '1' )then
  249.                                 N_S <= JMPZY3;
  250.                                 end if;
  251.                         when JMPZY3  =>
  252.                                 if( en = '1' )then
  253.                                 N_S <= FETCH1;
  254.                                 end if;
  255.                         when JMPZN1  =>
  256.                                 if( en = '1' )then
  257.                                 N_S <= JMPZN2;
  258.                                 end if;
  259.                         when JMPZN2  =>
  260.                                 if( en = '1' )then
  261.                                 N_S <= FETCH1;
  262.                                 end if;
  263.                         when JPNZY1  =>
  264.                                 if( en = '1' )then
  265.                                 N_S <= JPNZY2;
  266.                                 end if;
  267.                         when JPNZY2  =>
  268.                                 if( en = '1' )then
  269.                                 N_S <= JPNZY3;
  270.                                 end if;
  271.                         when JPNZY3  =>
  272.                                 if( en = '1' )then
  273.                                 N_S <= FETCH1;
  274.                                 end if;
  275.                         when JPNZN1  =>
  276.                                 if( en = '1' )then
  277.                                 N_S <= JPNZN2;
  278.                                 end if;
  279.                         when JPNZN2  =>
  280.                                 if( en = '1' )then
  281.                                 N_S <= FETCH1;
  282.                                 end if;
  283.                         when ADD1  =>
  284.                                 if( en = '1' )then
  285.                                 N_S <= FETCH1;
  286.                                 end if;
  287.                         when SUB1  =>
  288.                                 if( en = '1' )then
  289.                                 N_S <= FETCH1;
  290.                                 end if;
  291.                         when INAC1  =>
  292.                                 if( en = '1' )then
  293.                                 N_S <= FETCH1;
  294.                                 end if;
  295.                         when CLAC1  =>
  296.                                 if( en = '1' )then
  297.                                 N_S <= FETCH1;
  298.                                 end if;
  299.                         when AND1  =>
  300.                                 if( en = '1' )then
  301.                                 N_S <= FETCH1;
  302.                                 end if;
  303.                         when OR1  =>
  304.                                 if( en = '1' )then
  305.                                 N_S <= FETCH1;
  306.                                 end if;
  307.                         when XOR1  =>
  308.                                 if( en = '1' )then
  309.                                 N_S <= FETCH1;
  310.                                 end if;
  311.                         when NOT1  =>
  312.                                 if( en = '1' )then
  313.                                 N_S <= FETCH1;
  314.                                 end if;
  315.                 end case;
  316.         end process;
  317.        
  318.         --manage AC_REGISTER
  319.         process(clk, reset)
  320.         begin
  321.                 if(reset = '0')then
  322.                         AC_REGISTER  <= (others => '0');
  323.                 elsif (falling_edge(clk) and en = '1')then
  324.                         AC_REGISTER  <= AC_REGISTER ;
  325.                         case P_S is                                                       
  326.                         when MEM_INIT =>
  327.                                 AC_REGISTER(7 downto 4) <= "0011";
  328.                                 AC_REGISTER(3 downto 0) <= "0011";
  329.                         when LDAC5  =>
  330.                                 AC_REGISTER  <= DR_REGISTER ;
  331.                         when MOVR1  =>
  332.                                 AC_REGISTER  <= R_REGISTER ;
  333.                         when ADD1  =>
  334.                                 AC_REGISTER  <= std_logic_vector(unsigned(AC_REGISTER) + unsigned(R_REGISTER));
  335.                         when SUB1  =>
  336.                                 AC_REGISTER  <= std_logic_vector(unsigned(AC_REGISTER) - unsigned(R_REGISTER));
  337.                         when INAC1  =>
  338.                                 AC_REGISTER  <= std_logic_vector(unsigned(AC_REGISTER) + 1);
  339.                         when CLAC1  =>
  340.                                 AC_REGISTER  <= (others => '0');
  341.                         when AND1  =>
  342.                                 AC_REGISTER  <= AC_REGISTER  AND R_REGISTER ;
  343.                         when OR1  =>
  344.                                 AC_REGISTER  <= AC_REGISTER  OR R_REGISTER ;
  345.                         when XOR1  =>
  346.                                 AC_REGISTER  <= AC_REGISTER  XOR R_REGISTER ;
  347.                         when NOT1  =>
  348.                                 AC_REGISTER  <= NOT AC_REGISTER ;
  349.                         when others =>
  350.                 end case;
  351.                 end if;               
  352.         end process;
  353.        
  354.         --manage PC_REGISTER
  355.         process(clk, reset)
  356.         begin
  357.                 if(reset = '0')then
  358.                         PC_REGISTER  <= (others => '0');
  359.                 elsif (falling_edge(clk) and en = '1')then
  360.                         PC_REGISTER  <= PC_REGISTER ;
  361.                        
  362.                         case P_S is
  363.                         when FETCH2 =>
  364.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  365.                         when LDAC1  =>
  366.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  367.                         when LDAC2  =>
  368.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  369.                         when STAC1  =>
  370.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  371.                         when STAC2  =>
  372.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  373.                         when JUMP3  =>
  374.                                 PC_REGISTER(15 downto 8) <= TR_REGISTER;
  375.                                 PC_REGISTER(7 downto 0) <= DR_REGISTER;
  376.                         when JMPZY3  =>
  377.                                 PC_REGISTER(15 downto 8) <= TR_REGISTER;
  378.                                 PC_REGISTER(7 downto 0) <= DR_REGISTER;
  379.                         when JMPZN1  =>
  380.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  381.                         when JMPZN2  =>
  382.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  383.                         when JPNZY3  =>
  384.                                 PC_REGISTER(15 downto 8) <= TR_REGISTER;
  385.                                 PC_REGISTER(7 downto 0) <= DR_REGISTER;
  386.                         when JPNZN1  =>
  387.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  388.                         when JPNZN2  =>
  389.                                 PC_REGISTER  <= std_logic_vector(unsigned(PC_REGISTER) +1);
  390.                         when others =>
  391.                 end case;
  392.                 end if;               
  393.         end process;
  394.        
  395.         --manage AR_REGISTER
  396.         process(clk, reset)
  397.         begin
  398.                 if(reset = '0')then
  399.                         AR_REGISTER  <= (others => '0');
  400.                 elsif (falling_edge(clk) and en = '1')then
  401.                         AR_REGISTER  <= AR_REGISTER ;
  402.                        
  403.                         case P_S is
  404.                         when FETCH1 =>
  405.                                 AR_REGISTER  <= PC_REGISTER ;
  406.                         when FETCH3 =>
  407.                                 AR_REGISTER  <= PC_REGISTER ;
  408.                         when LDAC1  =>
  409.                                 AR_REGISTER  <= std_logic_vector(unsigned(AR_REGISTER) +1);
  410.                         when LDAC3  =>
  411.                                 AR_REGISTER(15 downto 8) <= TR_REGISTER;
  412.                                 AR_REGISTER(7 downto 0) <= DR_REGISTER;
  413.                         when STAC1  =>
  414.                                 AR_REGISTER  <= std_logic_vector(unsigned(AR_REGISTER) +1);
  415.                         when STAC3  =>
  416.                                 AR_REGISTER(15 downto 8) <= TR_REGISTER;
  417.                                 AR_REGISTER(7 downto 0) <= DR_REGISTER;
  418.                         when JUMP1  =>
  419.                                 AR_REGISTER  <= std_logic_vector(unsigned(AR_REGISTER) +1);
  420.                         when JMPZY1  =>
  421.                                 AR_REGISTER  <= std_logic_vector(unsigned(AR_REGISTER) +1);
  422.                         when JPNZY1  =>
  423.                                 AR_REGISTER  <= std_logic_vector(unsigned(AR_REGISTER) +1);
  424.                         when others =>
  425.                 end case;
  426.                 end if;               
  427.         end process;
  428.        
  429.         --manage DR_REGISTER
  430.        
  431.         process(clk, reset)
  432.         begin
  433.                 if(reset = '0')then
  434.                         DR_REGISTER  <= (others => '0');
  435.                 elsif (falling_edge(clk))then
  436.                         DR_REGISTER  <= DR_REGISTER ;
  437.                        
  438.                         case P_S is
  439.                         when FETCH2 =>
  440.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  441.                         when LDAC1  =>
  442.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  443.                         when LDAC2  =>
  444.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  445.                         when LDAC4  =>
  446.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  447.                         when STAC1  =>
  448.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  449.                         when STAC2  =>
  450.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  451.                         when STAC4  =>
  452.                                 DR_REGISTER  <= AC_REGISTER ;
  453.                         when JUMP1  =>
  454.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  455.                         when JUMP2  =>
  456.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  457.                         when JMPZY1  =>
  458.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  459.                         when JMPZY2  =>
  460.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  461.                         when JPNZY1  =>
  462.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  463.                         when JPNZY2  =>
  464.                                 DR_REGISTER  <= RAM(to_integer(unsigned(AR_REGISTER)));
  465.                         when others =>
  466.                 end case;
  467.                 end if;               
  468.         end process;
  469.        
  470.         --manage TR_REGISTER
  471.         process(clk, reset)
  472.         begin
  473.                 if(reset = '0')then
  474.                         TR_REGISTER  <= (others => '0');
  475.                 elsif (falling_edge(clk))then
  476.                         TR_REGISTER  <= TR_REGISTER ;
  477.                        
  478.                         case P_S is
  479.                         when LDAC2  =>
  480.                                 TR_REGISTER  <= DR_REGISTER ;
  481.                         when STAC2  =>
  482.                                 TR_REGISTER  <= DR_REGISTER ;
  483.                         when JUMP2  =>
  484.                                 TR_REGISTER  <= DR_REGISTER ;
  485.                         when JMPZY2  =>
  486.                                 TR_REGISTER  <= DR_REGISTER ;
  487.                         when JPNZY2  =>
  488.                                 TR_REGISTER  <= DR_REGISTER ;
  489.                         when others =>
  490.                 end case;
  491.                 end if;               
  492.         end process;
  493.        
  494.         --manage IR_REGISTER
  495.         process(clk, reset)
  496.         begin
  497.                 if(reset = '0')then
  498.                         IR_REGISTER  <= (others => '0');
  499.                 elsif (falling_edge(clk))then
  500.                         IR_REGISTER  <= IR_REGISTER ;
  501.                        
  502.                         case P_S is
  503.                         when FETCH3 =>
  504.                                 IR_REGISTER  <= DR_REGISTER ;
  505.                         when others =>
  506.                 end case;
  507.                 end if;               
  508.         end process;
  509.        
  510.         --manage R_REGISTER
  511.         process(clk, reset)
  512.         begin
  513.                 if(reset = '0')then
  514.                         R_REGISTER  <= (others => '0');
  515.                 elsif (falling_edge(clk))then
  516.                         R_REGISTER  <= R_REGISTER ;
  517.                        
  518.                         case P_S is
  519.                         when MEM_INIT =>
  520.                                 R_REGISTER(7 downto 4) <= "0000";
  521.                                 R_REGISTER(3 downto 0) <= "0010";
  522.                         when MVAC1  =>
  523.                                 R_REGISTER  <= AC_REGISTER ;
  524.                         when others =>
  525.                 end case;
  526.                 end if;               
  527.         end process;
  528.        
  529.         --manage Z_FLAG
  530.         process(clk, reset)
  531.         begin
  532.                 if(reset = '0')then
  533.                         Z_FLAG  <= '0';
  534.                 elsif (rising_edge(clk))then
  535.                         if (AC_REGISTER  = "00000000" ) then
  536.                                         Z_FLAG <= '1';
  537.                                 else
  538.                                         Z_FLAG <= '0';
  539.                                 end if;
  540.                 end if;               
  541.         end process;
  542.        
  543.         --manage memory
  544.         process(clk)
  545.         begin       
  546.                 if (falling_edge(clk))then
  547.                         case P_S is                       
  548.                         when MEM_INIT =>
  549.                                 RAM(Mem_count) <= ROM(Mem_count);
  550.                                 Mem_count <= Mem_count + 1;
  551.                        
  552.                         when STAC5  =>
  553.                                 RAM(to_integer(unsigned(AR_REGISTER))) <= DR_REGISTER ;
  554.                         when others =>
  555.                 end case;
  556.                 end if;               
  557.         end process;
  558.        
  559.         --Send value of register to output
  560.         process(clk)
  561.         variable tmp: STd_logic_vector(7 downto 0);
  562.         begin
  563.                 tmp := RAM(to_integer(unsigned(AR_REGISTER)));
  564.                 if(sw0 = '0')then
  565.                         output1 <= convSEG(AC_REGISTER(3 downto 0));
  566.                         output2 <= convSEG(AC_REGISTER(7 downto 4));
  567.                         output3 <= convSEG(R_REGISTER(3 downto 0));
  568.                         output4 <= convSEG(R_REGISTER(7 downto 4));
  569.                         output5 <= convSEG(tmp(3 downto 0));
  570.                         output6 <= convSEG(tmp(7 downto 4));
  571.                 else
  572.                         output1 <= convSEG(DR_REGISTER(3 downto 0));
  573.                         output2 <= convSEG(DR_REGISTER(7 downto 4));
  574.                         output3 <= convSEG(AR_REGISTER(3 downto 0));
  575.                         output4 <= convSEG(AR_REGISTER(7 downto 4));
  576.                         output5 <= convSEG(PC_REGISTER(3 downto 0));
  577.                         output6 <= convSEG(PC_REGISTER(7 downto 4));
  578.                 end if;
  579.         end process;
  580.        
  581.         process(clk)
  582.         begin
  583.        
  584.         if (falling_edge(clk))then
  585.         if(Delay_count = 100000000)then
  586.                 en <= '1';
  587.                 Delay_count <= 0;
  588.         else
  589.                 en <= '0';
  590.                 Delay_count <= Delay_count + 1;
  591.         end if;
  592.         end if;
  593.        
  594.         end process;
  595.        
  596.         test0 <= temp(0);
  597.         test1 <= temp(1);
  598.         Z <= Z_FLAG;
  599.        
  600. end behavioral;

复制代码
回复

使用道具 举报

ID:155507 发表于 2018-9-4 20:17 | 显示全部楼层
https://github.com/Kaaveh/Basic-Computer

  1. package States is
  2.         type myState is (RESET1, MEM_INIT, FINISH, FETCH1 , FETCH2, FETCH3, NOP1 , LDAC1 , LDAC2 , LDAC3, LDAC4 , LDAC5,
  3.         STAC1, STAC2, STAC3, STAC4, STAC5, MVAC1, MOVR1, JUMP1, JUMP2, JUMP3, JMPZY1, JMPZY2, JMPZY3,
  4.         JMPZN1, JMPZN2, JPNZY1, JPNZY2, JPNZY3, JPNZN1, JPNZN2, ADD1, SUB1, INAC1, CLAC1, AND1, OR1, XOR1, NOT1);  
  5. end States;

复制代码
回复

使用道具 举报

ID:393004 发表于 2018-9-4 22:15 | 显示全部楼层
985400330 发表于 2018-9-4 16:47
难了,做一个51吧,之前听说过,时间太紧了,做51需要下载IP核

然鹅只能用这个做。。
回复

使用道具 举报

ID:393004 发表于 2018-9-4 22:18 | 显示全部楼层
tt123 发表于 2018-9-4 19:44
其实你附上的要求,就是思路。
你将每一点要求转化成"什麽"或者"怎样"的问题,然後顺序,一个一个回答就 ...

我能不能说没做过51啊。。
回复

使用道具 举报

ID:393004 发表于 2018-9-4 22:28 | 显示全部楼层
angmall 发表于 2018-9-4 20:17
https://github.com/Kaaveh/Basic-Computer

果然江湖里大佬是真的存在啊。。
请教一下总工程师,内部结构在代码里我找到了,指令设计也是在代码里吗?具体的名称、格式、编码、描述、功能能否明示一下呢?
还有一个很重要的问题是这个cpu是干嘛功能的呢,请原谅初学者的无知。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表