summaryrefslogtreecommitdiff
path: root/booth_multiplier.py
diff options
context:
space:
mode:
Diffstat (limited to 'booth_multiplier.py')
-rwxr-xr-xbooth_multiplier.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/booth_multiplier.py b/booth_multiplier.py
index afd6710..dc32263 100755
--- a/booth_multiplier.py
+++ b/booth_multiplier.py
@@ -91,8 +91,12 @@ def booth_mod(multiplier, multiplicand, length):
return (result, operations)
if __name__ == "__main__":
- headers = ['multiplicand', 'multiplier', 'result (bin)', 'result (hex)']
- table = []
+ result_headers = ['multiplicand', 'multiplier', 'result (bin)', 'result (hex)']
+ result_table = []
+
+ opcount_headers = ['multiplicand', 'multiplier', 'length', 'booth', 'modified booth']
+ opcount_table = []
+
lengths = [] # for matplotlib plot
ops_booth = []
ops_mod_booth = []
@@ -106,7 +110,7 @@ if __name__ == "__main__":
multiplicand = int(operation.split(" ")[0], 2)
multiplier = int(operation.split(" ")[1], 2)
-
+ # get result and operation count of both algorithims
result_booth = booth(multiplier, multiplicand, length)
result_mod_booth = booth_mod(multiplier, multiplicand, length)
@@ -115,11 +119,19 @@ if __name__ == "__main__":
ops_mod_booth.append(result_mod_booth[1])
lengths.append(length)
- table.append([bin(multiplicand), bin(multiplier), bin(result_booth[0]), hex(result_booth[0])])
+ #gather data for report results table
+ result_table.append([bin(multiplicand), bin(multiplier), bin(result_booth[0]), hex(result_booth[0])])
+
+ #gather data for test function to check if simulator is working
debug_results.append([multiplicand, multiplier, result_booth[0], result_mod_booth[0], length])
+ #gather data for operation count table
+ opcount_table.append([bin(multiplicand), bin(multiplier), length, result_booth[1], result_mod_booth[1]])
+
debug(debug_results)
- print(tabulate(table, headers))
+ print(tabulate(result_table, result_headers))
+ print(tabulate(opcount_table, opcount_headers))
+
# generate graph
plt.plot(lengths, ops_booth, '^--m', label='booths algorithim')