// File: sthapliyal37[P]Microprocessor_8085_Updated/Essential.cpp
// Function: hexAdd(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool*, bool)
string hexAdd(string arg1,string arg2,bool* flag,bool carry){
	
	string resultant = "";
	int variable;
	int value1[5] = {0,0};
	int value2[5] = {0,0};
	int tempAnswer[2];
	hexToDecimal(arg1,value1);
	hexToDecimal(arg2,value2);
	
	tempAnswer[1] = value1[1] + value2[1];
	if(tempAnswer[1]>=16){
	
		tempAnswer[1] = tempAnswer[1]%16;
		value1[0]++;
		flag[4] = true;
		}
	tempAnswer[0] = value1[0] + value2[0];
	if(tempAnswer[0]>=16){
	
		tempAnswer[0] = tempAnswer[0]%16;
		if(carry == true)
			flag[0] = true;
	}
	
	variable = tempAnswer[0]*16 + tempAnswer[1];
	bitset<8> dataInBinary(variable);
	int parity = dataInBinary.count();
	if(parity%2 == 0 && parity!=0)
		flag[2] = true;
	else
		flag[2] = false;
	flag[7] = dataInBinary[7];
	if(parity == 0)
		flag[6] = true;
	
	for(int i = 1;i>=0;--i){
		
		if(tempAnswer[i]>=0 && tempAnswer[i]<=9)
			resultant = char('0' + tempAnswer[i]) + resultant;
		else if(tempAnswer[i]>=10 && tempAnswer[i]<=15)
			resultant = (char)('A'+(tempAnswer[i] - 10)) + resultant;
		}
	//cout<<resultant<<endl;
	return resultant;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdx, -0x148(%rbp)
movq %rsi, -0x140(%rbp)
movq %rdi, -0x130(%rbp)
movb %r8b, %al
movq %rdi, %r8
movq %r8, -0x138(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
leaq -0x23(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x3440
movq -0x130(%rbp), %rdi
movq -0x128(%rbp), %rdx
leaq 0xdae7(%rip), %rsi      # 0x15202
callq 0x50d0
jmp 0x7722
leaq -0x23(%rbp), %rdi
callq 0x32f0
movq -0x140(%rbp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movl $0x0, -0x40(%rbp)
movaps %xmm0, -0x70(%rbp)
movl $0x0, -0x60(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3110
jmp 0x7759
leaq -0x98(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x7a50
jmp 0x776b
leaq -0x98(%rbp), %rdi
callq 0x3190
movq -0x148(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x3110
jmp 0x778c
leaq -0xb8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x7a50
jmp 0x779e
leaq -0xb8(%rbp), %rdi
callq 0x3190
movl -0x4c(%rbp), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $0x10, -0x74(%rbp)
jl 0x7843
movl -0x74(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x74(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movb $0x1, 0x4(%rax)
jmp 0x7843
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x23(%rbp), %rdi
callq 0x32f0
jmp 0x7a46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x7a3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3190
jmp 0x7a3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3190
jmp 0x7a3a
movl -0x50(%rbp), %eax
addl -0x70(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0x10, -0x78(%rbp)
jl 0x7876
movl -0x78(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x78(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x7874
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
jmp 0x7876
movl -0x78(%rbp), %eax
shll $0x4, %eax
addl -0x74(%rbp), %eax
movl %eax, -0x38(%rbp)
movslq -0x38(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x83f0
leaq -0xc0(%rbp), %rdi
callq 0x8440
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x78ca
cmpl $0x0, -0xc4(%rbp)
je 0x78ca
movq -0x20(%rbp), %rax
movb $0x1, 0x2(%rax)
jmp 0x78d2
movq -0x20(%rbp), %rax
movb $0x0, 0x2(%rax)
leaq -0xd8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0x7, %edx
callq 0x8460
jmp 0x78ec
leaq -0xd8(%rbp), %rdi
callq 0x84a0
movb %al, %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x7(%rax)
leaq -0xd8(%rbp), %rdi
callq 0x84e0
cmpl $0x0, -0xc4(%rbp)
jne 0x7921
movq -0x20(%rbp), %rax
movb $0x1, 0x6(%rax)
movl $0x1, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
jl 0x7a14
movslq -0xdc(%rbp), %rax
cmpl $0x0, -0x78(%rbp,%rax,4)
jl 0x799b
movslq -0xdc(%rbp), %rax
cmpl $0x9, -0x78(%rbp,%rax,4)
jg 0x799b
movq -0x130(%rbp), %rdx
movslq -0xdc(%rbp), %rax
movl -0x78(%rbp,%rax,4), %eax
addl $0x30, %eax
movsbl %al, %esi
leaq -0x100(%rbp), %rdi
callq 0x84f0
jmp 0x797a
movq -0x130(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3330
leaq -0x100(%rbp), %rdi
callq 0x3190
jmp 0x79fe
movslq -0xdc(%rbp), %rax
cmpl $0xa, -0x78(%rbp,%rax,4)
jl 0x79fc
movslq -0xdc(%rbp), %rax
cmpl $0xf, -0x78(%rbp,%rax,4)
jg 0x79fc
movq -0x130(%rbp), %rdx
movslq -0xdc(%rbp), %rax
movl -0x78(%rbp,%rax,4), %eax
addl $0x37, %eax
movsbl %al, %esi
leaq -0x120(%rbp), %rdi
callq 0x84f0
jmp 0x79dd
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3330
leaq -0x120(%rbp), %rdi
callq 0x3190
jmp 0x79fe
jmp 0x7a00
movl -0xdc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x792b
movb $0x1, -0x22(%rbp)
testb $0x1, -0x22(%rbp)
jne 0x7a2a
movq -0x130(%rbp), %rdi
callq 0x3190
movq -0x138(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x130(%rbp), %rdi
callq 0x3190
movq -0x30(%rbp), %rdi
callq 0x3430
nop