// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movl %r8d, %r15d
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x649f(%rip), %rsi      # 0xa202
leaq -0x80(%rbp), %rdx
callq 0x2f1e
leaq -0xc0(%rbp), %rdi
movq %r13, %rsi
callq 0x2280
leaq -0xc0(%rbp), %r13
leaq -0x50(%rbp), %rsi
movq %r13, %rdi
callq 0x3d02
movq %r13, %rdi
callq 0x20f0
leaq -0xa0(%rbp), %rdi
movq %r12, %rsi
callq 0x2280
leaq -0xa0(%rbp), %r12
leaq -0x60(%rbp), %rsi
movq %r12, %rdi
callq 0x3d02
movq %r12, %rdi
callq 0x20f0
pushq $0x3
popq %rax
testl %eax, %eax
js 0x3dfa
movl %eax, %ecx
movl -0x50(%rbp,%rcx,4), %edx
subl -0x60(%rbp,%rcx,4), %edx
jge 0x3de7
addl $0x10, %edx
movl %edx, -0x40(%rbp,%rcx,4)
testl %eax, %eax
je 0x3def
leal -0x1(%rax), %ecx
decl -0x50(%rbp,%rcx,4)
jmp 0x3deb
movl %edx, -0x40(%rbp,%rcx,4)
decl %eax
jmp 0x3dc3
testb %r15b, %r15b
je 0x3deb
movb $0x1, (%r14)
jmp 0x3deb
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
movl %eax, %ecx
xorb %ah, %cl
setp %cl
testw $0xffff, %ax            # imm = 0xFFFF
sete 0x6(%r14)
setne %dl
andb %cl, %dl
movb %dl, 0x2(%r14)
shrb $0x7, %al
movb %al, 0x7(%r14)
pushq $0x3
popq %r15
leaq -0x80(%rbp), %r14
testl %r15d, %r15d
js 0x3e8e
movl %r15d, %eax
movl -0x40(%rbp,%rax,4), %eax
cmpl $0x9, %eax
ja 0x3e5e
orb $0x30, %al
movsbl %al, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4059
jmp 0x3e76
leal -0xa(%rax), %ecx
cmpl $0x5, %ecx
ja 0x3e89
addb $0x37, %al
movsbl %al, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4059
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2250
movq %r14, %rdi
callq 0x20f0
decl %r15d
jmp 0x3e3b
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3ea7
jmp 0x3ea7
movq %rax, %r14
movq %rbx, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x2310