Exemple #1
0
def jalr(code, computer):
    regA = extract_binary(code, 19, 21)
    regB = extract_binary(code, 16, 18)

    next_instruction = computer.get_pc() + 1
    computer.set_register(regB, next_instruction)
    computer.set_pc(computer.get_register(regA))
def nand(code, computer):
    destReg = extract_binary(code, 0, 2)
    regA = extract_binary(code, 19, 21)
    regB = extract_binary(code, 16, 18)

    value = ~(computer.get_register(regA) & computer.get_register(regB))
    computer.set_register(destReg, value)
    computer.go_next_pc()
def add(code, computer):
    regA = extract_binary(code, 19, 21)
    regB = extract_binary(code, 16, 18)
    destReg = extract_binary(code, 0, 2)

    value = computer.get_register(regA) + computer.get_register(regB)
    computer.set_register(destReg, value)
    computer.go_next_pc()
def lw(code, computer):
    regA = extract_binary(code, 19, 21)
    regB = extract_binary(code, 16, 18)
    offsetField = extract_binary(code, 0, 15, unsiged=False)

    address = computer.get_register(regA) + offsetField
    mem_value = computer.get_memory(address)
    computer.set_register(regB, mem_value)
    computer.go_next_pc()
def beq(code, computer):
    regA = extract_binary(code, 19, 21)
    regB = extract_binary(code, 16, 18)
    offsetField = extract_binary(code, 0, 15, unsiged=False)

    regA_value = computer.get_register(regA)
    regB_value = computer.get_register(regB)

    if regA_value == regB_value:
        computer.set_pc(computer.get_pc() + 1 + offsetField)
    else:
        computer.go_next_pc()