def sub1(ram, target_address): target_value = ram_fetch(ram, target_address) subtraction = target_value - 1 if subtraction < 0: new_ram = ram_store(ram, target_address, 0) return new_ram else: new_ram = ram_store(ram, target_address, subtraction) return new_ram
def sub(ram, target_address, source_address_1, source_address_2): source_value_1 = ram_fetch(ram, source_address_1) source_value_2 = ram_fetch(ram, source_address_2) subtraction = source_value_1 - source_value_2 if subtraction < 0: new_ram = ram_store(ram, target_address, 0) return new_ram else: new_ram = ram_store(ram, target_address, subtraction) return new_ram
def div(ram, target_address, source_address_1, source_address_2): source_value_1 = ram_fetch(ram, source_address_1) source_value_2 = ram_fetch(ram, source_address_2) if source_value_2 == 0: return "DIVISION BY 0" division = source_value_1 // source_value_2 new_ram = ram_store(ram, target_address, division) return new_ram
def if_zero_add1(ram, target_address, source_address): source_value = ram_fetch(ram, source_address) if source_value == 0: target_value = ram_fetch(ram, target_address) new_ram = ram_store(ram, target_address, target_value + 1) return new_ram else: return ram
def ram_load(ram, load_address, lst): if len(lst) == 0: return ram else: next_ram = ram_store(ram, load_address, lst[0]) next_load_address = load_address + 1 next_lst = lst.copy() next_lst.pop(0) return ram_load(next_ram, next_load_address, next_lst)
def if_greater_add1(ram, target_address, source_address_1, source_address_2): source_value_1 = ram_fetch(ram, source_address_1) source_value_2 = ram_fetch(ram, source_address_2) if source_value_1 > source_value_2: target_value = ram_fetch(ram, target_address) new_ram = ram_store(ram, target_address, target_value + 1) return new_ram else: return ram
def copy(ram, target_address, source_address): source_value = ram_fetch(ram, source_address) new_ram = ram_store(ram, target_address, source_value) return new_ram
def mult(ram, target_address, source_address_1, source_address_2): source_value_1 = ram_fetch(ram, source_address_1) source_value_2 = ram_fetch(ram, source_address_2) new_ram = ram_store(ram, target_address, source_value_1 * source_value_2) return new_ram
def add1(ram, target_address): target_value = ram_fetch(ram, target_address) new_ram = ram_store(ram, target_address, target_value + 1) return new_ram
def read(ram, target_address): user_input = int(input("> ")) new_ram = ram_store(ram, target_address, user_input) return new_ram
from ram import ram, ram_fetch, ram_store, core_dump my_ram = ram_store(ram_store(ram, 77, 1010), 2, 999) core_dump(my_ram) my_ram_replace_2 = ram_store(my_ram, 2, 111) core_dump(my_ram_replace_2)