// File: martinferianc[P]CPUSimulator-EIE2/src/mips_cpu_execute.cpp
// Function: mips_execute_J_X(mips_cpu_impl*, unsigned int const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, unsigned int&, unsigned int&)
mips_error mips_execute_J_X(mips_cpu_h state, const uint32_t* instruction_data, const string& op, string& instruction, uint32_t& pcN, uint32_t& pc){

	stringstream ss;
	mips_error err = mips_ExceptionInvalidInstruction;
	uint32_t imm_unsigned = uint32_t(instruction_data[1]);

	if (op.compare("JUMP")==0){
		pc = pcN;
		pcN = (pc & 0xF0000000) | (imm_unsigned << 2);
		err = mips_ExceptionBreak;
	}

	if (op.compare("JAL")==0){
		mips_cpu_set_register(state, 31, pc + 8);
		pc = pcN;
		pcN = (pc & 0xF0000000) | (imm_unsigned << 2);
		err = mips_ExceptionBreak;
	}

	ss <<op<<" "<<"#"<<instruction_data[1];

	instruction = ss.str();
	return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x31b0
movl $0x2005, -0x1bc(%rbp)   # imm = 0x2005
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x1c0(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x495a(%rip), %rsi      # 0x12c9b
callq 0x30d0
cmpl $0x0, %eax
jne 0xe37e
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
andl $0xf0000000, %ecx       # imm = 0xF0000000
movl -0x1c0(%rbp), %eax
shll $0x2, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x2000, -0x1bc(%rbp)   # imm = 0x2000
movq -0x18(%rbp), %rdi
leaq 0x43a0(%rip), %rsi      # 0x12729
callq 0x30d0
cmpl $0x0, %eax
jne 0xe404
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl (%rax), %edx
addl $0x8, %edx
movl $0x1f, %esi
callq 0x7cc0
jmp 0xe3ac
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
andl $0xf0000000, %ecx       # imm = 0xF0000000
movl -0x1c0(%rbp), %eax
shll $0x2, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x2000, -0x1bc(%rbp)   # imm = 0x2000
jmp 0xe404
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c8(%rbp)
movl %eax, -0x1cc(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x31d0
jmp 0xe4c2
leaq -0x1a8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3240
movq %rax, -0x1f8(%rbp)
jmp 0xe41d
movq -0x1f8(%rbp), %rdi
leaq 0x489d(%rip), %rsi      # 0x12cc8
callq 0x3260
movq %rax, -0x200(%rbp)
jmp 0xe439
movq -0x200(%rbp), %rdi
leaq 0x4863(%rip), %rsi      # 0x12caa
callq 0x3260
movq %rax, -0x208(%rbp)
jmp 0xe455
movq -0x208(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x3390
jmp 0xe46a
leaq -0x1f0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x3250
jmp 0xe47f
movq -0x20(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x3330
leaq -0x1f0(%rbp), %rdi
callq 0x3170
movl -0x1bc(%rbp), %eax
movl %eax, -0x20c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x31d0
movl -0x20c(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0x1c8(%rbp), %rdi
callq 0x3440
nop