Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
lab7
- Loading branch information
Jerry Shi
committed
Mar 17, 2024
1 parent
72817ee
commit aee68b7
Showing
6 changed files
with
1,186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from myhdl import block, always_comb | ||
|
||
@block | ||
def ALU1bit(a, b, carryin, binvert, operation, result, carryout): | ||
|
||
""" 1-bit ALU | ||
result and carrayout are output | ||
all other signals are input | ||
operation: | ||
0: AND | ||
1: OR | ||
2: ADD/SUB | ||
3: 0 | ||
""" | ||
# this implementation does not follow the requirements of the alu1 lab. | ||
|
||
@always_comb | ||
def alu1_logic(): | ||
if operation == 0: | ||
result.next = a and b | ||
elif operation == 1: | ||
result.next = a or b | ||
elif operation == 2: | ||
if binvert: | ||
res_add = a + carryin + (not b) | ||
else: | ||
res_add = a + carryin + b | ||
result.next = res_add & 1 | ||
carryout.next = bool(res_add & 2) | ||
else: | ||
result.next = 0 | ||
|
||
# return the logic | ||
return alu1_logic |
Oops, something went wrong.