From 9fedc983101291d5992e6a23d67673ebaba60915 Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Tue, 27 Jun 2023 16:40:09 +0300 Subject: [PATCH] Implemented input_handler function. --- main.py | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index 6bd310f..27f58ec 100644 --- a/main.py +++ b/main.py @@ -1,31 +1,32 @@ import bitutilities as bu -import timeit + + +def input_handler(first_register: bu.BasicRegister, second_register: bu.BasicRegister): + first_register, second_register = bu.align_registers(first_register, second_register) + + print() + 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": + pass + case "d": + pass + case "q": + exit() + case _: + print("Not an available operation, try again.") if __name__ == '__main__': reg: bu.BasicRegister = bu.BasicRegister(bu.get_memory("memory")) - - print() - print("Register 1:") - print(reg) - - print() reg2: bu.BasicRegister = bu.BasicRegister(bu.get_memory("more memory")) - print() - print("Register 2:") - print(reg2) - - reg, reg2 = bu.align_registers(reg, reg2) - - print() - sum_reg, carry = bu.binary_sum(reg, reg2, True) - - print() - print("Sum & carry:") - print(sum_reg, carry) - - print() - subtr_reg: bu.BasicRegister = bu.binary_subtraction_1_complement(reg, reg2) - print("Subtraction:") - print(subtr_reg) + input_handler(reg, reg2)