.


:




:

































 

 

 

 


3.




 

32- . , . , . , , , , .

, . . .

 

SISC

 

. (SISC) , 10 : (load), (store), (add), (multiply), (complement), (shift), (rotate), (nop), (halt) (branch). , .

, , . .

SISC . 3.1, - .3.2.

,-------------.

| |,--------------------------------.

| |---------| |

| | | |

`-------------' |,----------.,-------------. |

| | | | PSR | |

| | ( | | ( | |

| | ) | | | |

,-------------. | | | | )| |

| | | `----------' `-------------' |

| | | |

| |<------/-|,-----------------. |

| | | | IR | |

| | | | ( )| |

| |------/->| `-----------------' |

| |<----/---| |

| | | |

| | | |

| | |,---------------------------. |

`-------------' | | ALU | |

| | () | |

| `---------------------------' |

| |

| |

|,---------------------------. |

| | Register File | |

| | ( ) | |

| | | |

| `---------------------------' |

`--------------------------------'

. 3.1 SISC

 

,-------------------------------------------------------.

| |

| |

| (inst dst scr)|

| |

| |

| NOP NOP 0 NOP |

| BRANCH BRA 1 BRA mem, cc |

| LOAD LD 2 LD reg, mem1 |

| STORE STR 3 STR mem, sr |

| ADD ADD 4 ADD reg, sr |

| MULTIPLY MUL 5 MLT reg, sr |

| COMPLEMENT CMP 6 CMP reg, sr |

| SHIFT SHF 7 SHF reg, cnt |

| ROTATE ROT 8 ROT reg, cnt |

| HALT HLT 9 HLT |

| |

| |

| |

| A Always () 0 |

| C Carry () 1 |

| E Even ( ) 2 |

| P Parity ( ) 3 |

| Z Zero () 4 |

| N Negative () 5 |

| |

| |

| |

| mem - |

| mem1 - |

| reg - |

| scr - |

| cc - |

| cnt - shift/rotate, |

| >0=, <0= |

| |

| |

| |

| IR[31:28] |

| IR[27:24] |

| IR[27] 0=reg(mem), 1=- |

| (imm) |

| IR[26] 0=reg, 1=imm |

| IR[23:12] |

| IR[23:12] shift/rotate |

| IR[11:0] |

| |

| (PSR) |

| |

| PSR[0] Carry () |

| PSR[1] Even ( ) |

| PSR[2] Parity ( ) |

| PSR[3] Zero () |

| PSR[4] Negative ( ) |

`-------------------------------------------------------'

. 3.2 SISC

 

 

. . , (add)

{carry, sum}=in1+in2;

 

, : , - ; (in1 in2), .

. , .

SISC " " - :

 

module system;

...// , ,

...// , , initial

...// always ..

endmodule //

 

.

 

.

 

, , . :

32-

12-

5-

33- .

 

, , . 3.3.

, WIDTH. . , . ,

RFILE[3]=MEM[20];

21 4- . , 0 .

(12 ). 16.

,---------------------------------------------.

| // |

| |

| parameter WIDTH = 32; |

| parameter CYCLE = 10; |

| parameter ADDRSIZE = 12; |

| parameter MAXREGS = 16; |

| parameter MEMSIZE =(1<<ADDRSIZE); |

| |

| // |

| |

| reg [WIDTH-1:0] MEM[0:MEMSIZE-1], |

| RFILE[0:MAXREGS-1], |

| ir, // |

| src1, src2; |

|reg[WIDTH:0] result; |

|reg [ADDRSIZE-1:0] pc; |

|reg[4:0] psr; |

|reg dir; |

|reg reset; |

| |

|integer i; |

`---------------------------------------------'

. 3.3

 

33- . , 12 . psr 5 : (carry), (even), (parity), (zero) (negative).

 

,--------------------------------------------------.

| // |

| |

| `define OPCODE ir[31:28] |

| `define SRC ir[23:12] |

| `define DST ir[11:0] |

| `define SRCTYPE ir[27] |

| `define DSTTYPE ir[26] |

| `define CCODE ir[27:24] |

| `define SRCNT ir[23:12] |

| |

| // |

| |

| `define REGTYPE 0 |

| `define IMMTYPE 1 |

| |

| // |

| |

| `define NOP 4'b0000 |

| `define BRA 4'b0001 |

| `define LD 4'b0010 |

| `define STR 4'b0011 |

| `define ADD 4'b0100 |

| `define MUL 4'b0101 |

| `define CMP 4'b0110 |

| `define SHF 4'b0111 |

| `define ROT 4'b1000 |

| `define HLT 4'b1001 |

`--------------------------------------------------'

. 3.4

 

(parameter) WIDTH CYCLE. . , 16 , ADDRSIZE 12 14. MEMSIZE 4 16, 0 16-1.

'define (), . 3.4, , . ( ) . , SRCTYPE DSTTYPE , 2 , :

 

`define SCRTYPE ir[26]

`define DSTTYPE ir[27]

 

. 3.4 .

 

 

, , . -, . . , , .

, : , . .

, "-". . 3.5 Verilog (main) . , always, main_process : (fetch), (execution) (write_result). fetch , execute , write_result . .

,---------------------------------------------.

| always begin: main_process |

| if (!reset) begin |

| #CYCLE fetch; |

| #CYCLE execute; |

| #CYCLE write_result; |

| end |

| else #CYCLE; |

| end |

`---------------------------------------------'

. 3.5

 

, , . 3 . .

(reset) (, ) , . , main reset. if-then-else else . always reset.

 

 

, . , , . 3.6. .

,-------------------------------------------------.

|task apply_reset; |

| begin |

| reset = 1; |

| #YCLE; |

| reset = 0; |

| pc = 0; |

| end |

|endtask |

| |

| initial begin: prog_load |

| $readmemb("sisc.prog",MEM); |

| $monitor("%d %d %h %h %h",$time,pc, |

| RFILE[0],RFILE[1],RFILE[2]); |

| apply_reset; |

| end |

`-------------------------------------------------'

. 3.6

 

Verilog $readmemb ASCII mem.

apply_reset (. 3.6). , 0.

$monitor , .

 

 

, main , , . getsrc, getdst checkcond. fetch, execute, write_results, set_condcode, clear_condcode apply_reset.

execute (..3.7). case OPCODE , .

. , , .

(nop) - . halt $stop. . branch , Verilog.

load store . shift rotate Verilog.

add multiply . . , . , WIDTH, (WIDTH+1)- WIDTH+1 , WIDTH .

, ( 2*WIDTH) . - , . - , WIDTH+1 . SISC 32 .

, Verilog .

,---------------------------------------------------------.

| task execute; |

| begin |

| case (`OPCODE) |

| `NOP:; |

| `BRA: begin |

| if (checkcond(`CCODE)) pc = `DST; |

| end |

| `HLT: begin |

| $display("Halt..."); $stop; |

| end |

| `LD: begin |

| clearcondcode; |

| if (`SRC) RFILE[`DST] =`SRC; |

| else RFILE[`DST] = MEM[`SRC]; |

| setcondcode({1'b0,RFILE[`DST]}); |

| end |

| `STR: begin |

| clearcondcode; |

| if (`SRC) MEM[`DST] = `SRC; |

| else MEM[`DST] = RFILE[`SRC]; |

| end |

| `ADD: begin |

| clearcondcode; |

| src1 =getsrc(ir); |

| src2 = getdst(ir); |

| result = src1 + src2; |

| setcondcode(result); |

| end |

|... |

|... |

| default: $display("Invalid Opcode found"); |

| endcase |

|end |

|endtask |

`---------------------------------------------------------'

. 3.7 execute

 

 

, . , "1" . . 3.21.

sisc.prog mem $readmemb. 16- $readmemh.

 

 

 

, , , . , . :

%verilog sisc_instruction_set_model.v

sisc_instruction_set_model.v , Verilog SISC .

Verilog. , . . , , ..

Verilog . , .

. .

 

 

, . , , . .

disprm, , . 3.8. . , , , 20-, 21- 22-; , $display , .

,----------------------------------------------------.

|// |

|// |

| task disprm; |

| input rm; |

| input [ADDRSIZE-1:0] adr1, adr2; |

| begin |

| if (rm ==`REGTYPE) begin |

| while (adr2 >= adr1) begin |

| $display("REGFILE[%d]=%d\n", |

| adr1,RFILE[adr1]); |

| adr1 = adr1 + 1; |

| end |

| end |

| else begin |

| while (adr2 >= adr1) begin |

| $display("MEM[%d]=%d\n", |

| adr1,MEM[adr1]); |

| adr1 = adr1 + 1; |

| end |

| end |

|end |

|endtask |

`----------------------------------------------------'

. 3.8

 

apply_reset . (), . apply_reset $readmemb, .

 

 

SISC . .

SISC .

 

?

 

. .

, , . , . .

,----------------------------------------------------.

| # |

| 1 F1 F1 |

| 2 E1 F2 E1 |

| 3 W1 F3 E2 W1 |

| 4 F2 F4 E3 W2 |

| 5 E2 F5 E4 W3 |

| 6 W2 E5 W4 |

| 7 F3 W5 |

| 8 E3 |

| 9 W3 |

| 10 F4 |

| 11 E4 |

| 12 W4 F12 |

| 13 F5 F13 E12 W11 |

| 14 E5 F14 E13 W12 |

| 15 W5 F15 E14 W13 |

| |

| 5 15 |

| (- )*3 |

| 5 7 |

| (- )+2 |

| |

|: F=, =, W= |

| |

`----------------------------------------------------'

. 3.9 3-

 

. 3.9 , 3- . (F), () (W). , . , , . .

( ). , . , , , . , ( ), , , . , ( , ).

. " ". halt .

load store. , . , , . .

 

 

SISC , 3- . (fetch), (execute) (write_result). , . (brnch), (load) (store).

,------------------------------------------------.

| always @(posedge clock) begin: phase1_loop |

| if (!reset) begin |

| fetched = 0; |

| executed = 0; |

| if (!queue_full &&!mem_access) |

| -> do_fetch; |

| if (qsize || mem_access) |

| -> do_execute; |

| if (result_ready) |

| -> do_write_results; |

| end |

| end |

`------------------------------------------------'

. 3.10

 

SISC , . . 3.10 ( 1, ) - do_fetch, do_execute do_write_result. phase1_loop main_process SISC . . . 3.11 , . (reg), (wire) (event).

,-------------------------------------------------------.

| parameter QDEPTH=3; // |

| // |

| reg [WIDTH-1:0] IR_Queue[0:QDEPTH-1],wir; |

| |

| // |

| reg [WIDTH:0] wresult; |

| reg [2:0] eptr, fptr, qsize; |

| |

| // / |

| reg mem_access, branch_taken, halt_found; |

| reg result_ready; |

| reg executed, fetched; |

| reg queue_full; |

| |

| event do_fetch, do_execute, do_write_results; |

`-------------------------------------------------------'

 

. 3.11

 

, if phase1_loop , , . .

 

 

, . , . IR_Queue. , . 2- fptr IR_Queue, . qsize . , IR_Queue . , , ; , IR_Queue , .

mem_access load store. if, do_fetch. fetch (. . 3.12) , IR_Queue, IR. "1" , .

,-----------------------------------------.

| task fetch; |

| begin |

| IR_Queue[fptr]=MEM[pc]; |

| fetched=1; |

| end |

| endtask |

`-----------------------------------------'

. 3.12 fetch

 

 

. . , , load store, . : , - , , , - ( ), .

, - src1 src2 - result. , : . , .

. load store, . . 3.13 , , load. load "1" mem_access . . , . load , , mem_access "1". mem_access, , .

, . SISC : (branch) (halt). . 3.7 flush_queue .

,-------------------------------------------------------.

|if (!mem_access) ir=IR_Queue[eptr]; |

| `LD: begin |

| if (mem_access == 0) // |

| mem_access = 1; // |

| else begin // |

|...... // |

| // |

| end |

|end |

`-------------------------------------------------------'

. 3.13 load

 

,-------------------------------------------------.

| task flush_queue; |

| begin |

| // pc branch |

| fptr = 0; |

| eptr = 0; |

| qsize = 0; |

| branch_taken = 0; |

| end |

 

| endtask |

`-------------------------------------------------'

. 3.14

 

, task . 3.7. set_condcode, clear_condcode checkcond .

 

 

: wresult wir. , result_ready. result wresult, ir - wir. wresult , dest wir. wir , , dest -

.

, ir wir , . copy_result (. . 3.15) , , . 3.16 , .

 

,----------------------------------------------------.

| task copy_results; |

| begin |

| if ((`OPCODE >= `ADD) && (`OPCODE < `HLT)) begin |

| setcondcode(result); |

| wresult = result; |

| wir = ir; |

| result_ready = 1; |

| end |

| end |

| endtask |

`----------------------------------------------------'

. 3.15

 

, . , , . - . .

,--------------------------------------------------------.

| task write_result; |

| begin |

| if ((`WOPCODE >= `ADD) && (`WOPCODE < `HLT)) begin |

| if (`WDSTTYPE == `REGTYPE) |

| RFILE[`WDST] = wresult; |

| else MEM[`WDST] = wresult; |

| result_ready = 0; |

| end |

| end |

| endtask |

`--------------------------------------------------------'

. 3.16

 

2

 

SISC . . :

* () ,

.

*

.

* (ir)

(wir wresult -

).

* (eptr

fptr) .

,--------------------------------------------------------.

| task set_pointers; // |

| begin |

| case ({fetched,executed}) |

| 2'b00:; // |

| 2'b01: begin // |

| qsize = qsize - 1; |

| eptr = (eptr + 1)%QDEPTH; |

| end |

| 2'b10: begin // |

| qsize = qsize + 1; |

| fptr = (fptr + 1) % QDEPTH; |

| end |

| 2'b11: begin // |

| eptr = (eptr + 1)%QDEPTH; |

| fptr = (fptr + 1) % QDEPTH; |

| end |

| endcase |

| end |

| endtask |

| always @(negedge clock) begin: phase2_block |

| if (!reset) begin |

| if (!mem_access &&!branch_taken) |

| copy_results; |

| if (branch_taken) pc = `DST; |

| else if (!mem_access) pc = pc+1;... |

| if (branch_taken || halt_found) |

| flush_queue; |

| else set_pointers; |

| if (halt_found) begin |

| $stop; |

| halt_found = 0; |

| end |

| end |

| end |

`--------------------------------------------------------'

. 3.17 2

 

. 3.17. set_pointers phase2_loop.

, , , . halt , . , halt_found.

 

 

. " ". , , - , , . .

. , . 3.18. - - R2 , .

. (I3) (R1 R2) R1. (I4) R1 R3. - R1 I4. ( I3 R1.)

,-------------------------------------------.

| |

| I1: ADD R1, R2 // R1= R1 + R2 |

| I2: CMP R3, R2 // R3= ~R2 |

| |

| |

| I3: ADD R1, R2 // R1= R1 + R2 |

| I4: CMP R3, R1 // R3 = ~R1 |

`-------------------------------------------'

. 3.18

 

R1 , , I4 R1. . .

- nop , . , . , : , . , , SISC . . 3.19.

,-----------------------------------------------------.

| I3: ADD R1, R2 // R1 = R1 + R2 |

| IX: NOP // |

| I4: CMP R3, R1 // R3= ~R1 |

`-----------------------------------------------------'

. 3.19

 

,--------------------------------------------------.

| reg bypass; |

| |

| function [31:0] getsrc; |

| input [31:0] i; |

| begin |

| if (bypass) getsrc = result; |

| else if (`SRCTYPE === `REGTYPE) |

| getsrc = RFILE[`SRC]; |

| else getsrc = `SRC; // |

| end |

| endfunction |

| |

| function [31:0] getdst; |

| input [31:0] i; |

| begin |

| if (bypass) getdst=result; |

| else if (`DSTTYPE === `REGTYPE) |

| getdst = RFILE[`DST]; |

| else $display("Error: Immediate data |

| cannot be destination."); |

| end |

| endfunction |

| |

| always @(do_execute) begin: execute_block |

| if (!mem_access) begin |

| ir=IR_Queue[eptr]; |

| bypass=((`SCR == `WDST) || |

| (`DST == `WDST)); |

| end |

| execute; |

| if (!mem_access) executed = 1; |

| end |

`--------------------------------------------------'

. 3.20

 

. (src1 src2) . . "". , . 3.20, SISC .

, , store, . , .

 

 

, - , , . , , . NAND . , . . . .

, , () . , . "0" "1", . ( ).

, , , . , , . . ( ).

Verilog-XL , ASCII , : $readmemb $readmemh. $readmemb , , $readmemh 16-. , (_) .

. $readmemb initial (. . 3.6 , prog_load). , "1" - . 3.21. , . . , , .

----------------------------------------------------------.

// '1 |

// |

// |

0010_1000_0000_0000_0000_0000_0000_0001// LD R1,#0 |

0010_0000_0000_0000_1001_0000_0000_0000// LD R2,NMBR |

0001_0010_0000_0000_0000_0000_0000_0100//STRT:BRA L1 |

0100_1000_0000_0000_0001_0000_0000_0001// ADD R1,#1 |

0111_1000_0000_0000_0001_0000_0000_0000//L1:SHF R2,#1 |

0001_0100_0000_0000_0000_0000_0000_0111// BRA L2,ZERO |

0001_0000_0000_0000_0000_0000_0000_0010// BRA STRT,ALW|

0011_0000_0000_0000_0001_0000_0000_1010//L2:STR RSLT, R2|

1001_1111_1111_1111_1111_1111_1111_1111// HLT |

0101_0101_0101_0101_1010_1010_1010_1010//NMBR:5555a |

0000_0000_0000_0000_0000_0000_0000_0000//RSLT:00000000 |

----------------------------------------------------------'

. 3.21

 

, . reset , $readmemb .

 

 

, Verilog. . , . .

Verilog - . 3.22. , , . , , .

 

/*

* ,

* SISC .

* sisc_declarations.v

*

* %W% %G% --

*/

 

//

 

parameter CYCLE = 10; //

parameter WIDTH = 32; //

parameter ADDRSIZE = 12; //

parameter MEMSIZE = (1<<ADDRSIZE);//

//

parameter MAXREGS = 16; //

//

//

parameter SBITS = 5; //

 

//

 

reg [WIDTH-1:0] MEM[0:MEMSIZE-1], //

RFILE[0:MAXREGS-1], //

ir, //

src1, src2; //

reg [WIDTH:0] result; //

reg [SBITS-1:0] psr; //

reg [ADDRSIZE-1:0] pc; //

reg dir; //

reg reset; //

integer i; //

 

//

 

`define TRUE 1

`define FALSE 0

 

`define DEBUG_ON debug=1

`define DEBUG_OFF debug=0

 

//

 

`define OPCODE ir[31:28]

`define SRC ir[23:12]

`define DST ir[11:0]

`define SRCTYPE ir[27] // ,0= (

// load),1=

// (imm)

`define DSTTYPE ir[26] // , 0=, 1=imm

`define CCODE ir[27:24]

`define SRCNT ir[23:12] // shift/

//rotate -=, +=

 

//

 

`define REGTYPE 0

`define IMMTYPE 1

 

//

 

`define NOP 4'b0000

`define BRA 4'b0001

`define LD 4'b0010

`define STR 4'b0011

`define ADD 4'b0100

`define MUL 4'b0101

`define CMP 4'b0110

`define SHF 4'b0111

`define ROT 4'b1000

`define HLT 4'b1001

 

//

 

`define CARRY psr[0]

`define EVEN psr[1]

`define PARITY psr[2]

`define ZERO psr[3]

`define NEG psr[4]

 

//

 

// , ...

`define CC 0 //

`define CCE 1 // -

`define CCP 2 //C

//

`define CCZ 3 //

`define CCN 4 //

`define CCA 5 //

 

`define RIGHT 0 //

// Rotate/Shift

`define LEFT 1 //

// Rotate/Shift

 

//

 

function [WIDTH-1:0] getsrc;

input [WIDTH-1:0] in;

begin

if (`SRCTYPE === `REGTYPE) begin

getsrc = RFILE[`SRC];

end

else begin //

getsrc = `SRC;

end

end

endfunction

 

function [WIDTH-1:0] getdst;

input [WIDTH-1:0] in;

begin

if (`DSTTYPE === `REGTYPE) begin

getdst = RFILE[`DST];

end

else begin //

$display("Error:Immediate data cant be destination.");

end

end

endfunction

 

// /

 

function checkcond; // 1,

input [4:0] ccode;

begin

case (ccode)

`CCA: checkcond = 1;

`CCC: checkcond = `CARRY;

`CCE: checkcond = `EVEN;

`CCP: checkcond = `PARITY;

`CCZ: checkcond = `ZERO;

`CCN: checkcond = `NEG;

endcase

end

 

endfunction

 

task clearcondcode; // PSR

begin

psr = 0;

end

endtask

 

task setcondcode; //

//

input [WIDTH:0] res;

begin

`CARRY = res[WIDTH];

`EVEN = ~res[0];

`PARITY = ^res;

`ZERO = ~(|res);

`NEG = res[WIDTH-1];

end

endtask

 

/*=================================================

*

* SISC

*

* sisc_instruction_set_model.v

*

* - fetch,execute,write.

*

* %W% %G% --

*/

 

module instruction_set_model;

 

// sisc_declarations.v

// ,

// .

// .

// - fetch, execute, write_result

 

task fetch; // 1

//

begin

ir = MEM[pc];

pc = pc + 1;

end

endtask

 

task execute;//

begin

case (`OPCODE)

`NOP:;

`BRA: begin

if (checkcond(`CCODE) == 1) pc = `DST;

end

`LD: begin

clearcondcode;

if (`SRC) RFILE[`DST] = `SRC;

else RFILE[`DST] = MEM[`SRC];

setcondcode({1'b0,RFILE[`DST]});

end

`STR: begin

clearcondcode;

if (`SRC) MEM[`DST] = `SRC;

else MEM[`DST] = RFILE[`SRC];

end

`ADD: begin

clearcondcode;

src1 = getsrc(ir);

src2 = getdst(ir);

result = src1 + src2;

setcondcode(result);

end

`MUL: begin

clearcondcode;

src1 = getsrc(ir);

src2 = getdst(ir);

result = src1 * src2;

setcondcode(result);

end

`CMP: begin

clearcondcode;

src1 = getsrc(ir);

result = ~src1;

setcondcode(result);

end

`SHF: begin

clearcondcode;

src1 = getsrc(ir);

src2 = getdst(ir);

i = src1[ADDRSIZE-1:0];

result = (i>=0)? (src2 >> i): (src2 << -i);

setcondcode(result);

end

`ROT: begin

clearcondcode;

src1 = getsrc(ir);

src2 = getdst(ir);

dir = (src1[ADDRSIZE-1]==0)? `RIGHT: `LEFT;

i = (src1[ADDRSIZE-1]==0)?

src1: -src1[ADDRSIZE-1:0];

while (i > 0) begin

if (dir == `RIGHT) begin

result = src2 >> 1;

result[WIDTH-1] = src2[0];

end

else begin

result = src2 << 1;

result[0] = src2[WIDTH-1];

end

i = i - 1;

src2 = result;

end

setcondcode(result);

end

`HLT: begin

$display("Halt...");

$stop;

end

default: $display("Error: Illegal Opcode.");

endcase

end

endtask

 

//

 

task write_result;

begin

if ((`OPCODE >= `ADD) && (`OPCODE < `HLT)) begin

if (`DSTTYPE == `REGTYPE) RFILE[`DST] = result;

else MEM[`DST] = result;

end

end

endtask

 

// ....

 

task apply_reset;

begin

reset = 1;

#CYCLE

reset = 0;

pc = 0;

end

endtask

 

task disprm;

input rm;

input [ADDRSIZE-1:0] adr1, adr2;

begin

if (rm == `REGTYPE) begin

while (adr2 >= adr1) begin

$display("REGFILE[%d]=%d\n",adr1,RFILE[adr1]);

adr1 = adr1 + 1;

end

end

else begin

while (adr2 >= adr1) begin

$display("MEM[%d]=%d\n",adr1,MEM[adr1]);

adr1 = adr1 + 1;

end

end

end

endtask

 

// initial always

 

initial begin: prog_load

$readmemb("sisc.prog",MEM);

$monitor("%d %d %h %h %h",

$time,pc,RFILE[0],RFILE[1],RFILE[2]);

apply_reset;

end

 

always begin: main_process

if (!reset) begin

#CYCLE fetch;

#CYCLE execute;

#CYCLE write_result;

end

else #CYCLE;

end

endmodule

 

/*===========================================

*

*

* SISC

*

*sisc_pipeline_model.v

*

* %W% %G% --

*/

 

module pipeline_control;

 

// ,

//, . ,

//

// .

 

//

 

parameter HALFCYCLE = (CYCLE/2); //

parameter QDEPTH = 3; //

 

//

//

 

reg [WIDTH-1:0] IR_Queue[0:QDEPTH-1], //

wir, //

//

reg [2:0] eptr, fptr, qsize;//

reg clock; //

//

reg [WIDTH:0] wresult; //

//

 

// -

 

reg mem_access, branch_taken, halt_found;

reg result_ready;

reg executed, fetched;

reg debug;

 

wire queue_full;

 

event do_fetch, do_execute, do_write_results;

 

//

 

`define WOPCODE wir[31:28]

`define WDST wir[11:0]

`define WDSTTYPE wir[26] // , 0=,

//1=imm

//

// (queue_full)

 

assign queue_full = (qsize == QDEPTH);

 

//

 

task fetch;

begin

IR_Queue[fptr] = MEM[pc];

fetched = 1;

end

endtask

 

task execute;

begin

if (!mem_access) ir = IR_Queue[eptr];//

//

//

//(IR)

case (`OPCODE)

`NOP: begin

if (debug) $display("Nop...");

end

`BRA: begin

if (debug) $write("Branch...");

if (checkcond(`CCODE) == 1) begin

pc = `DST;

branch_taken = 1;

end

end

`LD: begin

if (mem_access == 0) begin

mem_access = 1; //

//

end

else begin //

if (debug) $display("Load...");

clearcondcode;

if (`SRCTYPE) begin

RFILE[`DST] = `SRC;

end

else RFILE[`DST] = MEM[`SRC];

setcondcode({1'b0,RFILE[`DST]});

mem_access = 0;

end

end

`STR: begin

if (mem_access == 0) begin

mem_access = 1; //

//

end

else begin //

if (debug) $display("Store...");

clearcondcode;

if (`SRCTYPE) begin

MEM[`DST] = `SRC;

end

else MEM[`DST] = RFILE[`SRC];

mem_access = 0;

end

end

 

// ADD, MUL, CMP, SHF ROT

// , .

 

`HLT: begin

$display("Halt...");

halt_found = 1;

end

default: $display("Error: Wrong Opcode in instruction.");

endcase

 

if (!mem_access) executed = 1; // ?

end

endtask

 

task write_result;

begin

if ((`WOPCODE >= `ADD) && (`WOPCODE < `HLT)) begin

if (`WDSTTYPE == `REGTYPE) RFILE[`WDST] = wresult;

else MEM[`WDST] = wresult;

result_ready = 0;

end

end

endtask

 

task flush_queue;

begin

// pc

// branch

fptr = 0;

eptr =





:


: 2017-04-15; !; : 688 |


:

:

, , .
==> ...

1896 - | 1536 -


© 2015-2024 lektsii.org - -

: 1.049 .