2023-06-27 14:18:37 +03:00
|
|
|
import bitutilities as bu
|
2023-06-26 00:24:47 +03:00
|
|
|
|
|
|
|
|
2023-06-27 16:40:09 +03:00
|
|
|
def input_handler(first_register: bu.BasicRegister, second_register: bu.BasicRegister):
|
|
|
|
first_register, second_register = bu.align_registers(first_register, second_register)
|
2023-06-26 00:24:47 +03:00
|
|
|
|
2023-06-27 14:18:37 +03:00
|
|
|
print()
|
2023-06-27 16:40:09 +03:00
|
|
|
print(first_register)
|
|
|
|
print(second_register)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
print()
|
|
|
|
match input("Choose the operation:\n[a]ddition, [s]ubtraction, [m]ultiplication, [d]ivision, [q]uit\n>>> "):
|
|
|
|
case "a":
|
|
|
|
print(f"Sum:\n{bu.binary_sum(first_register, second_register)}")
|
|
|
|
case "s":
|
|
|
|
print(f"Subtraction:\n{bu.binary_subtraction(first_register, second_register)}")
|
|
|
|
case "m":
|
2023-06-27 22:00:15 +03:00
|
|
|
match input("Choose method to use (1-4):\n>>> "):
|
|
|
|
case "1":
|
2023-06-28 12:36:02 +03:00
|
|
|
result, data_table = bu.binary_multiplication_method_1(first_register, second_register)
|
2023-06-28 12:59:25 +03:00
|
|
|
print(f"Multiplication:\n{bu.format_device_state_table(data_table)}\nResult: {result}")
|
2023-06-27 22:00:15 +03:00
|
|
|
case "2":
|
2023-06-28 12:36:02 +03:00
|
|
|
result, data_table = bu.binary_multiplication_method_2(first_register, second_register)
|
2023-06-28 12:59:25 +03:00
|
|
|
print(f"Multiplication:\n{bu.format_device_state_table(data_table)}\nResult: {result}")
|
2023-06-27 22:00:15 +03:00
|
|
|
case "3":
|
2023-06-28 12:36:02 +03:00
|
|
|
result, data_table = bu.binary_multiplication_method_3(first_register, second_register)
|
2023-06-28 12:59:25 +03:00
|
|
|
print(f"Multiplication:\n{bu.format_device_state_table(data_table)}\nResult: {result}")
|
2023-06-27 22:00:15 +03:00
|
|
|
case "4":
|
2023-06-28 12:36:02 +03:00
|
|
|
result, data_table = bu.binary_multiplication_method_4(first_register, second_register)
|
2023-06-28 12:59:25 +03:00
|
|
|
print(f"Multiplication:\n{bu.format_device_state_table(data_table)}\nResult: {result}")
|
2023-06-27 22:00:15 +03:00
|
|
|
case _:
|
|
|
|
print("Such method does not exist, try again.")
|
2023-06-27 16:40:09 +03:00
|
|
|
case "d":
|
2023-07-29 18:42:06 +03:00
|
|
|
match input("Choose method to use (1-2):\n>>> "):
|
|
|
|
case "1":
|
|
|
|
result, data_table = bu.binary_division_method_1(first_register, second_register)
|
|
|
|
print(f"Division:\n{bu.format_device_state_table(data_table)}\nResult: {result}")
|
|
|
|
case "2":
|
|
|
|
result, data_table = bu.binary_division_method_2(first_register, second_register)
|
|
|
|
print(f"Division:\n{bu.format_device_state_table(data_table)}\nResult: {result}")
|
2023-06-27 16:40:09 +03:00
|
|
|
case "q":
|
|
|
|
exit()
|
|
|
|
case _:
|
|
|
|
print("Not an available operation, try again.")
|
2023-06-26 00:24:47 +03:00
|
|
|
|
2023-06-26 21:05:45 +03:00
|
|
|
|
2023-06-27 16:40:09 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
reg: bu.BasicRegister = bu.BasicRegister(bu.get_memory("memory"))
|
|
|
|
reg2: bu.BasicRegister = bu.BasicRegister(bu.get_memory("more memory"))
|
2023-06-27 15:53:20 +03:00
|
|
|
|
2023-06-27 16:40:09 +03:00
|
|
|
input_handler(reg, reg2)
|