// File: /workspace/github_cpp_makefile_star2_O2/sthapliyal37[P]Microprocessor_8085_Updated/main.cpp
// Function: main
int main(int argc , char*argv[])
{
	map<string,string> memory;
	vector<string> sequence;
	string input;
	ifstream infile("test5.txt");
	if(argc!=0)	
	{
			ifstream infile(argv[1]);
	}
	string start=" ",pc=" ";
	string end="HLT",s;
	string registers[7];
	bool flag[8];
	int n;
	cout<<"Enter  Number of MemoryAddresses needed:: ";
	cin>>n;
	for(int i=0;i<n;i++)
	{		
		string str1,str2;
		cin>>str1>>str2;
		memory[str1]=str2;		
	}
	for(int i=0;i<7;i++)
			registers[i]="00";
	for(int i=0;i<8;i++)
			flag[i]=false;	
	cout<<"Starting Memory Address :: ";
	
	cin>>start;
	pc=start;
	/*if(memoryValidation(start))
	/{
				cout<<endl<<"INVALID/MEMORY ADDRESS OR RESERVED ADDRESS"<<endl;
					return 0;
	}*/	
	getline(infile,s);
	while(s.compare(end))
	{
				//if(inputValidation(s))
				//{
					cout<<pc;
					sequence.push_back(pc);	
					memory[pc]=s;
					string delimiter = " ";
					string token = s.substr(0, s.find(delimiter)); 
					pc=allocate_memory(token,pc);
					cout<<"::"<<s<<endl;
					getline(infile,s);
				//}		
				/*else
				{
							cout<<"INVALID INPUT"<<endl;
							return 0;	
			}*/
	}
	pc=start;
	int count=0;	
	int last=sequence.size()-1;
	//cout<<sequence[last];
	while(pc.compare(sequence[last]))
	{					
			cout<<memory[pc]<<endl;		
		pc=execute_statement(memory[pc],flag,registers,memory,pc);
	}
	pc=execute_statement(memory[pc],flag,registers,memory,pc);
	cout<<"*************************************************"<<endl<<endl;
	cout<<"REGISTERS"<<endl;
	for(int i=0;i<7;i++)	
		cout<<registers[i]<<" ";
	cout<<endl;	
	cout<<"*************************************************"<<endl;	
	cout<<endl;
	cout<<"flag"<<endl;
	for(int i=0;i<7;i++)	
		cout<<flag[i]<<" ";
	cout<<endl;

	cout<<"Enter  Number of RESult Addresses needed:: ";
	cin>>n;
	string result[n];
	for(int i=0;i<n;i++)
		cin>>result[i];
		
	cout<<"*************************************************"<<endl;
	cout<<"Accumulator Result ::"<<registers[0]<<endl;	
	cout<<"*************************************************"<<endl;
	cout<<"Memory Result"<<endl;
	for(int i=0;i<n;i++)
		cout<<result[i]<<" :: "<<memory[result[i]]<<endl;;

return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x648, %rsp            # imm = 0x648
movq %rsi, %rbx
leaq -0x108(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movl %edi, %r14d
andq $0x0, -0x70(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
leaq -0x1c0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x1108(%rip), %rsi      # 0xa250
leaq -0x668(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2330
testl %r14d, %r14d
je 0x917b
movq 0x8(%rbx), %rsi
leaq -0x460(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2330
leaq -0x460(%rbp), %rdi
callq 0x2080
leaq 0x1121(%rip), %rsi      # 0xa2a3
leaq -0xe0(%rbp), %rdi
leaq -0x460(%rbp), %rdx
callq 0x2f1e
leaq 0x1107(%rip), %rsi      # 0xa2a3
leaq -0xa0(%rbp), %rdi
leaq -0x460(%rbp), %rdx
callq 0x2f1e
leaq 0x10a4(%rip), %rsi      # 0xa25a
leaq -0x190(%rbp), %rdi
leaq -0x460(%rbp), %rdx
callq 0x2f1e
leaq -0x120(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
pushq $0x10
popq %rax
leaq (%rax,%rbp), %rcx
addq $-0x460, %rcx           # imm = 0xFBA0
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0xf0, %rax
jne 0x91df
movq 0x4dc7(%rip), %rdi      # 0xdfd0
leaq 0x104e(%rip), %rsi      # 0xa25e
callq 0x21e0
movq 0x4dc4(%rip), %rdi      # 0xdfe0
leaq -0x2c(%rbp), %rsi
callq 0x2130
xorl %r13d, %r13d
leaq -0x60(%rbp), %r14
leaq -0xc0(%rbp), %r15
leaq -0x110(%rbp), %r12
xorl %ebx, %ebx
cmpl -0x2c(%rbp), %ebx
jge 0x92b3
leaq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
andq $0x0, -0x58(%rbp)
movb %r13b, -0x50(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
andq $0x0, -0xb8(%rbp)
movb %r13b, -0xb0(%rbp)
movq 0x4d6a(%rip), %rdi      # 0xdfe0
movq %r14, %rsi
callq 0x2260
movq %rax, %rdi
movq %r15, %rsi
callq 0x2260
movq %r12, %rdi
movq %r14, %rsi
callq 0x724c
movq %rax, %rdi
movq %r15, %rsi
callq 0x2120
movq %r15, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x20f0
incl %ebx
jmp 0x923c
xorl %r14d, %r14d
leaq 0xf2d(%rip), %rbx       # 0xa1ea
cmpq $0xe0, %r14
je 0x92df
leaq (%r14,%rbp), %rdi
addq $-0x460, %rdi           # imm = 0xFBA0
movq %rbx, %rsi
callq 0x2340
addq $0x20, %r14
jmp 0x92bd
xorl %eax, %eax
cmpq $0x8, %rax
je 0x92f1
movb $0x0, -0x40(%rbp,%rax)
incq %rax
jmp 0x92e1
movq 0x4cd8(%rip), %rdi      # 0xdfd0
leaq 0xf8a(%rip), %rsi       # 0xa289
callq 0x21e0
movq 0x4cd5(%rip), %rdi      # 0xdfe0
leaq -0xe0(%rbp), %rsi
callq 0x2260
leaq -0xa0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2120
leaq -0x668(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x2070
leaq -0x130(%rbp), %rbx
leaq -0xa0(%rbp), %r12
movq %rbx, %rdi
leaq -0x190(%rbp), %rsi
callq 0x2040
testl %eax, %eax
je 0x9480
movq 0x4c67(%rip), %rdi      # 0xdfd0
movq %r12, %rsi
callq 0x21d0
leaq -0x80(%rbp), %rdi
movq %r12, %rsi
callq 0x9a84
leaq -0x110(%rbp), %rdi
movq %r12, %rsi
callq 0x724c
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2120
leaq -0x60(%rbp), %r13
movq %r13, %rdi
leaq 0xefe(%rip), %rsi       # 0xa2a3
leaq -0xc0(%rbp), %r14
movq %r14, %rdx
callq 0x2f1e
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x2360
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2210
leaq -0x1b0(%rbp), %rdi
movq %r14, %rsi
callq 0x2280
leaq -0x230(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x2280
leaq -0x250(%rbp), %r14
movq %r14, %rdi
leaq -0x1b0(%rbp), %r13
movq %r13, %rsi
movq %r15, %rdx
callq 0x319f
movq %r12, %rdi
movq %r14, %rsi
callq 0x2250
movq %r14, %rdi
callq 0x20f0
movq %r15, %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20f0
movq 0x4b98(%rip), %rdi      # 0xdfd0
leaq 0xee6(%rip), %rsi       # 0xa325
callq 0x21e0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq -0x668(%rbp), %rdi
movq %rbx, %rsi
callq 0x2070
leaq -0xc0(%rbp), %rdi
callq 0x20f0
leaq -0x60(%rbp), %rdi
callq 0x20f0
jmp 0x934b
leaq -0xa0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2120
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rax
subq %rsi, %rax
shlq $0x1b, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rax, %rcx
sarq $0x1b, %rcx
movq %rcx, -0x38(%rbp)
leaq -0xa0(%rbp), %rbx
leaq -0x110(%rbp), %r14
leaq -0x210(%rbp), %r12
leaq -0x1f0(%rbp), %r13
leaq -0x60(%rbp), %r15
addq -0x38(%rbp), %rsi
movq %rbx, %rdi
callq 0x2040
testl %eax, %eax
je 0x9576
movq %r14, %rdi
movq %rbx, %rsi
callq 0x724c
movq 0x4ad3(%rip), %rdi      # 0xdfd0
movq %rax, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq %r14, %rdi
movq %rbx, %rsi
callq 0x724c
movq %r12, %rdi
movq %rax, %rsi
callq 0x2280
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2280
movq %r15, %rdi
movq %r12, %rsi
leaq -0x40(%rbp), %rdx
leaq -0x460(%rbp), %rcx
movq %r14, %r8
movq %r13, %r9
callq 0x40c4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2250
movq %r15, %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
movq -0x80(%rbp), %rsi
jmp 0x94d7
leaq -0x110(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x724c
leaq -0x170(%rbp), %rdi
movq %rax, %rsi
callq 0x2280
leaq -0x150(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2280
leaq -0x60(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0x40(%rbp), %rdx
leaq -0x460(%rbp), %rcx
leaq -0x110(%rbp), %r8
leaq -0x150(%rbp), %r9
callq 0x40c4
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rbx
movq %rbx, %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x20f0
leaq -0x150(%rbp), %rdi
callq 0x20f0
leaq -0x170(%rbp), %rdi
callq 0x20f0
movq 0x49c2(%rip), %rdi      # 0xdfd0
leaq 0xc90(%rip), %rsi       # 0xa2a5
callq 0x21e0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
movq 0x499f(%rip), %rdi      # 0xdfd0
leaq 0xc9f(%rip), %rsi       # 0xa2d7
callq 0x21e0
movq %rax, %rdi
callq 0x2100
xorl %r15d, %r15d
movq 0x4981(%rip), %rbx      # 0xdfd0
leaq 0xc4d(%rip), %r14       # 0xa2a3
cmpq $0xe0, %r15
je 0x9683
leaq (%r15,%rbp), %rsi
addq $-0x460, %rsi           # imm = 0xFBA0
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21e0
addq $0x20, %r15
jmp 0x9656
movq 0x4946(%rip), %rdi      # 0xdfd0
callq 0x2100
movq 0x493a(%rip), %rdi      # 0xdfd0
leaq 0xc08(%rip), %rsi       # 0xa2a5
callq 0x21e0
movq %rax, %rdi
callq 0x2100
movq 0x491f(%rip), %rdi      # 0xdfd0
callq 0x2100
movq 0x4913(%rip), %rdi      # 0xdfd0
leaq 0xc1d(%rip), %rsi       # 0xa2e1
callq 0x21e0
movq %rax, %rdi
callq 0x2100
xorl %r15d, %r15d
movq 0x48f5(%rip), %rbx      # 0xdfd0
leaq 0xbc1(%rip), %r14       # 0xa2a3
cmpq $0x7, %r15
je 0x9706
movzbl -0x40(%rbp,%r15), %esi
movq %rbx, %rdi
callq 0x22e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21e0
incq %r15
jmp 0x96e2
movq 0x48c3(%rip), %rdi      # 0xdfd0
callq 0x2100
movq 0x48b7(%rip), %rdi      # 0xdfd0
leaq 0xbc6(%rip), %rsi       # 0xa2e6
callq 0x21e0
movq 0x48b4(%rip), %rdi      # 0xdfe0
leaq -0x2c(%rbp), %rsi
callq 0x2130
movq %rsp, -0x38(%rbp)
movl -0x2c(%rbp), %r15d
movq %rsp, %rbx
movq %r15, %rax
shlq $0x5, %rax
subq %rax, %rbx
movq %rbx, %rsp
testq %r15, %r15
je 0x976c
leaq 0x10(%rbx), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rcx
addq $-0x20, %rax
jne 0x9756
xorl %r13d, %r13d
movq 0x486a(%rip), %r12      # 0xdfe0
movq %rbx, %r14
movslq -0x2c(%rbp), %rax
cmpq %rax, %r13
jge 0x9796
movq %r12, %rdi
movq %r14, %rsi
callq 0x2260
incq %r13
addq $0x20, %r14
jmp 0x9779
movq 0x4833(%rip), %rdi      # 0xdfd0
leaq 0xb01(%rip), %rsi       # 0xa2a5
callq 0x21e0
movq %rax, %rdi
callq 0x2100
movq 0x4818(%rip), %rdi      # 0xdfd0
leaq 0xb53(%rip), %rsi       # 0xa312
callq 0x21e0
leaq -0x460(%rbp), %rsi
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
movq 0x47ee(%rip), %rdi      # 0xdfd0
leaq 0xabc(%rip), %rsi       # 0xa2a5
callq 0x21e0
movq %rax, %rdi
callq 0x2100
movq 0x47d3(%rip), %rdi      # 0xdfd0
leaq 0xb24(%rip), %rsi       # 0xa328
callq 0x21e0
movq %rax, %rdi
callq 0x2100
xorl %r14d, %r14d
movq %rbx, %r12
movslq -0x2c(%rbp), %rax
cmpq %rax, %r14
jge 0x986c
movq 0x47a9(%rip), %rdi      # 0xdfd0
movq %r12, %rsi
callq 0x21d0
movq %rax, %rdi
leaq 0xa67(%rip), %rsi       # 0xa2a0
callq 0x21e0
movq %rax, %r13
leaq -0x110(%rbp), %rdi
movq %r12, %rsi
callq 0x724c
movq %r13, %rdi
movq %rax, %rsi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
incq %r14
addq $0x20, %r12
jmp 0x9817
testq %r15, %r15
je 0x9888
addq $-0x20, %rbx
shlq $0x5, %r15
leaq (%rbx,%r15), %rdi
callq 0x20f0
addq $-0x20, %r15
jne 0x9879
movq -0x38(%rbp), %rsp
movl $0xc0, %ebx
leaq (%rbx,%rbp), %rdi
addq $-0x460, %rdi           # imm = 0xFBA0
callq 0x20f0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x9891
leaq -0x130(%rbp), %rdi
callq 0x20f0
leaq -0x190(%rbp), %rdi
callq 0x20f0
leaq -0xa0(%rbp), %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
leaq -0x668(%rbp), %rdi
callq 0x2080
leaq -0x1d0(%rbp), %rdi
callq 0x20f0
leaq -0x80(%rbp), %rdi
callq 0x53f2
leaq -0x110(%rbp), %rdi
callq 0x9ac0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x994b
movq %rax, %r14
leaq -0x150(%rbp), %rdi
callq 0x20f0
jmp 0x992f
movq %rax, %r14
leaq -0x170(%rbp), %rdi
jmp 0x99d3
movq %rax, %r14
jmp 0x9a37
movq %rax, %r14
jmp 0x9a43
movq %rax, %r14
jmp 0x9a4f
movq %rax, %r14
jmp 0x9a5b
jmp 0x99fd
jmp 0x99fd
jmp 0x99dc
jmp 0x99fd
jmp 0x99dc
movq %rax, %r14
jmp 0x9982
movq %rax, %r14
leaq -0x1f0(%rbp), %rdi
callq 0x20f0
leaq -0x210(%rbp), %rdi
jmp 0x99d3
jmp 0x99fd
movq %rax, %r14
jmp 0x99cf
jmp 0x99c0
movq %rax, %r14
jmp 0x99a8
movq %rax, %r14
leaq -0x230(%rbp), %rdi
callq 0x20f0
leaq -0x1b0(%rbp), %rdi
callq 0x20f0
jmp 0x99c3
jmp 0x99fd
jmp 0x99fd
jmp 0x99fd
jmp 0x99fd
jmp 0x99c0
movq %rax, %r14
leaq -0xc0(%rbp), %rdi
callq 0x20f0
leaq -0x60(%rbp), %rdi
callq 0x20f0
jmp 0x9a00
jmp 0x99fd
movq %rax, %r14
testq %r15, %r15
je 0x9a00
addq $-0x20, %rbx
shlq $0x5, %r15
leaq (%rbx,%r15), %rdi
callq 0x20f0
addq $-0x20, %r15
jne 0x99ec
jmp 0x9a00
movq %rax, %r14
movl $0xc0, %ebx
leaq (%rbx,%rbp), %rdi
addq $-0x460, %rdi           # imm = 0xFBA0
callq 0x20f0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x9a05
leaq -0x130(%rbp), %rdi
callq 0x20f0
leaq -0x190(%rbp), %rdi
callq 0x20f0
leaq -0xa0(%rbp), %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
leaq -0x668(%rbp), %rdi
callq 0x2080
leaq -0x1d0(%rbp), %rdi
callq 0x20f0
leaq -0x80(%rbp), %rdi
callq 0x53f2
leaq -0x110(%rbp), %rdi
callq 0x9ac0
movq %r14, %rdi
callq 0x2310