Тема: РАМ віртуальна машина
РАМ virtual machine. Програмування та оцінювання.
Написати програму для РАМ, яка читає n додатніх чисел, обмежених 0 і друкує їх у порядку неспадання.
Написати програму для РАМ, яка допускає всі входи виду 0.
Написати програму для РАМ, яка обчислює з часовою оцінкою О( ) при рівномірному ваговому критерії.
Написати програму для РАМ із використанням непрямої адресації, яка вводить масив.
Написати програму на РАСП, яка підраховує кількість від’ємних чисел на вході (подано n чисел)
Почав виконувати перше завдання та стикнувся з нехваткою досвіду чи що
Написав код
filename = "instructions.txt"
# Open the file in read mode
with open(filename, 'r') as file:
    # Read the content of the file and split it into lines
    lines = file.readlines()
# Initialize variables
n = None
count = 0
i = 1
tmp = 0
x = 0
numbers = []
# Loop through the lines of the file
while i <= len(lines):
    # Split the line into instruction and argument
    parts = lines[i - 1].split()
    inst = parts[0]
    arg = parts[1] if len(parts) > 1 else None
    # Execute the instruction
    if inst == "LOAD":
        if arg == "n":
            tmp = n
        elif arg == "count":
            tmp = count
        elif arg == "i":
            tmp = i
        elif arg == "tmp":
            tmp = tmp
        elif arg == "x":
            tmp = x
        elif arg is not None:
            tmp = int(arg)
    elif inst == "STORE":
        if arg == "count":
            count = tmp
        elif arg == "i":
            i = tmp
        elif arg == "tmp":
            tmp = tmp
    elif inst == "READ":
        if n is None:
            n = int(input("Enter the value of n: "))
        else:
            x = int(input("Enter a value for x: "))
            numbers.append(x)
            count += 1
            if count == n:
                numbers.sort()
                print(numbers)
                break
            else:
                tmp = x
    elif inst == "ADD":
        tmp += int(arg)
    elif inst == "SUB":
        tmp -= int(arg)
    elif inst == "JZERO":
        if tmp == 0:
            i += int(arg)
        else:
            i += 1
    elif inst == "JGTZ":
        if tmp > 0:
            i += int(arg)
        else:
            i += 1
    elif inst == "WRITE":
        print(tmp)
    elif inst == "HALT":
        break
    # Increment the instruction pointer
    i += 1У текстовий файл завантажив інструкції
# Read the value of n
LOAD n
READ
STORE n
# Loop through the input values and sort them
LOOP1:
    LOAD n
    SUB i
    JZERO END1
    STORE flag
    LOAD n
    ADD i
    LOAD j
    SUB i
    ADD i
    JZERO END2
    STORE tmp
    LOAD n
    ADD j
    STORE n
    LOAD tmp
    SUB j
    ADD j
    STORE n
    LOAD flag
    STORE tmp
    LOAD i
    ADD j
    STORE i
    LOAD tmp
    STORE j
    JUMP LOOP1
# Print the sorted values
LOOP2:
    LOAD n
    SUB i
    JZERO END3
    LOAD n
    WRITE
    LOAD i
    ADD 1
    STORE i
    JUMP LOOP2
# Halt the program
END1:
END2:
END3:
HALTПрошу допомогти та поправити код (можливо інструкції)