1 / 11

Project 4 Help

Project 4 Help. event GO; parameter mem_size = ‘h1000; ………………. `define word_size [15:0] `define byte_size [7:0] `define address_size [15:0] `define num_regs [15:0] ……………. reg `word_size I //instruction register MCR //memory count register ICR //instruction count register …………….

wolfe
Télécharger la présentation

Project 4 Help

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Project 4 Help

  2. event GO; parameter mem_size = ‘h1000; ……………….. `define word_size [15:0] `define byte_size [7:0] `define address_size [15:0] `define num_regs [15:0] …………… reg `word_size I //instruction register MCR //memory count register ICR //instruction count register …………… `define sp R[14] // stack pointer `define pc R[15] // program counter `define op2 I[15:14] // upper part of op_code `define m2 I[13:12] // lower part op_code `define Y4 I[11:8] // Y-operand (4 bits) `define Y3 I[10:8] // Y-operand (3 bits) `define X4 I[7:4] // X-operand (4 bits) `define Z4 I[3:0] // X-operand (4 bits)

  3. // main loop initial begin @GO initialize; printmem; forever begin : main_loop #1 $display (“-----------------------------------------------”); fetch; execute; $display (“pc=%h”, `pc); end end

  4. task initialize; …….. endtask task fetch; reg `byte_size I1, I2; begin I1= READ(`pc); // READ is function `pc = `pc +1; I2 = READ(`pc); `pc = `pc +1; I={I1, I2}; ICR= ICR + 1; end endtask

  5. // memory declaration reg `byte_size MB[0 : mem_size]; function `byte_size READ; input `address_size address; begin READ = MB[address]; MCR = MCR +1; end endfunction task write; input `address_size address; input `byte_size D_byte; begin MB[address] = D_Byte; MCR = MCR + 1; end endtask

  6. task execute; begin case (`op2) 2’b00 : load; 2’b01 :`sto_etc; 2’b10 : branch; 2’b11 : arith; endcase endtask task load; // implement ldb, ldw reg `byte_size I1, I2; reg `address_size address; begin case(`m2) 2’b00 : begin //ldb rd c I1 = I[7:0]; I2 = 0; R[`Y4] = {I2, I1}; $ display(“load byte-immediate”); end

  7. // if m2 = 0  immediate ldb // if m2 = 1  indexed ldb // if m2 = 2  immediate ldw // if m2 = 3  indexed ldw 2’b01: 2’b10: 2’b11: ……………..

  8. task sto_etc; // implement stb stw, nop, hlt // if m2 = 0  indexed stb // if m2 = 1  indexed stw // if m2 = 2  nop // if m2 = 3  hlt case (`m2) 2’b00:begin …. end 2’b01: 2’b10: nop; 2’b11: hlt; task hlt; begin $display (“system halted”); $finish; end endtask task nop; ….. …. ….. endtask

  9. task branch; // implement bra, brr // if m2 = 0  absolute branch, reg // if m2 = 1  absolute branch, con // if m2 = 2  relative branch. reg // if m2 = 3  relative branch, con case (`m2) 2’b00 : begin compare(result, , , ); //task compare if (result) begin …… end … … … endtask

  10. task compare; output result; input [15:0] reg1, reg2; input [3:0] opcode; begin case (opcode) 4’b0000 : result =reg1 < reg 2; ……. …….. 4’b1111 : result = reg1[15] != reg2[15] // signs not equal

  11. task arith; // if m2 = 0 & I[11] = 0 - & I[11] = 1 - // if m2 = 1 & I[11] = 0 - & I[11] = 1 - // if m2 = 2 // if m2 = 3

More Related