Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F10707505
alu8.v
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Size
1 KB
Referenced Files
None
Subscribers
None
alu8.v
View Options
module
alu8
(
input
clk
,
input
rst
,
input
[
7
:
0
]
a
,
input
[
7
:
0
]
b
,
input
[
2
:
0
]
opcode
,
// 000: add, 001: sub, 010: and, 011: or, 100: xor
output
reg
[
7
:
0
]
result
);
reg
[
7
:
0
]
stage1_a
,
stage1_b
;
reg
[
2
:
0
]
stage1_opcode
;
reg
[
7
:
0
]
stage2_result
;
// Stage 1: Register Inputs
always
@(
posedge
clk
)
begin
if
(
rst
)
begin
stage1_a
<=
0
;
stage1_b
<=
0
;
stage1_opcode
<=
0
;
end
else
begin
stage1_a
<=
a
;
stage1_b
<=
b
;
stage1_opcode
<=
opcode
;
end
end
// Stage 2: ALU Operations
always
@(
posedge
clk
)
begin
if
(
rst
)
begin
stage2_result
<=
0
;
end
else
begin
case
(
stage1_opcode
)
3
'b000
:
stage2_result
<=
stage1_a
+
stage1_b
;
// Add
3
'b001
:
stage2_result
<=
stage1_a
-
stage1_b
;
// Subtract
3
'b010
:
stage2_result
<=
stage1_a
&
stage1_b
;
// AND
3
'b011
:
stage2_result
<=
stage1_a
|
stage1_b
;
// OR
3
'b100
:
stage2_result
<=
stage1_a
^
stage1_b
;
// XOR
default
:
stage2_result
<=
0
;
endcase
end
end
// Stage 3: Output
always
@(
posedge
clk
)
begin
if
(
rst
)
begin
result
<=
0
;
end
else
begin
result
<=
stage2_result
;
end
end
endmodule
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 31, 4:53 PM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
328967
Default Alt Text
alu8.v (1 KB)
Attached To
Mode
R231 SoC_I-Edge_yosys_nem_optimization
Attached
Detach File
Event Timeline
Log In to Comment