// File: QFSW[P]MIPS1-Simulator/src/Simulator.cpp
// Function: Clarkitechture::MIPS::Simulator::executeNext()
void Simulator::executeNext()
{
    reg.PC += 4;
    size_t index = currInstrIndex();
    std::shared_ptr<Instruction> currentInstr;
    
    if (index < instrCount)
    {
        currentInstr = instrs[index];
        currentInstr->execute(mem, reg);
    }
    else { currentInstr = nullptr; }
    if (previousInstr) { previousInstr->delayedExecute(mem, reg); }
    
    if (!currentInstr && !previousInstr)
    {
        throw BadProgramCounter(reg.PC - 4, "PC was outside of the instruction memory space.");
    }
    
    previousInstr = currentInstr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movl 0x30(%rdi), %eax
addl $0x4, %eax
movl %eax, 0x30(%rdi)
callq 0x114c0
movq %rax, -0x10(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x118c0
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
cmpq (%rcx), %rax
jae 0x1133b
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
callq 0x11850
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x118e0
movq -0x78(%rbp), %rdi
callq 0x11910
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdx, %rsi
addq $0xc0, %rsi
addq $0x30, %rdx
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
jmp 0x11328
jmp 0x1135e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x114ae
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x11930
leaq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x11870
leaq -0x40(%rbp), %rdi
callq 0x118a0
movq -0x70(%rbp), %rdi
addq $0x20, %rdi
callq 0x11950
testb $0x1, %al
jne 0x11371
jmp 0x113a0
movq -0x70(%rbp), %rdi
addq $0x20, %rdi
callq 0x11910
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdx, %rsi
addq $0xc0, %rsi
addq $0x30, %rdx
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x1139e
jmp 0x113a0
leaq -0x20(%rbp), %rdi
callq 0x11950
testb $0x1, %al
jne 0x1148b
movq -0x70(%rbp), %rdi
addq $0x20, %rdi
callq 0x11950
testb $0x1, %al
jne 0x1148b
movb $0x1, -0x62(%rbp)
movl $0x50, %edi
callq 0x6140
movq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, -0x90(%rbp)
movl 0x30(%rax), %eax
addl $-0x4, %eax
movl %eax, -0x84(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x64c0
movq -0x80(%rbp), %rdx
leaq 0x3b40(%rip), %rsi      # 0x14f46
leaq -0x60(%rbp), %rdi
callq 0x8b50
jmp 0x11411
movl -0x84(%rbp), %esi
movq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x6fd0
jmp 0x11429
movq -0x90(%rbp), %rdi
movb $0x0, -0x62(%rbp)
leaq 0xaae5(%rip), %rsi      # 0x1bf20
leaq -0x9ab2(%rip), %rdx     # 0x7990
callq 0x6470
jmp 0x114c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x1146c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x6190
leaq -0x61(%rbp), %rdi
callq 0x62e0
testb $0x1, -0x62(%rbp)
jne 0x1147d
jmp 0x11489
movq -0x90(%rbp), %rdi
callq 0x61f0
jmp 0x114ae
movq -0x70(%rbp), %rdi
addq $0x20, %rdi
leaq -0x20(%rbp), %rsi
callq 0x118e0
leaq -0x20(%rbp), %rdi
callq 0x118a0
addq $0x90, %rsp
popq %rbp
retq
leaq -0x20(%rbp), %rdi
callq 0x118a0
movq -0x28(%rbp), %rdi
callq 0x64b0