1 |
2 |
simont |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// 8051 cores acccumulator ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the 8051 cores project ////
|
6 |
|
|
//// http://www.opencores.org/cores/8051/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// accumulaor register for 8051 core ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// To Do: ////
|
12 |
|
|
//// Nothing ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// Author(s): ////
|
15 |
|
|
//// - Simon Teran, simont@opencores.org ////
|
16 |
|
|
//// ////
|
17 |
|
|
//////////////////////////////////////////////////////////////////////
|
18 |
|
|
//// ////
|
19 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
20 |
|
|
//// ////
|
21 |
|
|
//// This source file may be used and distributed without ////
|
22 |
|
|
//// restriction provided that this copyright statement is not ////
|
23 |
|
|
//// removed from the file and that any derivative work contains ////
|
24 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
25 |
|
|
//// ////
|
26 |
|
|
//// This source file is free software; you can redistribute it ////
|
27 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
28 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
29 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
30 |
|
|
//// later version. ////
|
31 |
|
|
//// ////
|
32 |
|
|
//// This source is distributed in the hope that it will be ////
|
33 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
34 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
35 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
36 |
|
|
//// details. ////
|
37 |
|
|
//// ////
|
38 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
39 |
|
|
//// Public License along with this source; if not, download it ////
|
40 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
41 |
|
|
//// ////
|
42 |
|
|
//////////////////////////////////////////////////////////////////////
|
43 |
|
|
//
|
44 |
|
|
// ver: 1
|
45 |
|
|
//
|
46 |
|
|
|
47 |
|
|
// synopsys translate_off
|
48 |
|
|
`include "oc8051_timescale.v"
|
49 |
|
|
// synopsys translate_on
|
50 |
|
|
|
51 |
|
|
`include "oc8051_defines.v"
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
module oc8051_acc (clk, rst, bit_in, data_in, data2_in, wr, wr_bit, wad2, wr_addr, rd_addr,
|
55 |
|
|
data_out, bit_out, p);
|
56 |
|
|
// clk (in) clock
|
57 |
|
|
// rst (in) reset
|
58 |
|
|
// bit_in (in) bit input - used in case of writing bits to acc (bit adddressable memory space - alu carry) [oc8051_alu.desCy]
|
59 |
|
|
// data_in (in) data input - used to write to acc (from alu destiantion 1) [oc8051_alu.des1]
|
60 |
|
|
// data2_in (in) data 2 input - write to acc, from alu detination 2 - instuctions mul and div [oc8051_alu.des2]
|
61 |
|
|
// wr (in) write - actine high [oc8051_decoder.wr -r]
|
62 |
|
|
// wr_bit (in) write bit addresable - actine high [oc8051_decoder.bit_addr -r]
|
63 |
|
|
// wad2 (in) write data 2 [oc8051_decoder.wad2 -r]
|
64 |
|
|
// wr_addr (in) write address (if is addres of acc and white high must be written to acc) [oc8051_ram_wr_sel.out]
|
65 |
|
|
// data_out (out) data output [oc8051_alu_src1_sel.acc oc8051_alu_src2_sel.acc oc8051_comp.acc oc8051_ram_sel.acc]
|
66 |
|
|
// p (out) parity [oc8051_psw.p]
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
input clk, rst, wr, wr_bit, wad2, bit_in;
|
70 |
|
|
input [2:0] rd_addr;
|
71 |
|
|
input [7:0] wr_addr, data_in, data2_in;
|
72 |
|
|
|
73 |
|
|
output p, bit_out;
|
74 |
|
|
output [7:0] data_out;
|
75 |
|
|
|
76 |
|
|
reg [7:0] data_out;
|
77 |
|
|
reg bit_out;
|
78 |
|
|
|
79 |
|
|
//
|
80 |
|
|
//calculates parity
|
81 |
|
|
assign p = ^data_out;
|
82 |
|
|
|
83 |
|
|
//
|
84 |
|
|
//writing to acc
|
85 |
|
|
//must check if write high and correct address
|
86 |
|
|
always @(posedge clk or posedge rst)
|
87 |
|
|
begin
|
88 |
|
|
if (rst)
|
89 |
|
|
data_out <= #1 `OC8051_RST_ACC;
|
90 |
|
|
else if (wad2)
|
91 |
|
|
data_out <= #1 data2_in;
|
92 |
5 |
markom |
else if (wr) begin
|
93 |
|
|
if (!wr_bit) begin
|
94 |
|
|
if (wr_addr==`OC8051_SFR_ACC)
|
95 |
|
|
data_out <= #1 data_in;
|
96 |
|
|
end else begin
|
97 |
|
|
if (wr_addr[7:3]==`OC8051_SFR_B_ACC)
|
98 |
|
|
data_out[wr_addr[2:0]] <= #1 bit_in;
|
99 |
|
|
end
|
100 |
|
|
end
|
101 |
2 |
simont |
end
|
102 |
|
|
|
103 |
4 |
markom |
always @(posedge clk or posedge rst)
|
104 |
2 |
simont |
begin
|
105 |
4 |
markom |
if (rst) bit_out <= #1 1'b0;
|
106 |
22 |
simont |
else if ((rd_addr==wr_addr[2:0]) & wr & wr_bit) begin
|
107 |
|
|
bit_out <= #1 bit_in;
|
108 |
|
|
end else if ((wr_addr==`OC8051_SFR_ACC) & wr & !wr_bit) begin
|
109 |
|
|
bit_out <= #1 data_in[rd_addr];
|
110 |
|
|
end else bit_out <= #1 data_out[rd_addr];
|
111 |
2 |
simont |
end
|
112 |
|
|
|
113 |
|
|
endmodule
|
114 |
|
|
|