// File: saeefahmad[P]MIPS-pipeline-simulator/writeback.cpp
// Function: WritebackStage::process()
void WritebackStage::process() {
	Instruction instr;
	instr = this->ins;
	if(!instr.isNop() && !this->isStalled()){
		if(instr.isAluReg()){
			this->setReg(instr.getArg1(), instr.getAluOut());
			this->incStatistics((StatisticsType) 2);
		} else if(instr.isAluImm()){
			this->setReg(instr.getArg1(), instr.getAluOut());
			this->incStatistics((StatisticsType) 2);
		} else if(instr.isLoad()){
			this->setReg(instr.getArg1(), instr.getLoadMemData());
			this->incStatistics((StatisticsType) 2);
		} else if(instr.isHlt()){
			this->incStatistics((StatisticsType) 2);
			this->stopSimulation();
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
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 0x813d
leaq -0x64(%rbp), %rdi
callq 0x7510
movb %al, -0x89(%rbp)
jmp 0x814e
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x835e
jmp 0x815e
movq -0x88(%rbp), %rdi
callq 0x74f0
movb %al, -0x8a(%rbp)
jmp 0x8172
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0x835e
jmp 0x8182
leaq -0x64(%rbp), %rdi
callq 0x65e0
movb %al, -0x8b(%rbp)
jmp 0x8193
movb -0x8b(%rbp), %al
testb $0x1, %al
jne 0x819f
jmp 0x821b
leaq 0x55d2(%rip), %rax      # 0xd778
movq (%rax), %rax
movq %rax, -0x98(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x6660
movl %eax, -0x90(%rbp)
jmp 0x81c1
leaq -0x64(%rbp), %rdi
callq 0x8020
movl %eax, -0x9c(%rbp)
jmp 0x81d2
movq -0x98(%rbp), %rax
movl -0x9c(%rbp), %esi
movl -0x90(%rbp), %edi
callq *%rax
jmp 0x81e9
leaq 0x55b0(%rip), %rax      # 0xd7a0
movq (%rax), %rax
movl $0x2, %edi
callq *%rax
jmp 0x81fc
jmp 0x835c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x87e0
jmp 0x8370
leaq -0x64(%rbp), %rdi
callq 0x6680
movb %al, -0x9d(%rbp)
jmp 0x822c
movb -0x9d(%rbp), %al
testb $0x1, %al
jne 0x8238
jmp 0x829a
leaq 0x5539(%rip), %rax      # 0xd778
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x6660
movl %eax, -0xa4(%rbp)
jmp 0x825a
leaq -0x64(%rbp), %rdi
callq 0x8020
movl %eax, -0xb4(%rbp)
jmp 0x826b
movq -0xb0(%rbp), %rax
movl -0xb4(%rbp), %esi
movl -0xa4(%rbp), %edi
callq *%rax
jmp 0x8282
leaq 0x5517(%rip), %rax      # 0xd7a0
movq (%rax), %rax
movl $0x2, %edi
callq *%rax
jmp 0x8295
jmp 0x835a
leaq -0x64(%rbp), %rdi
callq 0x66c0
movb %al, -0xb5(%rbp)
jmp 0x82ab
movb -0xb5(%rbp), %al
testb $0x1, %al
jne 0x82b7
jmp 0x8316
leaq 0x54ba(%rip), %rax      # 0xd778
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x6660
movl %eax, -0xbc(%rbp)
jmp 0x82d9
leaq -0x64(%rbp), %rdi
callq 0x83d0
movl %eax, -0xcc(%rbp)
jmp 0x82ea
movq -0xc8(%rbp), %rax
movl -0xcc(%rbp), %esi
movl -0xbc(%rbp), %edi
callq *%rax
jmp 0x8301
leaq 0x5498(%rip), %rax      # 0xd7a0
movq (%rax), %rax
movl $0x2, %edi
callq *%rax
jmp 0x8314
jmp 0x8358
leaq -0x64(%rbp), %rdi
callq 0x7590
movb %al, -0xcd(%rbp)
jmp 0x8327
movb -0xcd(%rbp), %al
testb $0x1, %al
jne 0x8333
jmp 0x8356
leaq 0x5466(%rip), %rax      # 0xd7a0
movq (%rax), %rax
movl $0x2, %edi
callq *%rax
jmp 0x8346
leaq 0x5443(%rip), %rax      # 0xd790
movq (%rax), %rax
callq *%rax
jmp 0x8354
jmp 0x8356
jmp 0x8358
jmp 0x835a
jmp 0x835c
jmp 0x835e
leaq -0x64(%rbp), %rdi
callq 0x87e0
addq $0xd0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x2200
nopl (%rax)