// File: saeefahmad[P]MIPS-pipeline-simulator/execute.cpp
// Function: ExecuteStage::process()
void ExecuteStage::process() {
	Instruction instr;
	instr = this->ins;
	if(!instr.isNop() && !this->isStalled()){
		switch (instr.getType()){
		case 1: // ADD
			instr.setAluOut((instr.getA() + instr.getB()));
			break;
		case 2: // SUB
			instr.setAluOut((instr.getA() - instr.getB()));
			break;
		case 3: // MUL
			instr.setAluOut((instr.getA() * instr.getB()));
			break;
		case 4: // DIV
			if(instr.getB() != 0)
				instr.setAluOut((instr.getA() / instr.getB()));
			break;
		case 5: // XOR
			instr.setAluOut((instr.getA() ^ instr.getB()));
			break;
		case 6: // AND
			instr.setAluOut((instr.getA() & instr.getB()));
			break;
		case 7: // OR
			instr.setAluOut((instr.getA() | instr.getB()));
			break;
		case 8: // ADDI
			instr.setAluOut((instr.getA() + instr.getImmidiate()));
			break;
		case 9: // SUBI
			instr.setAluOut((instr.getA() - instr.getImmidiate()));
			break;
		case 10: // LD
			instr.setAluOut((instr.getA() + instr.getImmidiate()));
			break;
		case 11: // ST
			instr.setAluOut((instr.getA() + instr.getImmidiate()));
			break;
		case 12: // BEQZ
			instr.setAluOut((this->getPc() + (instr.getImmidiate()<<2)));
			instr.setCond(instr.getA() == 0);
			break;
		case 13: // BNEQZ
			instr.setAluOut((this->getPc() + (instr.getImmidiate()<<2)));
			instr.setCond(instr.getA() != 0);
			break;
		default:
			break;
		}
	}
	this->nextStage->setInstruction(instr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x64(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x8480
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdi
addq $0x8, %rsi
callq 0x86a0
jmp 0x76fd
leaq -0x64(%rbp), %rdi
callq 0x7510
movb %al, -0x89(%rbp)
jmp 0x770e
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x7b62
jmp 0x771e
movq -0x88(%rbp), %rdi
callq 0x74f0
movb %al, -0x8a(%rbp)
jmp 0x7732
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0x7b62
jmp 0x7742
leaq -0x64(%rbp), %rdi
callq 0x7bf0
movl %eax, -0x90(%rbp)
jmp 0x7753
movl -0x90(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x98(%rbp)
subl $0xc, %eax
ja 0x7b5e
movq -0x98(%rbp), %rax
leaq 0x1ae9(%rip), %rcx      # 0x9264
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x87e0
jmp 0x7b8a
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0x9c(%rbp)
jmp 0x77af
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xa0(%rbp)
jmp 0x77c0
movl -0xa0(%rbp), %eax
movl -0x9c(%rbp), %esi
addl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x77d9
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xa4(%rbp)
jmp 0x77ef
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xa8(%rbp)
jmp 0x7800
movl -0xa8(%rbp), %eax
movl -0xa4(%rbp), %esi
subl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x7819
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xac(%rbp)
jmp 0x782f
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xb0(%rbp)
jmp 0x7840
movl -0xb0(%rbp), %eax
movl -0xac(%rbp), %esi
imull %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x785a
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xb4(%rbp)
jmp 0x7870
movl -0xb4(%rbp), %eax
cmpl $0x0, %eax
je 0x78bb
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xb8(%rbp)
jmp 0x788c
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xbc(%rbp)
jmp 0x789d
movl -0xbc(%rbp), %ecx
movl -0xb8(%rbp), %eax
cltd
idivl %ecx
movl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x78b9
jmp 0x78bb
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xc0(%rbp)
jmp 0x78d1
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xc4(%rbp)
jmp 0x78e2
movl -0xc4(%rbp), %eax
movl -0xc0(%rbp), %esi
xorl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x78fb
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xc8(%rbp)
jmp 0x7911
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xcc(%rbp)
jmp 0x7922
movl -0xcc(%rbp), %eax
movl -0xc8(%rbp), %esi
andl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x793b
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xd0(%rbp)
jmp 0x7951
leaq -0x64(%rbp), %rdi
callq 0x7c40
movl %eax, -0xd4(%rbp)
jmp 0x7962
movl -0xd4(%rbp), %eax
movl -0xd0(%rbp), %esi
orl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x797b
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xd8(%rbp)
jmp 0x7991
leaq -0x64(%rbp), %rdi
callq 0x7c60
movl %eax, -0xdc(%rbp)
jmp 0x79a2
movl -0xdc(%rbp), %eax
movl -0xd8(%rbp), %esi
addl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x79bb
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xe0(%rbp)
jmp 0x79d1
leaq -0x64(%rbp), %rdi
callq 0x7c60
movl %eax, -0xe4(%rbp)
jmp 0x79e2
movl -0xe4(%rbp), %eax
movl -0xe0(%rbp), %esi
subl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x79fb
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xe8(%rbp)
jmp 0x7a11
leaq -0x64(%rbp), %rdi
callq 0x7c60
movl %eax, -0xec(%rbp)
jmp 0x7a22
movl -0xec(%rbp), %eax
movl -0xe8(%rbp), %esi
addl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x7a3b
jmp 0x7b60
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0xf0(%rbp)
jmp 0x7a51
leaq -0x64(%rbp), %rdi
callq 0x7c60
movl %eax, -0xf4(%rbp)
jmp 0x7a62
movl -0xf4(%rbp), %eax
movl -0xf0(%rbp), %esi
addl %eax, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x7a7b
jmp 0x7b60
leaq 0x5cb1(%rip), %rax      # 0xd738
movq (%rax), %rax
callq *%rax
movl %eax, -0xf8(%rbp)
jmp 0x7a94
leaq -0x64(%rbp), %rdi
callq 0x7c60
movl %eax, -0xfc(%rbp)
jmp 0x7aa5
movl -0xf8(%rbp), %edx
movl -0xfc(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,4), %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x7ac3
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0x100(%rbp)
jmp 0x7ad4
movl -0x100(%rbp), %eax
testl %eax, %eax
sete %al
movzbl %al, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c80
jmp 0x7aed
jmp 0x7b60
leaq 0x5c42(%rip), %rax      # 0xd738
movq (%rax), %rax
callq *%rax
movl %eax, -0x104(%rbp)
jmp 0x7b03
leaq -0x64(%rbp), %rdi
callq 0x7c60
movl %eax, -0x108(%rbp)
jmp 0x7b14
movl -0x104(%rbp), %edx
movl -0x108(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,4), %esi
leaq -0x64(%rbp), %rdi
callq 0x7c00
jmp 0x7b32
leaq -0x64(%rbp), %rdi
callq 0x7c20
movl %eax, -0x10c(%rbp)
jmp 0x7b43
movl -0x10c(%rbp), %eax
testl %eax, %eax
setne %al
movzbl %al, %esi
leaq -0x64(%rbp), %rdi
callq 0x7c80
jmp 0x7b5c
jmp 0x7b60
jmp 0x7b60
jmp 0x7b62
movq -0x88(%rbp), %rax
movq 0x78(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x6d40
jmp 0x7b78
leaq -0x64(%rbp), %rdi
callq 0x87e0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x2200
nopw %cs:(%rax,%rax)