找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3685|回復: 0
打印 上一主題 下一主題
收起左側

基于quartus 2 9.0c 軟件的MIPS指令集16位CPU設計

[復制鏈接]
跳轉到指定樓層
樓主
ID:505284 發(fā)表于 2019-11-20 12:20 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
  基于MIPS_RISC指令集的用VHDL語言寫的可以在quartus軟件運行成功的16位cpu模型機源碼及CPU芯片邏輯技術設計書分享,以及全國大學生計算機設計大賽參考,本設計僅僅只是基礎設計,滿足5條機器指令執(zhí)行,若需要更多要求,可以自行更改邏輯設計滿足不同要求。注意還有現(xiàn)成的設計原稿哦,文件大小限制,去繁從簡為主!

總體狀態(tài)轉換圖


畫出QuartusⅡ環(huán)境下的數(shù)據(jù)通路總圖



七、編寫匯編語言,調試程序,給出結果

為了方便輸入與編碼,指令格式自己譯成 操作碼/尋址方式/目的寄存器/源寄存器


總體仿真波形圖


1.ALU
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ALU is
   port(
     input1,input2:in std_logic_vector(15 downto 0);  --兩個操作數(shù)
     choice:in std_logic_vector(5 downto 0);          --選擇進行的運算
     result:buffer std_logic_vector(15 downto 0);     --結果輸出
     result2:buffer std_logic_vector(15 downto 0);     --結果輸出
     psw   :buffer std_logic_vector(15 downto 0)      --PSW,psw(0)為C,psw(1)為Z,psw(2)為S,psw(3)為O
                                                           
      );
end ALU;

architecture alu_b of ALU is
signal q : std_logic_vector(16 downto 0);  --中間變量
signal result3:std_logic_vector(32 downto 0);     --中間變量
begin
  process(input1,input2,choice,q,psw)
  variable i : integer;
  variable p :std_logic_vector(15 downto 0);
  begin   
    if  choice="000001" then              --ADD
        q<=('0' & input1) + ('0' & input2);
        psw(0) <=q(16);
        psw(2) <=q(15);
        if q(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
        result <= q(15 downto 0);
    elsif choice="000010"then                --ADDU
        result <= input1 + input2;
    elsif choice="000011" then                --SUB
        q<=('0'&input1) - ('0'& input2);   
        psw(0) <=q(16);
        psw(2) <=q(15);
        if q(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
        result <= q(15 downto 0);
        
    elsif choice="000100" then                --SUBU
        result <= input1 - input2;
    --elsif choice="000101" then                --IMUL
    --    result3<= ('0'&input1) * ('0'& input2);
    --    psw(0) <=result3(32);
    --    psw(2) <=result3(31);
    --    if result3(31 downto 0)= "00000000000000000000000000000000" then
    --    psw(1)<= '1';
        --else
    --        psw(1)<= '0';
        --end if;   
    --    result<=result3(31 downto 16);
    --    result2<=result3(15 downto 0);
    --elsif choice="000110" then                --IDIV
    --    q<= ('0'&input1) mod ('0'& input2);
    --    psw(0) <=q(16);
    --    psw(2) <=q(15);
    --    if q(15 downto 0)= "0000000000000000" then
    --        psw(1)<= '1';
    --    else
    --        psw(1)<= '0';
    --    end if;   
    --    result <=q(15 downto 0);
    --    result2 <=input1 rem input2;
    elsif choice="000111" then                --INC
        q(15 downto 0)<= "0000000000000001" + input1;
        result <=q(15 downto 0);
    elsif choice="001000" then                --DEC
        q(15 downto 0)<= input1 - "0000000000000001" ;
        result <=q(15 downto 0);
    elsif choice="001001" then                --CMP
        q<=('0'&input1) - ('0'& input2);   
        psw(0) <=q(16);
        psw(2) <=q(15);
        if q(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
    elsif choice="001010" then                --NEG
        q<="10000000000000000" - ('0'&input1);   
        psw(0) <=q(16);
        psw(2) <=q(15);
        if q(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
        result <=q(15 downto 0);
    elsif choice="001011" then                --NOT
        result <= not input1;
    elsif choice="001100" then                --AND
        psw(0) <='0';
        psw(3) <='0';
        result <= input1 and input2;
        psw(2) <= result(15);
        if result(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
    elsif choice="001101" then                --OR
        psw(0) <='0';
        psw(3) <='0';
        result <= input1 or input2;   
        psw(2) <= result(15);
        if result(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
    elsif choice="001110" then                --XOR
        psw(0) <='0';
        psw(3) <='0';
        result <= input1 xor input2;   
        psw(2) <= result(15);
        if result(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
    elsif choice="001111" then                --TEST
        psw(0) <='0';
        psw(3) <='0';
        q(15 downto 0) <= input1 xor input2;
        psw(2) <= q(15);
        if q(15 downto 0)= "0000000000000000" then
            psw(1)<= '1';
        else
            psw(1)<= '0';
        end if;   
    elsif choice="010000" then                --SHL
    --    function  f(bits,shift)
    --        for i in 1 to bits loop
     --         case shift is
     --           when shift="1001"
    --                 p:='0' & p(15 downto 1);
    --             when shift="1010"   
    --                 p:=p(15 downto 1) & '0' ;
    --             when shift ="1011" then
    --                 p:=p(14 downto 0)& p(15);
    --             when shift ="1100" then
    --                p:=p(0) & p(15 downto 1) ;
    --        end loop;
    --    end function

    end if;

全部資料51hei下載地址:
MIPS_16位CPU設計.rar (11.97 MB, 下載次數(shù): 21)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表