-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleALU.scala
More file actions
58 lines (50 loc) · 1.57 KB
/
SimpleALU.scala
File metadata and controls
58 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// import chisel3._
// class SimpleALU extends Module {
// val io = IO(new Bundle {
// val operandA = Input(UInt(4.W))
// val operandB = Input(UInt(4.W))
// val operation = Input(UInt(4.W))
// val result = Output(UInt(4.W))
// })
// // ALU operations
// val addResult = io.operandA + io.operandB
// val subResult = io.operandA - io.operandB
// val andResult = io.operandA & io.operandB
// val orResult = io.operandA | io.operandB
// val xorResult = io.operandA ^ io.operandB
// // Output selection based on the operation input
// io.result := MuxLookup(io.operation, 0.U,
// Array(
// 0.U -> addResult,
// 1.U -> subResult,
// 2.U -> andResult,
// 3.U -> orResult,
// 4.U -> xorResult
// )
// )
// }
// object SimpleALU extends App {
// chisel3.Driver.execute(args, () => new SimpleALU)
// }
import chisel3._
class SimpleALU extends Module {
val io = IO(new Bundle {
val operandA = Input(UInt(4.W))
val operandB = Input(UInt(4.W))
val operation = Input(UInt(3.W))
val result = Output(UInt(4.W))
})
io.result := 0.U
switch(io.operation) {
is(0.U) { io.result := io.operandA + io.operandB }
is(1.U) { io.result := io.operandA - io.operandB }
is(2.U) { io.result := io.operandA & io.operandB }
is(3.U) { io.result := io.operandA | io.operandB }
is(4.U) { io.result := io.operandA ^ io.operandB }
is(5.U) { io.result := io.operandA << 1 }
is(6.U) { io.result := io.operandA >> 1 }
}
}
object SimpleALU extends App {
chisel3.Driver.execute(args, () => new SimpleALU)
}