Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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)
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
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
Exemple #10
0
def read(ram, target_address):
    user_input = int(input("> "))
    new_ram = ram_store(ram, target_address, user_input)
    return new_ram
Exemple #11
0
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)