// File: /workspace/github_cpp_makefile_star2_O1/sthapliyal37[P]Microprocessor_8085_Updated/Essential.cpp
// Function: hexSub(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 hexSub(string arg1,string arg2,bool* flag,bool carry){
	
	string resultant = "";
	int variable;
	int parity;
	int value1[2];
	int value2[2];
	int tempAnswer[2];
	hexToDecimal(arg1,value1);
	hexToDecimal(arg2,value2);

	if(value1[1] < value2[1]){
		
		tempAnswer[1] = (16+value1[1])-value2[1];
		--value1[0];
		}
	else{
		tempAnswer[1] = value1[1] - value2[1];
	}

	if(value1[0] < value2[0]){
	
		if(carry == true)
			flag[0] = true;
			
		tempAnswer[0] = (16+value1[0]-value2[0]);
		}
	else
		tempAnswer[0] = value1[0] - value2[0];
		
	 
	variable = tempAnswer[0]*16 + tempAnswer[1];
	bitset<8> dataInBinary(variable);
	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;
	else
		flag[6] = false;
		
	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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r8d, -0x34(%rbp)
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, -0x48(%rbp)
movq %rax, (%rdi)
leaq 0x97e6(%rip), %rdx      # 0xe202
movq %rdx, %rsi
callq 0x32be
leaq -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x3224
movq -0xa8(%rbp), %rax
testl %eax, %eax
jle 0x4a84
movq -0xb0(%rbp), %rcx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %edx, %edx
movzbl (%rcx,%rdx), %esi
movsbl %sil, %edi
leal -0x30(%rsi), %r8d
addl $-0x37, %edi
addl $-0x30, %esi
cmpb $0xa, %r8b
cmovael %edi, %esi
movl %esi, -0x3c(%rbp,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x4a5f
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x4a9f
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x80(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x3224
movq -0x88(%rbp), %rax
testl %eax, %eax
jle 0x4afd
movq -0x90(%rbp), %rcx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %edx, %edx
movzbl (%rcx,%rdx), %esi
movsbl %sil, %edi
leal -0x30(%rsi), %r8d
addl $-0x37, %edi
addl $-0x30, %esi
cmpb $0xa, %r8b
cmovael %edi, %esi
movl %esi, -0x50(%rbp,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x4ad8
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x4b15
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movl -0x38(%rbp), %eax
subl -0x4c(%rbp), %eax
jge 0x4b28
addl $0x10, %eax
movl %eax, -0x2c(%rbp)
decl -0x3c(%rbp)
jmp 0x4b2b
movl %eax, -0x2c(%rbp)
movl -0x3c(%rbp), %eax
movl -0x50(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4b42
cmpb $0x0, -0x34(%rbp)
je 0x4b3f
movb $0x1, (%r14)
addl $0x10, %eax
subl %ecx, %eax
movl %eax, -0x30(%rbp)
shll $0x4, %eax
addl -0x2c(%rbp), %eax
movzbl %al, %eax
testb %al, %al
setp %cl
testl %eax, %eax
sete 0x6(%r14)
setne %dl
andb %cl, %dl
movb %dl, 0x2(%r14)
cmpl $0x7f, %eax
seta 0x7(%r14)
leaq -0x60(%rbp), %r15
movl $0x1, %r12d
leaq -0x70(%rbp), %r14
movl -0x30(%rbp,%r12,4), %eax
cmpl $0x9, %eax
ja 0x4b97
orb $0x30, %al
movsbl %al, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4c11
jmp 0x4baf
leal -0xa(%rax), %ecx
cmpl $0x5, %ecx
ja 0x4bcf
addb $0x37, %al
movsbl %al, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4c11
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2270
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x4bcf
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
addq $-0x1, %r12
jb 0x4b7b
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4bee
jmp 0x4bee
movq %rax, %r14
movq (%rbx), %rdi
cmpq -0x48(%rbp), %rdi
je 0x4c09
movq -0x48(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2210
movq %r14, %rdi
callq 0x2320