Bisa2008 - MCU Turkey
Transkript
Bisa2008 - MCU Turkey
BİSA CPU Proje Raporu Proje Danışmanı Yrd.Doç.Dr.Aydoğan Savran Proje Ekibi Arş.Gör.Özkan Akın Cihat Eroğlu(Proje Yetkilisi) 1 İÇİNDEKİLER 1)GİRİŞ _______________________________________________________________________ 3 2)BİSA MULTIPLE-CYCLE MİKROİŞLEMCİ______________________________________________3 2.1)DONANIM BÖLÜMÜ________________________________________________________ 4 2.1.1)Genel Blok Diyagram _________________________________________________ 4 2.1.2)Hafıza Ünitesi(Memory) _______________________________________________ 5 2.1.3)Veri yolu(Datapath) ___________________________________________________5 a.Register File______________________________________________________ 6 b.Arithmetic Logic Unit(ALU)___________________________________________6 c.Mux B___________________________________________________________ 8 d.Mux D __________________________________________________________ 8 e.Mux M___________________________________________________________8 2.1.4)Kontrol Ünitesi(Control Unit)____________________________________________ 8 a.Program Counter(PC)_______________________________________________ 9 b.Instruction Register(IR)______________________________________________9 c.Mux C___________________________________________________________ 9 d.Control Address Register(CAR)_______________________________________ 9 e.Mux S___________________________________________________________ 9 f. Control Memory___________________________________________________9 2.2)YAZILIM BÖLÜMÜ_________________________________________________________10 a.Synthesis Report__________________________________________________ 10 b.Translate Report__________________________________________________ 12 c.Map Report ______________________________________________________ 13 d.Device Utilization Summary _________________________________________ 15 3)REFERANSLAR________________________________________________________________ 15 EKLER________________________________________________________________________ 16 EK 1:Yazılım Kodları_____________________________________________________________ 16 EK 2:Model Sim Çıktıları__________________________________________________________ 71 2 Anahtar Kelimeler VHDL,Multiple Cycle-Hardwired Control,BİSA,Memory,Datapath,Control Unit,ALU,Register File,Control Memory 1) GİRİŞ VHDL programlama dili temelli Xilinx 7.1 editörü kullanılarak program kodları özgün biçimde geliştirilen ve Model Sim XE II 5.8c simülasyon programı kullanılarak performans testi yapılan BİSA CPU basit ve temel düzeyde bir işlemci olarak tasarlanmıştır.Bu rapor BİSA’nın sonuçlandırılma aşamasında hazırlanmış ve işlemcinin temel özellikleri ile işlemci tasarımında kullanılan teorik bilgi hakkında ayrıntılı bilgiye erişilebilecek bir doküman özeliğindedir.İlgili VHDL kodları ve Model Sim simülasyon çıktıları rapora ilaveten dahil edilen ekte yer almaktadır. BİSA’nın VHDL kod tasarımının yapısal olmasına özellikle dikkat edilmiştir.Alu,register file gibi farklı görevleri üstlenen alt kod yapıları oluşturulmuş ve bu yapılar 3 ana yapı altında toplanarak tüm işlemci yapısıyla bağlantılı hale getirilmiştir. 2)BİSA MULTIPLE-CYCLE MİKROİŞLEMCİ Bisa Multiple-Cycle mikroişlemcinin temel özelikleri aşağıdaki gibi sıralanabilir: VHDL kullanılarak tasarlanmıştır. Multiple Cycle-Hardwired Control temelli işlemci özelliğindedir. “Memory,datapath ve control unit “ olmak üzere 3 ana yapıdan oluşması Kod tasarımında iç içe yapılarin kullanılması dolayısıyla modüler bir yapı oluşturulması Geliştirilme aşamasında 25 temel komut yazılım kodu Xilinx’in VHDL editöründe oluşturulup Model Sim’de simülasyonla test edilmiş ve başarılı sonuç alınmıştır. ü Sistem donanım ve yazılım olmak üzere 2 kısımdan oluşmaktadır. ü Donanım kısmında sistemi oluşturan 3 ana yapı hafıza ünitesi,kontrol ünitesi ve veri yolu ayrı ayrı alt yapılardan oluşmaktadır.Her bir alt yapı ayrı bir işlemi gerçekleştirmekte ve kendi aralarında koordineli çalışarak ana işlemciyi oluşturmaktadırlar. ü Yazılım kısmında sistemin Xilinx VHDL editöründe oluşturulmuş yazılım kodları koşturularak gerekli sonuçlar alınmıştır.Yazılım kodları Ekler kısmında incelenebilir. ü ü ü ü ü 3 2.1.1) Genel Blok Diyagram Şekil-1 BİSA Multiple-Cycle işlemci tasarımında ana yapılar(datapath vb.) ve iç yapılar(control memory,reg file vb.)arasındaki bağlantı ve işleyiş mantığının kod tasarımının yapılmasında bu şema kullanılmıştır.Fakat tasarımın gerektirdiği bazı durumlarda bağlantılarda birtakım değişikliklere gidilmiştir.Örneğin kontrol ünitesinde “control memory” çıkışındaki TD,TA ve TB bayrakları iptal edilerek “datapath“de register file girişleri uygun bir şekilde ayarlanmıştır.Yukarıdaki şemaya göre yapılan diğer değişiklikler Ekler kısmında ModelSim çıktıları ve VHDL kodlarından incelenebilir. 4 2.1.2 HafızaÜnitesi(Memory) Şekil-2 Bisa’nın 3 ana yapısından birisi olan hafıza(memory)bloğu bu tasarımda şu görevleri üstlenmektedir:PC(Program Counter)dan veya A kaydedicisinden(registerinden) gelen adres bilgisini okunarak ilgili adres gözündeki 16 bitlik bilgi çıkışa aktarılmaktadır.Adres kaynağı seçimi memory girişindeki MUX M bloğu ile gerçekleştirilmektedir.Hafıza ünitesinin bu şekilde okuma modunda çalışması için yazılım kodlarında Read olarak belirlenen girişi high(aktif)konumda olmalıdır.Bu hafıza bloğunun diğer bir görevi de IR(Instruction Register)den gelen ivedi(immediate) bilginin veya B kaydedicisindeki bilginin MUX B bloğunun katkısıyla seçilerek PC veya A kaydedicisi tarafından adres gözüne yazılabilmesidir.Hafıza bloğunun bu şekilde yazma modunda çalışması için yazılımda MW olarak belirlenen girişi aktif durumda olmalıdır.Yazma modunda istenirse Read biti de aktif yapılarak hafıza ünitesine yazılan bilgi hafıza ünitesi çıkışında görülebilir.Sistemimizin tasarımında hafıza ünitesi 16 bitlik bilgi içeren 256 adet adres gözünden oluşmaktadır. 2.1.2)Veri yolu(Datapath) Şekil-3 Bisa’nın diğer bir ana yapısı olan datapath bloğu farklı özellikte işlemlerin gerçekleştirildiği işlem sonuçlarının istenen kaydedicilere saklanabildiği bir blok görevi üstlenmektedir.Bu blok farklı görevleri üstlenen ve birbiriyle koordineli çalışan birtakım alt yapılardan oluşmaktadır.Bunlar,ALU,Register File,Mux M,Mux B ve Mux D olmak üzere 5 adettir.Her bir yapının üstlendiği görev aşağıda detaylı olarak verilmektedir. 5 a.)Register File Bisa mikroişlemci tasarımında veriyolunda gerçekleştirilen işlevlerin sonuçlarının kaydedildiği kaydedicileri(register)içeren register file bu tasarımda 8 adet register içermektedir.Her bir kaydedici kontrol ünitesinden gelen bilgiye göre hedef kaydedici, A kaynak kaydedicisi veya B kaynak kaydedicisi olarak kullanılabilmektedir.Yazılımda RW olarak atanan bitin aktif yapılmasıyla register filenin belirlenen hedef kaydedicisine alu dan veya memory den gelen bilgi kaydedilebilir. b.) Arithmetic Logic Unit(ALU) Bisa mikroişlemci tasarımında aritmetik lojik ünitemiz 5 bitlik FS girişi ile 32 farklı işlevi gerçekleştirebilecek şekilde tasarlanmıştır.Tasarımda 24 farklı işlem başarıyla ModelSim simülasyon ortamında gerçeklenmiş ve doğru sonuçlar elde edilmiştir.Çıkışa yerleştirilen elde,taşma,negatif ve sıfır bayraklarıyla kontrol ünitesinin sistemin yönlendirilmesine katkıda bulunulmuştur.Aşağıda tasarımda gerçekleştirilen işlevler kısa açıklamalarla birlikte gösterilmektedir.Her işlemin kod algoritması Ekler kısmında Yazılım kodları bölümünde incelenebilir. FS = ”00000” à Nop(No operation) :Herhangi bir işlem gerçekleştirilmemekte sadece A kaydedicisindeki 16 bitlik sayı alu çıkışına atanmaktadır.) FS= “00001” à Add(Addition):A kaydedicisindeki 16 bitlik sayı ile B kaydedicisindeki 16 bitlik sayı toplanmaktadır. FS= “00010” à Addi(Addition Immediate): A kaydedicisindeki 16 bitlik sayı ile 16 bitlik IR(Instruction Register) çıkışından alınan ivedi bir sayı toplanmaktadır. FS= “00011” à Sub(Subtraction):A kaydedicisindeki 16 bitlik sayıdan B kaydedicisindeki 16 bitlik sayı çıkarılmaktadır. FS= “00100” à Subi(Subtraction Immediate): A kaydedicisindeki 16 bitlik sayıdan 16 bitlik IR çıkışından alınan ivedi bir sayı çıkarılmaktadır. FS= “00101” à Cmp(Compare):A kaydedicisindeki 16 bitlik sayı ile B kaydedicisindeki 16 bitlik sayı karşılaştırılarak(çıkarma algoritması kullanılarak) A > B iken alu çıkışına yerleştirilen 2 bitlik “alucmp” çıkışına 2 sayısı atanıyor.A < B iken bu çıkışa 1 sayısı atanıyor.A = B iken bu çıkışa 0 sayısı atanıyor. FS= “00110” à And(AND): A kaydedicisindeki 16 bitlik sayı ile B kaydedicisindeki 16 bitlik sayının tüm bitleri And işlemine tabi tutuluyor. FS= “00111” à Andi(AND Immediate): A kaydedicisindeki 16 bitlik sayı ile 16 bitlik ivedi bir sayının tüm bitleri And işlemine tabi tutuluyor. FS= “01000” à Or(OR): A kaydedicisindeki 16 bitlik sayı ile B kaydedicisindeki 16 bitlik sayının tüm bitleri Or işlemine tabi tutuluyor. 6 FS= “01001” à Ori(OR Immediate): A kaydedicisindeki 16 bitlik sayı ile 16 bitlik ivedi bir sayının tüm bitleri Or işlemine tabi tutuluyor. FS= “01010” à Not(NOT): A kaydedicisindeki 16 bitlik sayının tüm bitleri Not işlemine tabi tutuluyor. FS= “01011” à Xor(XOR): A kaydedicisindeki 16 bitlik sayı ile B kaydedicisindeki 16 bitlik sayının tüm bitleri Xor işlemine tabi tutuluyor. FS= “01100” à Xori(XOR immediate): A kaydedicisindeki 16 bitlik sayı ile 16 bitlik ivedi bir sayının tüm bitleri Xor işlemine tabi tutuluyor. FS= “01101” à kaydırılıyor. Sll(Logical Shift Left):A kaydedicisindeki 16 bitlik sayı 1 bit sola FS= “01110” à kaydırılıyor. Srl(Logical Shift Right): A kaydedicisindeki 16 bitlik sayı 1 bit sağa FS= “01111” à Sla(Arithmetic Shift Left): A kaydedicisindeki 16 bitlik sayı Sll de olduğu gibi 1 bit sola kaydırılıyor.Sll’den farklı olarak Sla kaydırma esnasında overflow bitini set edebiliyor. FS= “10000” à Sra(Arithmetic Shift Right): A kaydedicisindeki 16 bitlik sayı A’nın en anlamlı biti(MSB) ‘1’ ise 1 bit sağa kaydırılarak başına 1 konur.A’nın en anlamlı biti ‘0’ ise A 1 bit sağa kaydırılarak başına ‘0’konur. FS= “10001” à Lw(Load word):Hafıza ünitesindeki seçilen bir adres gözündeki 16 bitlik sayı IR tarafından belirlenen bir kaydediciye(register)kaydedilir. FS= “10010” à Mov(Move data between registers):IR tarafından belirlenen bir kaynak kaydedicideki sayı yine IR tarafından belirlenen bir hedef kaydediciye kopyalanır. FS= “10011” à Movi(Move data immediate):IR tarafından belirlenen ivedi bir sayı yine IR tarafından belirlenen bir hedef kaydediciye kopyalanır. FS= “10100” à Ba(Branch always):Program counter(PC),IR’nin en düşük anlamlı 6 biti tarafından belirlenen memory adres gözüne herhangi bir koşula dayanmadan atlar. FS= “10101” à Mulu(Multiplication Unsigned):A ve B kaydedicilerindeki işaretsiz iki sayı çarpma işlemine tabi tutulur. FS= “10110” à işlemine tabi tutulur. Mul(Multiplication):A ve B kaydedicilerindeki işaretli iki sayı çarpma FS= “10111” à Muli(Multiplication Immediate):A kaydedicisindeki işaretli sayı ile işaretli ivedi bir sayı çarpma işlemine tabi tutulur. FS= “11000” à Hlt(Halt):Program counter’ın halt girişi set edildiği zaman PC’nin içeriği sıfırlanır ve işlemcinin start girişi set edilene kadar herhangi bir işlem yapılmaz. 7 Yukarıdaki Halt,Branch always,Load word gibi işlemlerde matematiksel işlem yapılmadığı için alu çıkışına sadece A kaydedicisindeki sayı aktarılmıştır. Alu çıkışına yerleştirilen elde,taşma,negatif ve sıfır bayraklarıyla ilgili kodlar Ekler bölümünde Yazılım kodlarından takip edilebilir. c.)Mux B Bisa mikroişlemcisinde Mux B bloğu B kaydedicisinden gelen bilgi ile IR çıkışından gelen ivedi bilginin seçildiği bloktur.Seçim kontrol hafızası çıkışından gelen MB biti ile ayarlanmaktadır. d.)Mux D Bisa mikroişlemcisinde Mux D bloğu alu çıkışından gelen bilgi ile memory çıkışından gelen bilginin seçildiği bloktur.Seçim kontrol hafızasından gelen MD biti ile sağlanmaktadır. e.) Mux M Hafıza ünitesine adres bilgisinin PC den mi A kaydedicisinden mi geleceğini belirleyen bloktur.Seçim kontrol hafızasından gelen MM biti ile sağlanmaktadır. 2.1.4)Control Unit Şekil-4 a.Program Counter(PC) IR’de yer alan DR ve SB bit gruplarındaki bilgiyle yüklenebilen PC,memory’nin hangi adres gözüne erişileceğinin dolayısıyla hangi komutun seçileceğinin belirlenmesinde görev alır.PC’nin girişindeki control memory’den gelen PI bayrağı aktifken PC 1 artırım yoluyla memory adres gözlerine erişirken,PL bayrağı aktif olduğunda IR’den de yüklenebilir ve bu değerin göstediği memory adres gözüne erişilir. 8 b.Instruction Register(IR) IR(Komut kaydedicisi),bünyesinde barındırabileceği farklı opcode bilgileriyle farklı farklı komutların işletilmesinde görev almaktadır.Bu opcode bilgisi ile birlikte DR(Destination register) ve SA(Source A-A kaydedicisi için R0-R7 seçimi),SB(Source B-B kaydedicisi için R0-R7 seçimi)bilgileri IL aktif olmak şartıyla memory’den alınabilir. c.Mux C Mux C bloğu, Control Memory çıkışındaki NA‘dan gelen 8 bitlik sayı ile IR’den gelen 8 bitlik opcode bilgisi arasında seçim yapılan multiplexer(çoğullayıcı)ünitesidir.Bu seçim control memory ye saklanan MC biti yardımıyla yapılır.MC =’1’ ise IR’den gelen opcode bilgisi çoğullayıcı çıkışına alınır.MC = ‘0’ ise NA’dan gelen opcode bilgisi çoğullayıcı çıkışına alınır. d.Control Address Register(CAR) Mux C çıkışından alınan opcode bilgisi CAR’a iletilir.Bu bilginin CAR çıkışına iletilebilmesi için Mux S çıkışından gelen ve CAR’a giriş olarak bağlanan enable bitinin set edilmiş olması gerekir.Aksi takdirde CAR sadece 1 artırılır ve bir sonraki opcode bilgisi control memory ye aktarılmış olur. e.Mux S Alu’dan gelen sıfır,taşma,elde ve negatif bayraklarına göre Mux S çıkışı set edilir ve alçak seviyede bırakılır.Bu bayrak değerleri yüksek seviye olarak Mux S çoğullayıcı bloğuna geldiğinde çıkış set edilir aksi takdirde alçak seviyede bırakılır.Hangi bayrağın durumuna göre işlem yapılacağı control memory den gelen 3 bitlik MS sinyali ile belirlenir. f.Control Memory BİSA’da Control memory başta verilen blok diyagramdan farklı olarak 26 bit sayısına sahiptir.TA,TB,TD bitleri iptal edilmiş,PCCLR isminde PC’yi istenildiğinde halt komutundan farklı olarak sıfırlayan giriş eklenmiştir.Control memory genel olarak datapath memory ve control unit te gerçekleşen olayların belli şartlara bağlı olarak gerçekleşmesini sağlayan bayrakların yer aldığı hafıza bloğudur.BİSA’da bu sonuçlandırma aşamasında belirlenen 30 adres gözüne bilgi depolanmıştır. 2.2) YAZILIM BÖLÜMÜ Bisa mikroişlemcinin tasarımı için Xilinx 7.1 ISE editöründe VHDL dili kullanılarak oluşturulan yazılım kodları Ekler kısmında verilmekle birlikte aşağıda kodların koşturulmasıyla birlikte elde elde edilen Synthesis Report,Translate Report,Map Report ve Device Utilisation Summary çıktılarına erişilebilir. 9 a.Synthesis Report ========================================================================= * Advanced HDL Synthesis * ========================================================================= Advanced RAM inference ... MAC inference ... Advanced multiplier inference ... Advanced Registered AddSub inference ... DSP optimizations ... Dynamic shift register inference ... ========================================================================= HDL Synthesis Report Macro Statistics # LUT RAMs :1 256x16-bit single-port distributed RAM: 1 # ROMs :1 256x26-bit ROM # Multipliers :1 :2 16x16-bit multiplier :2 # Adders/Subtractors :6 16-bit adder :4 32-bit adder :1 8-bit adder :1 # Counters :1 16-bit up counter :1 # Registers : 10 1-bit register :1 16-bit register :9 10 # Latches : 15 1-bit latch :1 16-bit latch :6 2-bit latch :1 26-bit latch :1 3-bit latch :3 32-bit latch :2 8-bit latch :1 # Comparators :1 16-bit comparator greater # Multiplexers :1 :6 1-bit 8-to-1 multiplexer :1 16-bit 4-to-1 multiplexer :2 16-bit 8-to-1 multiplexer :2 2-bit 4-to-1 multiplexer :1 # Xors :3 1-bit xor2 :2 16-bit xor2 :1 Timing Summary: --------------Speed Grade: -12 Minimum period: 11.950ns (Maximum Frequency: 83.683MHz) Minimum input arrival time before clock: 1.791ns Maximum output required time after clock: 14.013ns Maximum combinational path delay: No path found 11 b.Translate Report Release 7.1i ngdbuild H.38 Copyright (c) 1995-2005 Xilinx, Inc. All rights reserved. Command Line: ngdbuild -intstyle ise -dd h:\datakontrol/_ngo -i -p xc4vlx15-sf363-12 microprocessor.ngc microprocessor.ngd Reading NGO file 'H:/datakontrol/microprocessor.ngc' ... Checking timing specifications ... Checking expanded design ... NGDBUILD Design Results Summary: Number of errors: 0 Number of warnings: 0 Total memory usage is 78348 kilobytes Writing NGD file "microprocessor.ngd" ... Writing NGDBUILD log file "microprocessor.bld"... c.Map Report Removed Logic Summary --------------------------------8 block(s) removed 2 block(s) optimized away 8 signal(s) removed Additional Device Resource Counts ---------------------------------------------Number of JTAG Gates for IOBs = 198 Number of Equivalent Gates for Design = 41,618 Number of RPM Macros = 0 Number of Hard Macros = 0 PMV = 0 USR_ACCESS_VIRTEX4 = 0 12 BUFIO = 0 GT11CLK = 0 GT11 = 0 IDELAYCTRL = 0 FRAME_ECC_VIRTEX4 = 0 STARTUP_VIRTEX4 = 0 JTAGPPC = 0 ICAP_VIRTEX4 = 0 DPM = 0 DCI_TEST = 0 DCIRESET = 0 CAPTURE_VIRTEX4 = 0 BSCAN_VIRTEX4 = 0 OSERDES = 0 ISERDES = 0 BUFR = 0 EMAC = 0 PPC405_ADV = 0 MONITOR = 0 PMCD = 0 DCM_ADV = 0 DSP48 = 2 Unbonded IOBs = 0 Bonded IOBs = 198 XORs = 107 CARRY_INITs = 58 CARRY_SKIPs = 0 CARRY_MUXes = 110 13 Shift Registers = 0 Static Shift Registers = 0 Dynamic Shift Registers = 0 16x1 ROMs = 0 16x1 RAMs = 0 32x1 RAMs = 128 Dual Port RAMs = 0 MUXFs = 281 MULT_ANDs = 0 4 input LUTs used as Route-Thrus = 9 4 input LUTs = 853 Slice Latches not driven by LUTs = 157 Slice Latches = 157 Slice Flip Flops not driven by LUTs = 32 Slice Flip Flops = 161 SliceMs = 128 SliceLs = 530 Slices = 658 F6 Muxes = 48 F5 Muxes = 105 F8 Muxes = 0 F7 Muxes = 0 Number of LUT signals with 4 loads = 3 Number of LUT signals with 3 loads = 16 Number of LUT signals with 2 loads = 116 Number of LUT signals with 1 load = 644 NGM Average fanout of LUT = 3.12 NGM Maximum fanout of LUT = 129 14 NGM Average fanin for LUT = 3.4689 Number of LUT symbols = 853 d.Device Utilisation Summary Selected Device : 4vlx15sf363-12 Number of Slices: 732 out of 6144 11% Number of Slice Flip Flops: 351 out of 12288 2% Number of 4 input LUTs: 1111 out of 12288 9% Number of bonded IOBs: 214 out of 240 89% Number of GCLKs: 8 out of 32 25% Number of DSP48s: 2 out of 32 6% 3)REFERANSLAR [1]Logic And Computer Design Fundamentals,M.Morris Mano-Charles R.Kime,Prentice Hall, 2nd Edition [2] http://esd.cs.ucr.edu/labs/tutorial/VHDL Tutorial Learn by Example by Weijun Zhang 15 EKLER EK 1:YAZILIM KODLARI 1)Microprocessor --------------------------------------------------------------------------------- Company: -- Engineer: Cihat Eroğlu --- Create Date: 14:33:50 05/29/08 -- Design Name: -- Module Name: microprocessor - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating 16 ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity microprocessor is Port ( clock : IN std_logic; reset,start: IN std_logic; PCin : IN std_logic_vector(15 downto 0); PCclr : out std_logic; Memoryread : IN std_logic; cMemoryread: IN std_logic; cpuoutput : OUT std_logic_vector(15 downto 0); registerA : OUT std_logic_vector(15 downto 0); registerB : OUT std_logic_vector(15 downto 0); alu_Bmul : out std_logic_vector(15 downto 0); PCout : OUT std_logic_vector(15 downto 0); IRout : OUT std_logic_vector(15 downto 0); memoryout : OUT std_logic_vector(15 downto 0); CARout : OUT std_logic_vector(7 downto 0); muxsout : OUT std_logic; NA : OUT std_logic_vector(7 downto 0); MS : OUT std_logic_vector(2 downto 0); MC : OUT std_logic; IL : OUT std_logic; PI : OUT std_logic; PL : OUT std_logic; MB : OUT std_logic; FunctionSel: OUT std_logic_vector(4 downto 0); 17 MD : OUT std_logic; RW : OUT std_logic; MM : OUT std_logic; MW : OUT std_logic; muxcout : OUT std_logic_vector(7 downto 0); Overflow : OUT std_logic; Carry : OUT std_logic; Negative : OUT std_logic; Zero : OUT std_logic; Compare : OUT std_logic_vector(1 downto 0); memorydata : OUT std_logic_vector(15 downto 0); mxM_out : OUT std_logic_vector(15 downto 0) ); end microprocessor; architecture Behavioral of microprocessor is COMPONENT ana PORT( clock : in std_logic; start : PCclr : out std_logic; PCout IRIM seIM IN std_logic; : out std_logic_vector(15 downto 0); : out std_logic_vector(15 downto 0); : out std_logic_vector(15 downto 0); dir_addr : out std_logic_vector(7 downto 0); IRin : in std_logic_vector(15 downto 0); IRin2 : in std_logic_vector(15 downto 0); IRout : out std_logic_vector(15 downto 0); DR_IR : out std_logic_vector(2 downto 0); SA_IR : out std_logic_vector(2 downto 0); 18 SB_IR : out std_logic_vector(2 downto 0); CAR_out : OUT std_logic_vector(7 downto 0); NEG : IN std_logic; ZR : IN std_logic; CRY : IN std_logic; OVR : IN std_logic; mxS_out : OUT std_logic; Read : IN std_logic; NA : OUT std_logic_vector(7 downto 0); MS : OUT std_logic_vector(2 downto 0); MC : OUT std_logic; IL : OUT std_logic; PI : OUT std_logic; PL : OUT std_logic; MB Func_S : OUT std_logic; : OUT std_logic_vector(4 downto 0); MD : OUT std_logic; RW : OUT std_logic; MM : OUT std_logic; MW : OUT std_logic; Data_out : OUT std_logic_vector(25 downto 0); mxC_out : OUT std_logic_vector(7 downto 0) ); END COMPONENT; COMPONENT main PORT(clock : IN std_logic; m_alu_FS : IN std_logic_vector(4 downto 0); m_alu_V : OUT std_logic; 19 m_alu_C : OUT std_logic; m_alu_N : OUT std_logic; m_alu_Z : OUT std_logic; alucmp : OUT std_logic_vector(1 downto 0); m_alu_F : OUT std_logic_vector(15 downto 0); alu_b : OUT std_logic_vector(15 downto 0); alu_Bmul : out std_logic_vector(15 downto 0); m_wr_en : IN std_logic; reset : IN std_logic; m_adrs_D : IN std_logic_vector(2 downto 0); m_adrs_A : IN std_logic_vector(2 downto 0); m_adrs_B : IN std_logic_vector(2 downto 0); m_reg_A : OUT std_logic_vector(15 downto 0); m_reg_B : OUT std_logic_vector(15 downto 0); m_R0 : OUT std_logic_vector(15 downto 0); m_R1 : OUT std_logic_vector(15 downto 0); m_R2 : OUT std_logic_vector(15 downto 0); m_R3 : OUT std_logic_vector(15 downto 0); m_R4 : OUT std_logic_vector(15 downto 0); m_R5 : OUT std_logic_vector(15 downto 0); m_R6 : OUT std_logic_vector(15 downto 0); m_R7 : OUT std_logic_vector(15 downto 0); mxB_SB : IN std_logic_vector(15 downto 0); mxB_sel : IN std_logic; mxD_mrydata: IN std_logic_vector(15 downto 0); mxDmrydata_dp : IN std_logic_vector(15 downto 0); mxD_sel : IN std_logic; mxD_out : OUT std_logic_vector(15 downto 0); 20 mxM_PC : IN std_logic_vector(15 downto 0); mxM_sel : IN std_logic; mxM_out : OUT std_logic_vector(15 downto 0) ); END COMPONENT; COMPONENT memory PORT(clock Mre : IN std_logic; : IN std_logic; Mwe : IN std_logic; address : IN std_logic_vector(15 downto 0); data_in : IN std_logic_vector(15 downto 0); data_outmem : OUT std_logic_vector(15 downto 0); data : OUT std_logic_vector(15 downto 0) ); END COMPONENT; signal PCout1,IRIM1,IRout1,seIM1,registerA1,m_alu_F1:std_logic_vector(15 downto 0); signal data_in1,mxM_out1,memoryout1,memorydata1,Mrydatain:std_logic_vector(15 downto 0); signal dir_addr1,CARout1:std_logic_vector(7 downto 0); signal DR_IR1,SA_IR1,SB_IR1:std_logic_vector(2 downto 0); signal NEG1,ZR1,CRY1,OVR1,MB1,MD1,RW1,MM1,MW1:std_logic; signal Func_S1:std_logic_vector(4 downto 0); signal Data_out1:std_logic_vector(25 downto 0); signal m_R0,m_R1,m_R2,m_R3,m_R4,m_R5,m_R6,m_R7:std_logic_vector(15 downto 0); begin Inst_ana: ana PORT MAP( clock => clock, ----- start => start, PCclr => PCclr, 21 PCout => PCout1, ----- IRIM => IRIM1, ----- seIM => seIM1, ----- dir_addr => dir_addr1,----IRin => memoryout1,----- IRin2 => memorydata1, IRout => IRout, ----- DR_IR => DR_IR1, ----- SA_IR => SA_IR1, ----- SB_IR => SB_IR1, ----- CAR_out => CARout, ----- NEG ZR => NEG1, ----- => ZR1, ----- CRY => CRY1, ----- OVR => OVR1, ----- mxS_out Read => muxsout,----=> cMemoryread, ----- NA => NA, ----- MS => MS, ----- MC => MC, ----- IL => IL, ----- PI => PI, ----- PL => PL, ----- MB Func_S => MB1, ----=> Func_S1, ----- MD => MD1, ----- RW => RW1, ----- MM => MM1, ----- 22 MW => MW1, ----- Data_out => Data_out1,----mxC_out => muxcout ----- ); Inst_main: main PORT MAP( clock => clock, ----- m_alu_FS => Func_S1, ----- m_alu_V => OVR1, ----- m_alu_C => CRY1, ----- m_alu_N => NEG1, ----- m_alu_Z => ZR1, ----- alu_b => Mrydatain, alu_Bmul => alu_Bmul, alucmp => COMPARE, mxD_out => cpuoutput,----- m_wr_en => RW1, reset ----- => reset, ----- m_adrs_D => DR_IR1, ----m_adrs_A => SA_IR1, ----m_adrs_B => SB_IR1, ----m_reg_A => registerA1,----- m_reg_B => registerB,----- m_R0 => m_R0, ----- m_R1 => m_R1, ----- m_R2 => m_R2, ----- m_R3 => m_R3, ----- m_R4 => m_R4, ----- m_R5 => m_R5, ----- 23 m_R6 => m_R6, ----- m_R7 => m_R7, ----- mxB_SB => IRIM1, ----- mxB_sel => MB1, ----- mxD_sel => MD1, ----- m_alu_F => m_alu_F1,----- mxD_mrydata => memoryout1,---- mxDmrydata_dp=> memorydata1,----mxM_PC => PCout1,----- mxM_sel => MM1, mxM_out ----- => mxM_out1 ----- ); Inst_memory: memory PORT MAP( clock => clock, Mre => Memoryread,----- Mwe => MW1, ----- address => mxM_out1, ----- data_in => Mrydatain,----- data_outmem => memoryout1,-----data => memorydata1------ ); PCout <= PCout1; Negative <= NEG1; Zero <= ZR1; Carry <= CRY1; Overflow <= OVR1; MB <= MB1; FunctionSel <= Func_S1; 24 MD <= MD1; RW <= RW1; MM <= MM1; MW <= MW1; registerA <= registerA1; mxM_out <= mxM_out1; memoryout <= memoryout1; memorydata <= memorydata1; end Behavioral; 2)Kontrol Ünitesi(Ana) --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 06:41:51 05/29/08 -- Design Name: -- Module Name: ana - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- 25 -------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity ana is Port ( clock PCclr : in std_logic; : out std_logic; PCout : out std_logic_vector(15 downto 0 IRIM : out std_logic_vector(15 downto 0); seIM : out std_logic_vector(15 downto 0); dir_addr : out std_logic_vector(7 downto 0); IRin : in std_logic_vector(15 downto 0); IRin2 : in std_logic_vector(15 downto 0); IRout : out std_logic_vector(15 downto 0); DR_IR : out std_logic_vector(2 downto 0); SA_IR : out std_logic_vector(2 downto 0); SB_IR : out std_logic_vector(2 downto 0); CAR_out : OUT std_logic_vector(7 downto 0); start NEG ZR : IN std_logic; : IN std_logic; : IN std_logic; 26 CRY : IN std_logic; OVR : IN std_logic; mxS_out : OUT std_logic; Read : IN std_logic; NA : OUT std_logic_vector(7 downto 0); MS : OUT std_logic_vector(2 downto 0); MC : OUT std_logic; IL : OUT std_logic; PI : OUT std_logic; PL : OUT std_logic; MB : OUT std_logic; Func_S : OUT std_logic_vector(4 downto 0); MD : OUT std_logic; RW : OUT std_logic; MM : OUT std_logic; MW : OUT std_logic; Data_out : OUT std_logic_vector(25 downto 0); mxC_out : OUT std_logic_vector(7 downto 0)); end ana; architecture Behavioral of ana is COMPONENT ir PORT( IRin : IN std_logic_vector(15 downto 0); IRin2 : in std_logic_vector(15 downto 0); IRld : IN std_logic; IRIM : OUT std_logic_vector(15 downto 0); seIM : OUT std_logic_vector(15 downto 0); dir_addr: OUT std_logic_vector(7 downto 0); 27 IRout : OUT std_logic_vector(15 downto 0); DR_IR : OUT std_logic_vector(2 downto 0); SA_IR : OUT std_logic_vector(2 downto 0); SB_IR : OUT std_logic_vector(2 downto 0) ); END COMPONENT; COMPONENT pc PORT( clock : IN std_logic; start : in std_logic; halt : in std_logic; PCclr : in std_logic; PCld : IN std_logic; PCinc : IN std_logic; PCin : IN std_logic_vector(15 downto 0); PCout : OUT std_logic_vector(15 downto 0) ); END COMPONENT; COMPONENT car PORT( -- clock : IN std_logic; LD_en : IN std_logic; adrsin : IN std_logic_vector(7 downto 0); CAR_out : OUT std_logic_vector(7 downto 0) ); END COMPONENT; COMPONENT mux_s PORT( 28 NEG : IN std_logic; ZR : IN std_logic; CRY : IN std_logic; OVR : IN std_logic; mxS_sel : IN std_logic_vector(2 downto 0); mxS_out : OUT std_logic ); END COMPONENT; COMPONENT control_memory PORT( Read : IN std_logic; PCCLR : out std_logic; Address : IN std_logic_vector(7 downto 0); NA : OUT std_logic_vector(7 downto 0); MS : OUT std_logic_vector(2 downto 0); MC : OUT std_logic; IL : OUT std_logic; PI : OUT std_logic; PL : OUT std_logic; MB : OUT std_logic; Func_S : OUT std_logic_vector(4 downto 0); MD : OUT std_logic; RW : OUT std_logic; MM : OUT std_logic; MW : OUT std_logic; Data_out : OUT std_logic_vector(25 downto 0) ); END COMPONENT; 29 COMPONENT mux_c PORT( mxC_nxtadrs : IN std_logic_vector(7 downto 0); mxC_opadrs : IN std_logic_vector(7 downto 0); mxC_sel : IN std_logic; mxC_out : OUT std_logic_vector(7 downto 0) ); END COMPONENT; signal PCld,PCinc,IRld,LD_en,mxC_sel1,PCclear:std_logic; signal adrsin,Address1,mxC_next,mxC_opcode:std_logic_vector(7 downto 0); signal mxS_sel2:std_logic_vector(2 downto 0); signal PCin1:std_logic_vector(15 downto 0); signal halt:std_logic; signal IReg:std_logic_vector(15 downto 0); signal IRop:std_logic_vector(6 downto 0); begin Inst_ir: ir PORT MAP( IRin => IRin, IRin2 => IRin2, IRld => IRld, IRIM => IRIM, seIM => PCin1, dir_addr => mxC_opcode, IRout => IReg, DR_IR => DR_IR, SA_IR => SA_IR, SB_IR => SB_IR ); 30 Inst_pc: pc PORT MAP( clock => clock, PCclr => PCclear, start => start, halt => halt, PCld => PCld, PCinc => PCinc, PCin => PCin1, PCout => PCout ); Inst_car: car PORT MAP( LD_en => LD_en, adrsin => adrsin, CAR_out => Address1 ); Inst_mux_s: mux_s PORT MAP( NEG ZR => NEG, => ZR, CRY => CRY, OVR => OVR, mxS_sel => mxS_sel2, mxS_out => LD_en ); Inst_control_memory: control_memory PORT MAP( Read => Read, PCCLR => PCclear, NA => mxC_next, 31 MS => mxS_sel2, MC => mxC_sel1, IL => IRld, PI => PCinc, PL => PCld, MB => MB, Func_S => Func_S, MD => MD, RW => RW, MM => MM, MW => MW, Address => Address1, Data_out=> Data_out ); Inst_mux_c: mux_c PORT MAP( mxC_nxtadrs => mxC_next, mxC_opadrs => mxC_opcode, mxC_out => adrsin, mxC_sel => mxC_sel1 ); IRout <= IReg; IRop <= IReg(15 downto 9); halt<='1' when IRop="1010111" else '0'; IL <= IRld; PL <= PCld; PI <= PCinc; PCclr <= PCclear; 32 seIM IL <= PCin1; <= IRld; mxS_out MC <= LD_en; <= mxC_sel1; mxC_out <= adrsin; CAR_out <= Address1; NA <= mxC_next; dir_addr MS <= mxC_opcode; <= mxS_sel2; end Behavioral; 3)CAR --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 19:46:30 05/24/06 -- Design Name: -- Module Name: CAR - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: 33 --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity CAR is port( LD_en : in std_logic; adrsin : in std_logic_vector(7 downto 0); CAR_out : out std_logic_vector(7 downto 0) ); end CAR; architecture Behavioral of CAR is signal tmp_OUT : std_logic_vector(7 downto 0):="00000000"; begin process(adrsin,tmp_OUT) begin if (LD_en='0') then tmp_OUT <= tmp_OUT + "00000001"; elsif (LD_en='1') then tmp_OUT <= adrsin; end if; 34 end process; CAR_out <= tmp_OUT; end Behavioral; 4)Control Memory library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity control_memory is port( Read : in std_logic; PCCLR : out std_logic; NA : out std_logic_vector(7 downto 0); MS : out std_logic_vector(2 downto 0); MC : out std_logic; IL : out std_logic; P : out std_logic; PL : out std_logic; MB : out std_logic; Func_S : out std_logic_vector(4 downto 0); MD : out std_logic; RW : out std_logic; MM : out std_logic; MW : out std_logic; Address : in std_logic_vector(7 downto 0); Data_out: out std_logic_vector(25 downto 0) ); end control_memory; 35 architecture Behav of control_memory is type control_memory_Array is array (0 to 255) of std_logic_vector(25 downto 0); signal Content:control_memory_Array :=( 0 => "00000100100111100000000110", --nop 64 => "00001001000111101000010110", --add 65 => "00010001100111100000100110", --addi 66 => "01000010000111101000110110", --sub 67 => "00100000000111100001000110", --subi 68 => "00100000100111100001010110", 69 => "00100001100111100001100110", 70 => "00100010000111100001110110", 71 => "00100011000111100010000110", 72 => "00100011100111101010010110", 73 => "00100111000111100010100110", 74 => "00100111100111101010110110", 75 => "00100110000111100011000110", 76 => "00100100000111100011010110", 77 => "00101000000111101011100110", 78 => "00111100000111100011110110", 79 => "00101000000111100100000110", 80 => "00100000100111100100011110", 81 => "00101001000111100100100110", 82 => "00101001100111101100110110", 83 => "00101100000111100101000110", 84 => "00101100100111100101010110", --mulu 85 => "00101100000111100101100110", --mul 86 => "00101100000111101101110110", --muli 36 87 => "00101100000111100110000110", --hlt 88 => "00101100000111100110010110", 89 => "10101100000111000110100110", 90 => "00101100000111100110110110", 91 => "00101100000111100111000110", 92 => "00101100000111100111010110", others => "ZZZZZZZZZZZZZZZZZZZZZZZZZZ"); signal data_out1 :std_logic_vector(25 downto 0); begin process(Address) begin if( Read = '1' ) then ---Read set edilirse adres gözünün içeriği çıkışa verilir. data_out1 <= Content(conv_integer(Address)); end if; end process; PCCLR <= data_out1(25); NA <= data_out1(24 downto 17); MS <= data_out1(16 downto 14); MC <= data_out1(13); IL <= data_out1(12); PI <= data_out1(11); PL <= data_out1(10); MB <= data_out1(9); Func_S<= data_out1(8 downto 4); MD <= data_out1(3); RW <= data_out1(2); MM <= data_out1(1); MW <= data_out1(0); 37 Data_out <= data_out1 ; end Behav; 5)IR --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 19:45:45 05/24/06 -- Design Name: -- Module Name: IR - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating 38 ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity IR is port( IRin : in std_logic_vector(15 downto 0); IRin2 : in std_logic_vector(15 downto 0); IRld : in std_logic; IRIM : out std_logic_vector(15 downto 0); seIM : out std_logic_vector(15 downto 0); dir_addr out std_logic_vector(7 downto 0); IRout : out std_logic_vector(15 downto 0); DR_IR : out std_logic_vector(2 downto 0); SA_IR : out std_logic_vector(2 downto 0); SB_IR : out std_logic_vector(2 downto 0) ); end IR; architecture Behavioral of IR is signal IRout1,IRout2 : std_logic_vector(15 downto 0); begin process(IRin,IRout1) begin if(IRld = '1') then IRout1 <= IRin; dir_addr <= '0' & IRin(15 downto 9); ---Opcode bilgisi aktarılıyor. IRIM <= IRin; ---İvedi sayı belirleniyor. seIM <= "0000000" & IRin(8 downto 0); ---PC'ye dallanma için yüklenecek sayı belirleniyor. 39 DR_IR <= IRout1(8 downto 6); ---Hedef Register belirtici SA_IR <= IRout1(5 downto 3); ---A kaynak registeri belirtici SB_IR <= IRout1(2 downto 0); ---B kaynak registeri belirtici end if; IRout <= IRout1; end process; end Behavioral; 6)Mux_C --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 19:46:13 05/24/06 -- Design Name: -- Module Name: MUX_C - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; 40 use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity MUX_C is port ( mxC_nxtadrs : in std_logic_vector(7 downto 0); mxC_opadrs : in std_logic_vector(7 downto 0); mxC_out mxC_sel : out std_logic_vector(7 downto 0); : in std_logic ); end MUX_C; architecture Behavioral of MUX_C is begin process(mxC_nxtadrs,mxC_opadrs) begin if (mxC_sel = '0') then mxC_out <= mxC_nxtadrs; elsif (mxC_sel = '1') then mxC_out <= mxC_opadrs; end if; end process; end Behavioral; 7)Mux_S 41 --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 22:46:47 05/25/06 -- Design Name: -- Module Name: mux_s - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; 42 entity mux_s is port( NEG ZR : in std_logic; : in std_logic; CRY : in std_logic; OVR : in std_logic; mxS_sel: in std_logic_vector(2 downto 0); mxS_out: out std_logic ); end mux_s; architecture Behavioral of mux_s is begin process(ZR,mxS_sel) begin case mxS_sel is when "000" => mxS_out <= '0'; when "001" => mxS_out <= '1'; when "010" => mxS_out <= CRY; when "011" => mxS_out <= OVR; when "100" => mxS_out <= ZR; when "101" => mxS_out <= NEG; 43 when "110" => mxS_out <= not CRY; when others => mxS_out <= not ZR; end case ; end process; end Behavioral; 8)PC --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 19:45:12 05/24/06 -- Design Name: -- Module Name: PC - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; 44 use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity PC is port(clock: in std_logic; start: in std_logic; halt : in std_logic; PCclr: in std_logic; PCld : in std_logic; PCinc: in std_logic; PCin : in std_logic_vector(15 downto 0); PCout: out std_logic_vector(15 downto 0) ); end PC; architecture Behavioral of PC is signal tmp_PC: std_logic_vector(15 downto 0):= "0000000000000000";---PC içeriği başlangıçta sıfırlanıyor. signal run,say: std_logic; begin process(start,halt) ---Sistem açma kapama test ediliyor. begin if (halt='1') then 45 run <= '0'; elsif(start'event and start = '1') then run <= '1'; end if; end process; say <= clock and RUN; ---clock ve run her iki sinyal set edildiği zaman sistem çalışmaya başlar. process(say,PCclr,tmp_PC,halt) begin if(PCclr='1' or halt='1')then sıfırlanır. ---PCclr veya halt sinyalinden biri et edilmişse PCnin içeriği tmp_PC <= "0000000000000000"; elsif(say'event and say = '1') then if(PCld='1')then ---PC'yi belirlenen sayıyla yükleme test edilyor. tmp_PC <= PCin; elsif(PCinc='1')then ---PC'yi 1 artırma test ediliyor. tmp_PC <= tmp_PC +"0000000000000001"; end if; end if; end process; PCout <= tmp_PC; end Behavioral; 9)Datapath(main) --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 17:38:08 05/24/08 -- Design Name: -- Module Name: main - Behavioral 46 -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity main is port(clock : IN std_logic; m_alu_FS : IN std_logic_vector(4 downto 0); m_alu_V : OUT std_logic; m_alu_C : OUT std_logic; m_alu_N : OUT std_logic; 47 m_alu_Z : OUT std_logic; alucmp : OUT std_logic_vector(1 downto 0); m_alu_F : OUT std_logic_vector(15 downto 0); alu_b : OUT std_logic_vector(15 downto 0); alu_Bmul : out std_logic_vector(15 downto 0); m_wr_en : IN std_logic; reset : IN std_logic; m_adrs_D : IN std_logic_vector(2 downto 0); m_adrs_A : IN std_logic_vector(2 downto 0); m_adrs_B : IN std_logic_vector(2 downto 0); m_reg_A : OUT std_logic_vector(15 downto 0); m_reg_B : OUT std_logic_vector(15 downto 0); m_R0 : OUT std_logic_vector(15 downto 0); m_R1 : OUT std_logic_vector(15 downto 0); m_R2 : OUT std_logic_vector(15 downto 0); m_R3 : OUT std_logic_vector(15 downto 0); m_R4 : OUT std_logic_vector(15 downto 0); m_R5 : OUT std_logic_vector(15 downto 0); m_R6 : OUT std_logic_vector(15 downto 0); m_R7 : OUT std_logic_vector(15 downto 0); mxB_SB : IN std_logic_vector(15 downto 0); mxB_sel : IN std_logic; mxD_mrydata: IN std_logic_vector(15 downto 0); mxDmrydata_dp : IN std_logic_vector(15 downto 0); mxD_sel : IN std_logic; mxD_out : OUT std_logic_vector(15 downto 0); mxM_PC : IN std_logic_vector(15 downto 0); mxM_sel : IN std_logic; 48 mxM_out : OUT std_logic_vector(15 downto 0)); end main; architecture Behavioral of main is COMPONENT alu PORT( alu_A : IN std_logic_vector(15 downto 0); alu_B : IN std_logic_vector(15 downto 0); alu_Bmul : out std_logic_vector(15 downto 0); alu_FS : IN std_logic_vector(4 downto 0); alu_V : OUT std_logic; alu_C : OUT std_logic; alu_N : OUT std_logic; alu_Z : OUT std_logic; alu_F : OUT std_logic_vector(15 downto 0); alucmp : OUT std_logic_vector(1 downto 0) ); END COMPONENT; COMPONENT reg_file PORT( clock wr_en reset D : IN std_logic; : IN std_logic; : IN std_logic; : IN std_logic_vector(15 downto 0); adrs_D : IN std_logic_vector(2 downto 0); adrs_A : IN std_logic_vector(2 downto 0); adrs_B : IN std_logic_vector(2 downto 0); reg_A : OUT std_logic_vector(15 downto 0); reg_B : OUT std_logic_vector(15 downto 0); 49 R0 : OUT std_logic_vector(15 downto 0); R1 : OUT std_logic_vector(15 downto 0); R2 : OUT std_logic_vector(15 downto 0); R3 : OUT std_logic_vector(15 downto 0); R4 : OUT std_logic_vector(15 downto 0); R5 : OUT std_logic_vector(15 downto 0); R6 : OUT std_logic_vector(15 downto 0); R7 : OUT std_logic_vector(15 downto 0) ); END COMPONENT; COMPONENT mux_b PORT( mxB_SB : IN std_logic_vector(15 downto 0); mxB_regB : IN std_logic_vector(15 downto 0); mxB_sel : IN std_logic; mxB_out : OUT std_logic_vector(15 downto 0) ); END COMPONENT; COMPONENT mux_d PORT( mxDmrydata : IN std_logic_vector(15 downto 0); mxD_mrydata : IN std_logic_vector(15 downto 0); mxD_funit : IN std_logic_vector(15 downto 0); mxD_sel : IN std_logic; mxD_out : OUT std_logic_vector(15 downto 0) ); END COMPONENT; COMPONENT mux_m 50 PORT( mxM_adrs : IN std_logic_vector(15 downto 0); mxM_PC : IN std_logic_vector(15 downto 0); mxM_sel : IN std_logic; mxM_out : OUT std_logic_vector(15 downto 0) ); END COMPONENT; signal V_sig,C_sig,N_sig,Z_sig:std_logic; signal F_sig,A_sig,B_sig,mxB_regB,mxD_funit1,mxM_regA: std_logic_vector(15 downto 0); signal R0_sig,R1_sig,R2_sig,R3_sig,R4_sig,R5_sig,R6_sig,R7_sig:std_logic_vector(15 downto 0); begin Inst_alu: alu PORT MAP( alu_A => A_sig, alu_B => mxB_regB, alu_Bmul => alu_Bmul, alu_FS => m_alu_FS, alu_V => V_sig, alu_C => C_sig, alu_N => N_sig, alu_Z => Z_sig, alu_F => mxD_funit1, alucmp => alucmp ); Inst_reg_file: reg_file PORT MAP( clock => clock, wr_en => m_wr_en, reset => reset, D => F_sig, 51 adrs_D => m_adrs_D, adrs_A => m_adrs_A, adrs_B => m_adrs_B, reg_A => A_sig, reg_B => B_sig, R0 => R0_sig, R1 => R1_sig, R2 => R2_sig, R3 => R3_sig, R4 => R4_sig, R5 => R5_sig, R6 => R6_sig, R7 => R7_sig ); Inst_mux_b: mux_b PORT MAP( mxB_SB => mxB_SB, mxB_regB => B_sig, mxB_out => mxB_regB, mxB_sel => mxB_sel ); Inst_mux_d: mux_d PORT MAP( mxDmrydata =>mxDmrydata_dp, mxD_mrydata => mxD_mrydata, mxD_funit => mxD_funit1, mxD_out => F_sig, mxD_sel => mxD_sel ); Inst_mux_m: mux_m PORT MAP( 52 mxM_adrs => A_sig, mxM_PC => mxM_PC, mxM_sel => mxM_sel, mxM_out => mxM_out ); m_alu_V <= V_sig; m_alu_C <= C_sig; m_alu_N <= N_sig; m_alu_Z <= Z_sig; mxD_out <= F_sig; m_reg_A <= A_sig; m_reg_B <= B_sig; alu_b <= mxB_regB; m_R0 <= R0_sig; m_R1 <= R1_sig; m_R2 <= R2_sig; m_R3 <= R3_sig; m_R4 <= R4_sig; m_R5 <= R5_sig; m_R6 <= R6_sig; m_R7 <= R7_sig; end Behavioral; 10)ALU --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 19:44:20 05/24/06 53 -- Design Name: -- Module Name: ALU - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity alu is port ( alu_A : in std_logic_vector(15 downto 0); alu_B : in std_logic_vector(15 downto 0); alu_Bmul : out std_logic_vector(15 downto 0); 54 alu_FS : in std_logic_vector(4 downto 0); alu_V : out std_logic; alu_C : out std_logic; alu_N : out std_logic; alu_Z : out std_logic; alu_F : out std_logic_vector(15 downto 0); alucmp : out std_logic_vector(1 downto 0) ); end alu; architecture Behavioral of alu is signal alu_F_tmp2,alu_F_tmp3: signal alu_F_tmp std_logic_vector(31 downto 0); : std_logic_vector(15 downto 0):="0000000000000000"; signal alu_cout_tmp : std_logic_vector(1 downto 0); signal alu_cout_tmp1 : std_logic; signal alu_A1,alu_A2 : std_logic_vector(15 downto 0); signal alu_Bmul1,alu_Bmul2:std_logic_vector(15 downto 0):="0000000000000000"; begin process(alu_FS,alu_A,alu_B,alu_F_tmp,alu_cout_tmp1, alu_Bmul1,alu_F_tmp2,alu_A1,alu_A2,alu_Bmul2) begin case alu_FS is when "00000" => alu_F_tmp <= alu_A; ---No operation when "00001" => alu_F_tmp <= alu_A + alu_B; ---Addition when "00010" => alu_F_tmp <= alu_A + alu_B; ---Addition(immediate) when "00011" => 55 alu_F_tmp <= alu_A + not(alu_B)+1; ---Subtraction when "00100" => alu_F_tmp <= alu_A + not(alu_B)+1; ---Subtraction(immediate) when "00101" => alu_F_tmp <= alu_A + not(alu_B)+1; ---Compare if(alu_F_tmp < "0000000000000000") then alucmp <= "01"; elsif(alu_F_tmp = "0000000000000000") then alucmp <= "00"; elsif(alu_F_tmp > "0000000000000000") then alucmp <= "10"; end if; when "00110" => alu_F_tmp <= alu_A and alu_B ; ---AND when "00111" => alu_F_tmp <= alu_A and alu_B; ---AND(immediate) when "01000" => alu_F_tmp <= alu_A or alu_B; ---OR when "01001" => alu_F_tmp <= alu_A or alu_B; ---OR(immediate) when "01010" => alu_F_tmp <= not alu_A; ---NOT when "01011" => alu_F_tmp <= alu_A xor alu_B; ---XOR when "01100" => alu_F_tmp <= alu_A xor alu_B; ---XOR(immediate) when "01101" => alu_F_tmp <= alu_A(14 downto 0) & '0'; ---Logical Shift Left 56 when "01110" => alu_F_tmp <= '0' & alu_A(15 downto 1); ---Logical Shift Right when "01111" => alu_F_tmp <= alu_A(14 downto 0) & '0'; ---Arithmetic Shift Left when "10000" => if(alu_A(15) = '1')then alu_F_tmp <= '1' & alu_A(15 downto 1); ---Arithmetic Shift Right elsif(alu_A(15) = '0')then alu_F_tmp <= '0' & alu_A(15 downto 1); end if; when "10001" => alu_F_tmp <= alu_A; ---Load word when "10010" => alu_F_tmp <= alu_A; ---Move when "10011" => alu_F_tmp <= alu_B; ---Move(immediate) when "10100" => alu_F_tmp <= alu_A; when "10101" => ---Branch always ---Multiplication unsigned alu_F_tmp2 <= alu_A*alu_B; alu_A1 <= alu_F_tmp2(15 downto 0); alu_Bmul1 <= alu_F_tmp2(31 downto 16); alu_F_tmp <= alu_A1; when "10110" => ---Multiplication if(alu_A(15)='0')then alu_A2 <= alu_A; elsif(alu_A(15)='1')then alu_A2 <= not(alu_A)+1; 57 end if; if(alu_B(15)='0')then alu_Bmul2 <= alu_B; elsif(alu_B(15)='1')then alu_Bmul2 <= not(alu_B)+1; end if; alu_F_tmp2 <= alu_A2*alu_Bmul2; if((alu_A(15) xor alu_B(15))='0')then alu_F_tmp3 <= alu_F_tmp2; elsif((alu_A(15) xor alu_B(15))='1')then alu_F_tmp3 <= not(alu_F_tmp2)+1; end if; alu_A1 <= alu_F_tmp3(15 downto 0); alu_Bmul1 <= alu_F_tmp3(31 downto 16); alu_F_tmp <= alu_A1; when "10111" => ---Multiplication(immediate) if(alu_A(15)='0')then alu_A2 <= alu_A; elsif(alu_A(15)='1')then alu_A2 <= not(alu_A)+1; end if; if(alu_B(15)='0')then alu_Bmul2 <= alu_B; elsif(alu_B(15)='1')then alu_Bmul2 <= not(alu_B)+1; end if; 58 if((alu_A(15) xor alu_B(15))='0')then alu_F_tmp3 <= alu_A2*alu_Bmul2; elsif((alu_A(15) xor alu_B(15))='1')then alu_F_tmp3 <= not(alu_A2*alu_Bmul2)+1; end if; alu_A1 <= alu_F_tmp3(15 downto 0); alu_Bmul1 <= alu_F_tmp3(31 downto 16); alu_F_tmp <= alu_A1; when "11000" => alu_F_tmp <= alu_A ; ---Halt when "11001" => alu_F_tmp <= alu_A ; when "11010" => alu_F_tmp <= alu_B; when "11011" => alu_F_tmp <= alu_B; when "11100" => alu_F_tmp <= alu_B; when "11101" => alu_F_tmp <= alu_B; when others => alu_F_tmp <= "0000000000000000"; end case; if(alu_F_tmp(15) = '1') then alu_N <= '1'; elsif(alu_F_tmp(15) = '0') then alu_N <= '0'; 59 end if; if (alu_F_tmp = "0000000000000000") then alu_Z <= '1'; elsif(alu_F_tmp /= "0000000000000000") then alu_Z <= '0'; end if; alu_cout_tmp(1) <= alu_A(15) and alu_B(15); alu_cout_tmp(0) <= alu_A(14) and alu_B(14); alu_cout_tmp1 <= alu_cout_tmp(1) xor alu_cout_tmp(0); if(alu_cout_tmp1 ='1') then alu_V <= '1'; elsif(alu_cout_tmp1 ='0')then alu_V <= '0'; end if; if((alu_A(15) and alu_B(15))='1') then alu_C <= '1'; elsif((alu_A(15) and alu_B(15))='0') then alu_C <= '0'; end if; end process; alu_F <=alu_F_tmp; alu_Bmul <=alu_Bmul1; end Behavioral; 11)Mux_B -------------------------------------------------------------------------------60 -- Company: -- Engineer: --- Create Date: 19:46:03 05/24/06 -- Design Name: -- Module Name: MUX_B - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; 61 entity MUX_B is port ( mxB_SB : in std_logic_vector(15 downto 0); mxB_regB : in std_logic_vector(15 downto 0); mxB_out : out std_logic_vector(15 downto 0); mxB_sel : in std_logic ); end MUX_B; architecture Behavioral of MUX_B is begin process(mxB_sel,mxB_regB,mxB_SB) begin if(mxB_sel = '0')then mxB_out <= mxB_regB; elsif(mxB_sel = '1')then mxB_out <= mxB_SB; end if; end process; end Behavioral; 12)Mux_D --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 19:48:19 05/24/06 -- Design Name: -- Module Name: MUX_D - Behavioral 62 -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity MUX_D is port ( mxDmrydata : IN std_logic_vector(15 downto 0); mxD_mrydata : in std_logic_vector(15 downto 0); mxD_funit : in std_logic_vector(15 downto 0); mxD_out : out std_logic_vector(15 downto 0); mxD_sel : in std_logic 63 ); end MUX_D; architecture Behavioral of MUX_D is begin process(mxD_sel,mxD_mrydata,mxD_funit) begin if(mxD_sel = '0')then mxD_out <= mxD_funit; elsif(mxD_sel = '1')then mxD_out <= mxD_mrydata; end if; end process; end Behavioral; 14)Mux_M --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 22:43:32 05/25/06 -- Design Name: -- Module Name: mux_m - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: -- 64 -- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity mux_m is PORT( mxM_adrs : in std_logic_vector(15 downto 0); mxM_PC : in std_logic_vector(15 downto 0); mxM_sel : in std_logic; mxM_out : out std_logic_vector(15 downto 0) ); end mux_m; architecture Behavioral of mux_m is begin process(mxM_sel,mxM_PC,mxM_adrs) begin if(mxM_sel = '0')then mxM_out <= mxM_adrs; 65 elsif (mxM_sel = '1')then mxM_out <= mxM_PC; end if; end process; end Behavioral; 15)REG_FILE --------------------------------------------------------------------------------- Company: -- Engineer: --- Create Date: 19:44:54 05/24/06 -- Design Name: -- Module Name: REG_FILE - Behavioral -- Project Name: -- Target Device: -- Tool versions: -- Description: --- Dependencies: --- Revision: -- Revision 0.01 - File Created -- Additional Comments: --------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; 66 use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. ---- library UNISIM; ---- use UNISIM.VComponents.all; entity reg_file is port ( clock : in std_logic; wr_en : reset : in std_logic; D in std_logic; : in std_logic_vector(15 downto 0); adrs_D : in std_logic_vector(2 downto 0); adrs_A : in std_logic_vector(2 downto 0); adrs_B : in std_logic_vector(2 downto 0); reg_A : out std_logic_vector(15 downto 0); reg_B : out std_logic_vector(15 downto 0); R0 : out std_logic_vector(15 downto 0); R1 : out std_logic_vector(15 downto 0); R2 : out std_logic_vector(15 downto 0); R3 : out std_logic_vector(15 downto 0); R4 : out std_logic_vector(15 downto 0); R5 : out std_logic_vector(15 downto 0); R6 : out std_logic_vector(15 downto 0); R7 : out std_logic_vector(15 downto 0)); end reg_file; architecture Behavioral of reg_file is 67 type reg_type is array (0 to 7) of std_logic_vector(15 downto 0); signal K : reg_type; begin process(clock,reset,wr_en,D) begin if (reset='1') then K(0) <= "0000000000000000"; K(1) <= "0000000000000011"; K(2) <= "0000000000001010"; K(3) <= "0000000000000000"; K(4) <= "0000000000000000"; K(5) <= "1111111111111110"; K(6) <= "0000000000001000"; K(7) <= "0000000000000000"; elsif (clock'event and clock = '1') then if (wr_en = '1') then K(conv_integer(adrs_D)) <= ---Register yazma biti aktifse hedef registere sayıyı kopyala. D; end if; end if; end process; reg_A <=K(conv_integer(adrs_A)); reg_B <= K(conv_integer(adrs_B)); R0 <= K(0); R1 <= K(1); R2 <= K(2); R3 <= K(3); 68 R4 <= K(4); R5 <= K(5); R6 <= K(6); R7 <= K(7); end Behavioral; 16)Memory library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity memory is port (clock :in std_logic; Mre : in std_logic; Mwe : in std_logic; address :in std_logic_vector(15 downto 0); data_in :in std_logic_vector(15 downto 0); data_outmem,data: out std_logic_vector(15 downto 0)); end memory; architecture behv of memory is type ram_type is array (0 to 255) of std_logic_vector(15 downto 0); signal tmp_ram: ram_type:=( 0 => "0000000011001010", --Nop 1 => "1000000011001010", --Add 2 => "1000001001011010", --Addi 3 => "1000010001001010", --Sub 4 => "1000011001011010", --Subi 5 => "1000100000001010", --Cmp 6 => "1000101001001010", --And 69 7 => "1000110001001010", --Andi 8 => "1000111001001010", --Or 9 => "1001000001001010", --Ori 10 => "1001001001011010", --Not 11 => "1001010100011010", --Xor 12 => "1001011001001010", --Xori 13 => "1001100001001010", --Sll 14 => "1001101001001010", --Srl 15 => "1001110001001010", --Sla 16 => "1001111001001010", --Sra 17 => "1010000001000010", --Lw 18 => "1010001001011010", --Mov 19 => "1010010001001010", --Movi 20 => "1010011000010111", --Ba 21 => "1010100000101010", --Mulu 22 => "1010101000101011", --Mul 23 => "1010110000110101", --Muli 24 => "1010111001001010", --Halt 25 => "1011000001001010", 26 => "1011001001001010", 27 => "1011010001001010", 28 => "1011011001001010", 29 => "101110000100101 others=> "ZZZZZZZZZZZZZZZZ"); begin process(clock,Mwe,Mre,data_in,address) begin if (clock'event and clock = '1') then 70 if (Mre = '1' AND Mwe='0')then ---Memory okuma modunda data_outmem <= tmp_ram(conv_integer(address)); elsif(Mwe = '1'AND Mre='1')then ---Memory yazma modunda tmp_ram(conv_integer(address)) <= data_in; end if; end if; end process; data <= tmp_ram(conv_integer(address)); end behv; EK2:MODEL SİM ÇIKTILARI 71 72 Modelsim çıktısı alınırken öncelikle Edit à Radix à Decimal seçildi.Functionsel çıkışı için Unsigned olarak seçildi. 73