Commit ce8f7f4e authored by Khoi Lam's avatar Khoi Lam 💬
Browse files

Lab 7, Finished

parent dc5beff3
......@@ -73,9 +73,9 @@ def run_cpu(imem, dmem, symbols, debug):
isTaken = False
if ( (instr.instr_name == "beq" or instr.instr_name == "beqz") and (rs1_value == rs2_value) ): isTaken = True
if (instr.instr_name == "bne" and (rs1_value != rs2_value) ): isTaken = True
if (instr.instr_name == "blt" and (rs1_value < rs2_value) ): isTaken = True
if (instr.instr_name == "bge" and (rs1_value >= rs2_value) ): isTaken = True
if (instr.instr_name == "bne" and (as_twos_comp(rs1_value) != as_twos_comp(rs2_value)) ): isTaken = True
if (instr.instr_name == "blt" and (as_twos_comp(rs1_value) < as_twos_comp(rs2_value)) ): isTaken = True
if (instr.instr_name == "bge" and (as_twos_comp(rs1_value) >= as_twos_comp(rs2_value)) ): isTaken = True
if (instr.instr_name == "bltu" and (as_twos_comp(rs1_value) < as_twos_comp(rs2_value)) ): isTaken = True
if (instr.instr_name == "bgeu" and (as_twos_comp(rs1_value) >= as_twos_comp(rs2_value)) ): isTaken = True
......@@ -146,8 +146,9 @@ def run_cpu(imem, dmem, symbols, debug):
if debug != 0:
print(' rd_val: ' + str(rd_value) + ' rs1_val: ' + format(rs1_value, "x") + ' rs2_val: ' + format(rs2_value, "x") )
if pc_val in symbols:
print ("-"*10 + symbols[pc_val] + "-"*10)
if debug != 0:
if pc_val in symbols:
print ("-"*10 + symbols[pc_val] + "-"*10)
if debug != 0:
print('rd: ' + str(rd_value) + ' rs1: ' + str(rs1_value) + ' rs2: ' + str(rs2_value))
......@@ -215,25 +216,29 @@ if __name__ == "__main__":
# imem = sys_mem
# dmem = Memory(sys_mem) #for lab 5
# if (run_cpu(imem, dmem, symbols, debug = 0)) == 0:
# print("TEST PASS")
# else:
# print("TEST FAIL")
directory = "riscv_isa/programs/riscv-test/"
for filename in os.listdir(directory):
print(filename)
program_file = directory + filename
if len(sys.argv) > 1:
program_file = sys.argv[1]
sys_mem, symbols = load_elf(program_file)
imem = sys_mem
dmem = Memory(sys_mem)
is_passed = run_cpu(imem, dmem, symbols, debug = 0);
if is_passed == 0:
test_result = "TEST PASS"
if (run_cpu(imem, dmem, symbols, debug = 0)) == 0:
print("TEST PASS")
else:
test_result = "TEST_FAIL"
print(directory + filename + ': ' + test_result)
print("TEST FAIL")
else:
directory = "riscv_isa/programs/riscv-test/"
for filename in os.listdir(directory):
program_file = directory + filename
sys_mem, symbols = load_elf(program_file)
imem = sys_mem
dmem = Memory(sys_mem)
is_passed = run_cpu(imem, dmem, symbols, debug = 0)
if is_passed == 0:
test_result = "TEST PASS"
else:
test_result = "TEST_FAIL"
print(directory + filename + ': ' + test_result)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment