diff --git a/assignment-1/supporting_files/__pycache__/evaluate.cpython-310.pyc b/assignment-1/supporting_files/__pycache__/evaluate.cpython-310.pyc new file mode 100644 index 0000000..9b48afc Binary files /dev/null and b/assignment-1/supporting_files/__pycache__/evaluate.cpython-310.pyc differ diff --git a/assignment-1/supporting_files/emulator.jar b/assignment-1/supporting_files/emulator.jar new file mode 100755 index 0000000..80440aa Binary files /dev/null and b/assignment-1/supporting_files/emulator.jar differ diff --git a/assignment-1/supporting_files/evaluate.py b/assignment-1/supporting_files/evaluate.py new file mode 100755 index 0000000..ff4179b --- /dev/null +++ b/assignment-1/supporting_files/evaluate.py @@ -0,0 +1,113 @@ +#!/bin/python + +import os +import shutil +import sys +import subprocess +from threading import Timer + +def evaluate(submitted_program): + + jarfile = "./emulator.jar" + testcases_directory = "./test_cases/" + + l = len(submitted_program.split("/")) + program_name = submitted_program.split("/")[l-1].split("_")[0].split(".")[0] + total_marks = 0 + scored_marks = 0 + for cur_file in os.listdir(testcases_directory): + if program_name in cur_file and ".input" in cur_file: + total_marks = total_marks + 1 +#find starting and ending address + expected_file = open(testcases_directory + cur_file.split(".")[0] + ".expected") + starting_address = "x" + ending_address = "x" + memory_required = False + for line in expected_file: + if memory_required == True: + if len(line.split(":")) > 1: + if starting_address == "x": + starting_address = line.split(":")[0].split()[0] + else: + ending_address = line.split(":")[0].split()[0] + if "Main Memory Contents" in line: + memory_required = True + expected_file.close() + + if starting_address == "x": + starting_address = "0" + ending_address = "0" + if ending_address == "x": + ending_address = starting_address +#create new assembly file based on test case + new_assembly_file = open("./tmp.asm", 'w') + input_file = open(testcases_directory + cur_file) + for line in input_file: + new_assembly_file.write(line) + input_file.close() + + text_encountered = False + submitted_file = open(submitted_program) + for line in submitted_file: + if ".text" in line: + text_encountered = True + if text_encountered == True: + new_assembly_file.write(line) + submitted_file.close() + new_assembly_file.close() +# spawn emulator + stdout_file = open("./tmp.output", 'w') + popen_args = ["java", "-Xmx1g", "-jar", jarfile, "./tmp.asm", starting_address, ending_address] + proc = subprocess.Popen(popen_args, stdout = stdout_file, stderr = stdout_file) + timer = Timer(5, proc.kill) + try: + timer.start() + stdout, stderr = proc.communicate() + finally: + timer.cancel() + stdout_file.close() +# evaluate against expected output + expected_file = open(testcases_directory + cur_file.split(".")[0] + ".expected") + result_file = open("./tmp.output") + expected_line = expected_file.readline() + first_line_found = False + evaluation = True + for line in result_file: + if first_line_found == True and line != expected_line: + evaluation = False + break + if expected_line == line: + first_line_found = True + expected_line = expected_file.readline() + if expected_line == None or expected_line == "": + break + if first_line_found == False: + evaluation = False + + expected_file.close() + result_file.close() + + if evaluation == True: + scored_marks = scored_marks + 1 + print(cur_file + "\t: PASS!") + else: + print(cur_file + "\t: Fail") +#debug print + debug = False + if debug == True: + print("testcase = " + cur_file) + print("\n output expected to contain = ") + expected_file = open(testcases_directory + cur_file.split(".")[0] + ".expected") + for line in expected_file: + print(line) + expected_file.close() + print("\n obtained output = ") + output_file = open("./tmp.output") + for line in output_file: + print(line) + output_file.close() + + os.remove("./tmp.asm") + os.remove("./tmp.output") + + return [total_marks, scored_marks] diff --git a/assignment-1/supporting_files/program_templates/descending_template.asm b/assignment-1/supporting_files/program_templates/descending_template.asm new file mode 100755 index 0000000..b101748 --- /dev/null +++ b/assignment-1/supporting_files/program_templates/descending_template.asm @@ -0,0 +1,16 @@ + .data +a: + 70 + 80 + 40 + 20 + 10 + 30 + 50 + 60 +n: + 8 + .text +// your code here +// you may change the numbers in the array, and the size of the array; but allow the name of the array to remain as 'a', and size as 'n' +// remove these comments! diff --git a/assignment-1/supporting_files/program_templates/even-odd_template.asm b/assignment-1/supporting_files/program_templates/even-odd_template.asm new file mode 100755 index 0000000..d08577b --- /dev/null +++ b/assignment-1/supporting_files/program_templates/even-odd_template.asm @@ -0,0 +1,8 @@ + .data +a: + 10 + .text +// your code here to check if the number 'a' is even or odd. If yes, write 1 to x10. Else write -1. +// you may change the value of 'a' +// remove these comments! + diff --git a/assignment-1/supporting_files/program_templates/fibonancci_template.asm b/assignment-1/supporting_files/program_templates/fibonancci_template.asm new file mode 100755 index 0000000..a999cbd --- /dev/null +++ b/assignment-1/supporting_files/program_templates/fibonancci_template.asm @@ -0,0 +1,7 @@ + .data +n: + 10 + .text +// your code here to get the first 'n' Fibonacci numbers +// you may change the value of 'n' +// remove these comments! diff --git a/assignment-1/supporting_files/program_templates/palindrome_template.asm b/assignment-1/supporting_files/program_templates/palindrome_template.asm new file mode 100755 index 0000000..2979620 --- /dev/null +++ b/assignment-1/supporting_files/program_templates/palindrome_template.asm @@ -0,0 +1,7 @@ + .data +a: + 10 + .text +// your code here to check if 'a' is a palindrome +// you may change the value of 'a' +// remove these comments! diff --git a/assignment-1/supporting_files/program_templates/prime_template.asm b/assignment-1/supporting_files/program_templates/prime_template.asm new file mode 100755 index 0000000..395f0f8 --- /dev/null +++ b/assignment-1/supporting_files/program_templates/prime_template.asm @@ -0,0 +1,8 @@ + .data +a: + 10 + .text +// your code here to check if the number 'a' is prime. If yes, write 1 to x10. Else write -1. +// you may change the value of 'a' +// remove these comments! + diff --git a/assignment-1/supporting_files/test_cases/descending_1.expected b/assignment-1/supporting_files/test_cases/descending_1.expected new file mode 100755 index 0000000..7a6878a --- /dev/null +++ b/assignment-1/supporting_files/test_cases/descending_1.expected @@ -0,0 +1,10 @@ +Main Memory Contents: + +0 : 80 +1 : 70 +2 : 60 +3 : 50 +4 : 40 +5 : 30 +6 : 20 +7 : 10 diff --git a/assignment-1/supporting_files/test_cases/descending_1.input b/assignment-1/supporting_files/test_cases/descending_1.input new file mode 100755 index 0000000..c41a03f --- /dev/null +++ b/assignment-1/supporting_files/test_cases/descending_1.input @@ -0,0 +1,12 @@ + .data +a: + 70 + 80 + 40 + 20 + 10 + 30 + 50 + 60 +n: + 8 diff --git a/assignment-1/supporting_files/test_cases/even-odd_1.expected b/assignment-1/supporting_files/test_cases/even-odd_1.expected new file mode 100755 index 0000000..2e7e5d3 --- /dev/null +++ b/assignment-1/supporting_files/test_cases/even-odd_1.expected @@ -0,0 +1 @@ +x10 : -1 diff --git a/assignment-1/supporting_files/test_cases/even-odd_1.input b/assignment-1/supporting_files/test_cases/even-odd_1.input new file mode 100755 index 0000000..2a7d973 --- /dev/null +++ b/assignment-1/supporting_files/test_cases/even-odd_1.input @@ -0,0 +1,3 @@ + .data +a: + 10 diff --git a/assignment-1/supporting_files/test_cases/fibonacci_1.expected b/assignment-1/supporting_files/test_cases/fibonacci_1.expected new file mode 100755 index 0000000..9accc8e --- /dev/null +++ b/assignment-1/supporting_files/test_cases/fibonacci_1.expected @@ -0,0 +1,12 @@ +Main Memory Contents: + +65526 : 34 +65527 : 21 +65528 : 13 +65529 : 8 +65530 : 5 +65531 : 3 +65532 : 2 +65533 : 1 +65534 : 1 +65535 : 0 diff --git a/assignment-1/supporting_files/test_cases/fibonacci_1.input b/assignment-1/supporting_files/test_cases/fibonacci_1.input new file mode 100755 index 0000000..cad0e0d --- /dev/null +++ b/assignment-1/supporting_files/test_cases/fibonacci_1.input @@ -0,0 +1,3 @@ + .data +n: + 10 diff --git a/assignment-1/supporting_files/test_cases/palindrome_1.expected b/assignment-1/supporting_files/test_cases/palindrome_1.expected new file mode 100755 index 0000000..d5d7827 --- /dev/null +++ b/assignment-1/supporting_files/test_cases/palindrome_1.expected @@ -0,0 +1 @@ +x10 : 1 diff --git a/assignment-1/supporting_files/test_cases/palindrome_1.input b/assignment-1/supporting_files/test_cases/palindrome_1.input new file mode 100755 index 0000000..fcbb54a --- /dev/null +++ b/assignment-1/supporting_files/test_cases/palindrome_1.input @@ -0,0 +1,3 @@ + .data +a: + 12321 diff --git a/assignment-1/supporting_files/test_cases/prime_1.expected b/assignment-1/supporting_files/test_cases/prime_1.expected new file mode 100755 index 0000000..2e7e5d3 --- /dev/null +++ b/assignment-1/supporting_files/test_cases/prime_1.expected @@ -0,0 +1 @@ +x10 : -1 diff --git a/assignment-1/supporting_files/test_cases/prime_1.input b/assignment-1/supporting_files/test_cases/prime_1.input new file mode 100755 index 0000000..2a7d973 --- /dev/null +++ b/assignment-1/supporting_files/test_cases/prime_1.input @@ -0,0 +1,3 @@ + .data +a: + 10 diff --git a/assignment-1/supporting_files/test_each.py b/assignment-1/supporting_files/test_each.py new file mode 100755 index 0000000..c1c6835 --- /dev/null +++ b/assignment-1/supporting_files/test_each.py @@ -0,0 +1,6 @@ +#!/bin/python + +import sys +from evaluate import evaluate + +evaluate(sys.argv[1]) diff --git a/assignment-1/supporting_files/test_zip.py b/assignment-1/supporting_files/test_zip.py new file mode 100755 index 0000000..dc0f7f6 --- /dev/null +++ b/assignment-1/supporting_files/test_zip.py @@ -0,0 +1,35 @@ +#!/bin/python + +import sys +import os +import zipfile +from evaluate import evaluate +import shutil + +zip_file = sys.argv[1] + +l = len(zip_file.split("/")) +print("Students :\t" + zip_file.split("/")[l-1].split("_")[0] + " and " + zip_file.split("_")[1].split(".")[0]) +print("") + +submissions_temp_dir = "./submissions/" + +if not os.path.exists(submissions_temp_dir): + os.mkdir(submissions_temp_dir) + +zip_ref = zipfile.ZipFile(zip_file, 'r') +zip_ref.extractall(submissions_temp_dir) +zip_ref.close() + +total_marks = 0 +scored_marks = 0 +for asm_file in os.listdir(submissions_temp_dir): + if ".asm in file": + [t,s] = evaluate(submissions_temp_dir + asm_file) + print(asm_file + ";\tscore = " + str(s) + " out of " + str(t)) + total_marks = total_marks + t + scored_marks = scored_marks + s + +shutil.rmtree(submissions_temp_dir) + +print("total score = " + str(scored_marks) + " out of " + str(total_marks))