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

finished alu, working on regfile

parent bb50682f
def alu(op1, op2, alu_fun):
if alu_fun == 0:
return 0
elif alu_fun == 1: #xor
return op1^op2
elif alu_fun == 2: #cp
return op1
elif alu_fun == 3: #sltu
return op1 << op2
elif alu_fun == 4: #and
return op1 & op2
elif alu_fun == 5: #add
return op1 + op2
elif alu_fun == 6: #set less than
if op1 < op2: return 1
return 0
elif alu_fun == 7: #shift right arithmetic
return op1 >> op2
elif alu_fun == 8: #sub
return op1 - op2
elif alu_fun == 9: #shift right logical
return op1 >> op2
elif alu_fun == 10: #shift left logical
return op1 << op2
elif alu_fun == 11: #Or
return op1 | op2
else:
return "Invalid alu_fun"
if __name__ == "__main__":
op1 = 2
op2 = 1
alu_funs = list(range(12))
op_dict = {0: "NOP", 1:"xor", 2:"cp", 3:"sltu", 4:"and", 5:"add", 6:"slt", 7:"sra", 8:"sub", 9:"srl", 10:"sll", 11:"or"}
for i in alu_funs:
ret_val = alu(op1, op2, alu_funs[i])
print(str(op1) + " " + op_dict[i] + " " + str(op2) + " = " + str(ret_val))
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