// File: /workspace/github_cpp_makefile_star2_O3/sthapliyal37[P]Microprocessor_8085_Updated/Essential.cpp
// Function: hexSub16bit(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 hexSub16bit(string arg1,string arg2,bool* flag,bool carry){
	
	string resultant = "";
	int variable;
	int parity;
	int value1[4];
	int value2[4];
	int tempAnswer[4];
	hexToDecimal(arg1,value1);
	hexToDecimal(arg2,value2);
	for(int i=3;i>=0;i--){
		
		if(value1[i] < value2[i]){
			
			tempAnswer[i] = (16 + value1[i]) - value2[i];
			if(i!=0)
				--value1[i-1];
			else{
				if(carry)
					flag[0] = true;
			}
		}
		else
		
			tempAnswer[i] = value1[i] - value2[i];
	}
	variable = tempAnswer[0]*16*16*16 + tempAnswer[1]*16*16 + tempAnswer[2]*16 + tempAnswer[3];
	bitset<16> 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 = 3;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;
		}

	return resultant;
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, -0x2c(%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 0x9aa8(%rip), %rdx      # 0xe202
movq %rdx, %rsi
callq 0x328a
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x31ec
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rax
testl %eax, %eax
jle 0x47bf
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movsbl (%rdi,%rcx), %edx
leal -0x30(%rdx), %esi
leal -0x37(%rdx), %r8d
addl $-0x30, %edx
cmpb $0xa, %sil
cmovael %r8d, %edx
movl %edx, -0x60(%rbp,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x479d
cmpq %r15, %rdi
je 0x47d3
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x90(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x31ec
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rax
testl %eax, %eax
jle 0x4834
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movsbl (%rdi,%rcx), %edx
leal -0x30(%rdx), %esi
leal -0x37(%rdx), %r8d
addl $-0x30, %edx
cmpb $0xa, %sil
cmovael %r8d, %edx
movl %edx, -0xd0(%rbp,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x480f
cmpq %r15, %rdi
je 0x4848
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2210
xorl %eax, %eax
movl -0x54(%rbp,%rax), %ecx
subl -0xc4(%rbp,%rax), %ecx
jge 0x486a
addl $0x10, %ecx
movl %ecx, -0x34(%rbp,%rax)
cmpq $-0xc, %rax
je 0x487a
decl -0x58(%rbp,%rax)
jmp 0x486e
movl %ecx, -0x34(%rbp,%rax)
addq $-0x4, %rax
cmpq $-0x10, %rax
jne 0x484a
jmp 0x4884
cmpb $0x0, -0x2c(%rbp)
je 0x4884
movb $0x1, (%r14)
movl -0x40(%rbp), %eax
movl -0x3c(%rbp), %ecx
shll $0xc, %eax
shll $0x8, %ecx
addl %eax, %ecx
movl -0x38(%rbp), %eax
shll $0x4, %eax
addl %ecx, %eax
addl -0x34(%rbp), %eax
movzwl %ax, %edi
xorl %edx, %edx
movl %eax, %ecx
xorb %ah, %cl
setnp %sil
shrb $0x7, %al
testl %edi, %edi
je 0x48c4
movb %sil, %dl
testq %rdx, %rdx
jne 0x48c4
movb $0x1, 0x2(%r14)
movb %al, 0x7(%r14)
jmp 0x48d5
movb $0x0, 0x2(%r14)
movb %al, 0x7(%r14)
testl %edi, %edi
je 0x4958
xorl %eax, %eax
movb %al, 0x6(%r14)
leaq -0x70(%rbp), %r15
movl $0x3, %r12d
leaq -0x80(%rbp), %r14
movl -0x40(%rbp,%r12,4), %eax
cmpl $0x9, %eax
ja 0x4905
orb $0x30, %al
movsbl %al, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4bc8
jmp 0x491d
leal -0xa(%rax), %ecx
cmpl $0x5, %ecx
ja 0x493d
addb $0x37, %al
movsbl %al, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4bc8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2270
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x493d
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2210
addq $-0x1, %r12
jb 0x48e9
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0x48d7
jmp 0x4963
jmp 0x4963
movq %rax, %r14
movq (%rbx), %rdi
cmpq -0x48(%rbp), %rdi
je 0x497e
movq -0x48(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2210
movq %r14, %rdi
callq 0x2320