// File: akshayrajput[P]ARMV8_Simulator/simulo.cpp
// Function: fetch()
void fetch()
{

		
	uint64_t addr = PC.getData();
	int i = addr - Memory[0].addr; 
	if(SR[i]>1 && subroutine == 0)//don't mess with main flow of control
	{	
			skip = true;
	}
	else if(SR[i] == 1)
		SR[i]++;

	printf("[log]-fetching instruction\n");
	if(debug_prompt)
	{
		printf("DEBUG-mode enabled\n");
		show_prompt();
	}

	if(breakpt[i])
	{
		printf("Break point at address - %lx\n",addr);
		show_prompt();
	}
		//TODO - read the memory
	uint64_t w = Memory[i].getData()<<24; i++;
	uint64_t x = Memory[i].getData()<<16; i++;
	uint64_t y = Memory[i].getData()<<8; i++;
	uint64_t z = Memory[i].getData(); i++;


	//TODO - take data to IR

	IR.setData(w|x|y|z);
	BR.setData(PC.getData());
	PC.setData(addr + 4 );
	printf("[log]-done fetching instruction\n");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
leaq 0x14a29(%rip), %rdi     # 0x1e1e8
callq 0xa6c0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
subq 0x4a0d(%rip), %rax      # 0xe1e0
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x15a1f(%rip), %rax     # 0x1f200
cmpl $0x1, (%rax,%rcx,4)
jle 0x97f9
cmpl $0x0, 0x19a12(%rip)     # 0x23200
jne 0x97f9
movb $0x1, 0x14a06(%rip)     # 0x1e1fd
jmp 0x9827
movslq -0xc(%rbp), %rcx
leaq 0x159fc(%rip), %rax     # 0x1f200
cmpl $0x1, (%rax,%rcx,4)
jne 0x9825
movslq -0xc(%rbp), %rcx
leaq 0x159eb(%rip), %rax     # 0x1f200
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0x159de(%rip), %rax     # 0x1f200
movl %edx, (%rax,%rcx,4)
jmp 0x9827
leaq 0x25b6(%rip), %rdi      # 0xbde4
movb $0x0, %al
callq 0x1030
testb $0x1, 0x149c0(%rip)     # 0x1e1fc
je 0x9851
leaq 0x25bb(%rip), %rdi      # 0xbe00
movb $0x0, %al
callq 0x1030
callq 0x9510
movslq -0xc(%rbp), %rcx
leaq 0x149a4(%rip), %rax     # 0x1e200
testb $0x1, (%rax,%rcx)
je 0x9879
movq -0x8(%rbp), %rsi
leaq 0x25a7(%rip), %rdi      # 0xbe14
movb $0x0, %al
callq 0x1030
callq 0x9510
movslq -0xc(%rbp), %rax
leaq 0x495c(%rip), %rdi      # 0xe1e0
shlq $0x4, %rax
addq %rax, %rdi
callq 0xa6a0
movzbl %al, %eax
shll $0x18, %eax
cltq
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
leaq 0x4930(%rip), %rdi      # 0xe1e0
shlq $0x4, %rax
addq %rax, %rdi
callq 0xa6a0
movzbl %al, %eax
shll $0x10, %eax
cltq
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
leaq 0x4904(%rip), %rdi      # 0xe1e0
shlq $0x4, %rax
addq %rax, %rdi
callq 0xa6a0
movzbl %al, %eax
shll $0x8, %eax
cltq
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
leaq 0x48d8(%rip), %rdi      # 0xe1e0
shlq $0x4, %rax
addq %rax, %rdi
callq 0xa6a0
movzbl %al, %eax
movq %rax, -0x30(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x18(%rbp), %rsi
orq -0x20(%rbp), %rsi
orq -0x28(%rbp), %rsi
orq -0x30(%rbp), %rsi
leaq 0x148a5(%rip), %rdi     # 0x1e1e0
callq 0xa710
leaq 0x148a1(%rip), %rdi     # 0x1e1e8
callq 0xa6c0
movq %rax, %rsi
leaq 0x1489a(%rip), %rdi     # 0x1e1f0
callq 0xa710
movq -0x8(%rbp), %rsi
addq $0x4, %rsi
leaq 0x1487e(%rip), %rdi     # 0x1e1e8
callq 0xa710
leaq 0x24bc(%rip), %rdi      # 0xbe32
movb $0x0, %al
callq 0x1030
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)