Dear all,
I've been trying to set up a MIPS code run through a Python3 code. So, students write a MIPS code, and they should be able to check it, using the CHECK button. The CHECK button must run a python script, which launches a java process using the Mars jar file to run and give the output of their MIPS code.
I tried it using the following settings:
Question type: Python3, and I also tried my own prototype
Customisation: on
Template:
import subprocess
import sys
#__student_answer__ = """{{ STUDENT_ANSWER | e('py') }}"""
with open("test.asm", "w") as f:
f.write("""{{ STUDENT_ANSWER }}""")
command = ["java", "-jar", "Mars4_5.jar", "test.asm", "nc"]
try:
result = subprocess.run(command, capture_output=True, text=True, shell=True)
print("Standard Output:")
print(result.stdout)
# print(result.stdout.decode())
if result.stderr:
# print("ERROR:", result.stderr.decode(), file=sys.stderr)
print("ERROR:", result.stderr)
except Exception as e:
print("Runtime Error:", str(e), file=sys.stderr)
{% for TEST in TESTCASES %}
{{ TEST.testcode }}
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}
Grading: I tried "Exact match" and "Template grading"
Student answer: Ace; Template uses ace: on
The question is simple - create a hello world code in MIPS
Answer:
.data
msg: .asciiz "Hello, World!"
.text
main:
li $v0, 4
la $a0, msg
syscall
li $v0, 10
syscall