// File: 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
subq $0x140, %rsp            # imm = 0x140
movq %rdx, -0x140(%rbp)
movq %rsi, -0x138(%rbp)
movq %rdi, -0x128(%rbp)
movb %r8b, %al
movq %rdi, %r8
movq %r8, -0x130(%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, -0x120(%rbp)
callq 0x3440
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rdx
leaq 0xd697(%rip), %rsi      # 0x15202
callq 0x50d0
jmp 0x7b72
leaq -0x23(%rbp), %rdi
callq 0x32f0
movq -0x138(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x3110
jmp 0x7b90
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x7a50
jmp 0x7ba2
leaq -0x90(%rbp), %rdi
callq 0x3190
movq -0x140(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x3110
jmp 0x7bc3
leaq -0xb0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x7a50
jmp 0x7bd5
leaq -0xb0(%rbp), %rdi
callq 0x3190
movl $0x3, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jl 0x7d06
movslq -0xb4(%rbp), %rax
movl -0x50(%rbp,%rax,4), %eax
movslq -0xb4(%rbp), %rcx
cmpl -0x60(%rbp,%rcx,4), %eax
jge 0x7ccf
movslq -0xb4(%rbp), %rax
movl -0x50(%rbp,%rax,4), %ecx
addl $0x10, %ecx
movslq -0xb4(%rbp), %rax
subl -0x60(%rbp,%rax,4), %ecx
movslq -0xb4(%rbp), %rax
movl %ecx, -0x70(%rbp,%rax,4)
cmpl $0x0, -0xb4(%rbp)
je 0x7cbe
movl -0xb4(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x50(%rbp,%rax,4), %ecx
addl $-0x1, %ecx
movl %ecx, -0x50(%rbp,%rax,4)
jmp 0x7ccd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x23(%rbp), %rdi
callq 0x32f0
jmp 0x7eed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x7ee1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3190
jmp 0x7ee1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3190
jmp 0x7ee1
testb $0x1, -0x21(%rbp)
je 0x7ccb
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
jmp 0x7ccd
jmp 0x7cf0
movslq -0xb4(%rbp), %rax
movl -0x50(%rbp,%rax,4), %ecx
movslq -0xb4(%rbp), %rax
subl -0x60(%rbp,%rax,4), %ecx
movslq -0xb4(%rbp), %rax
movl %ecx, -0x70(%rbp,%rax,4)
jmp 0x7cf2
movl -0xb4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x7beb
movl -0x70(%rbp), %eax
shll $0x4, %eax
shll $0x4, %eax
shll $0x4, %eax
movl -0x6c(%rbp), %ecx
shll $0x4, %ecx
shll $0x4, %ecx
addl %ecx, %eax
movl -0x68(%rbp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
addl -0x64(%rbp), %eax
movl %eax, -0x38(%rbp)
movslq -0x38(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x82f0
leaq -0xc0(%rbp), %rdi
callq 0x83d0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x7d6a
cmpl $0x0, -0x3c(%rbp)
je 0x7d6a
movq -0x20(%rbp), %rax
movb $0x1, 0x2(%rax)
jmp 0x7d72
movq -0x20(%rbp), %rax
movb $0x0, 0x2(%rax)
leaq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0x7, %edx
callq 0x8340
jmp 0x7d8c
leaq -0xd0(%rbp), %rdi
callq 0x8380
movb %al, %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x7(%rax)
leaq -0xd0(%rbp), %rdi
callq 0x83c0
cmpl $0x0, -0x3c(%rbp)
jne 0x7dc0
movq -0x20(%rbp), %rax
movb $0x1, 0x6(%rax)
jmp 0x7dc8
movq -0x20(%rbp), %rax
movb $0x0, 0x6(%rax)
movl $0x3, -0xd4(%rbp)
cmpl $0x0, -0xd4(%rbp)
jl 0x7ebb
movslq -0xd4(%rbp), %rax
cmpl $0x0, -0x70(%rbp,%rax,4)
jl 0x7e42
movslq -0xd4(%rbp), %rax
cmpl $0x9, -0x70(%rbp,%rax,4)
jg 0x7e42
movq -0x128(%rbp), %rdx
movslq -0xd4(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
addl $0x30, %eax
movsbl %al, %esi
leaq -0xf8(%rbp), %rdi
callq 0x84f0
jmp 0x7e21
movq -0x128(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x3330
leaq -0xf8(%rbp), %rdi
callq 0x3190
jmp 0x7ea5
movslq -0xd4(%rbp), %rax
cmpl $0xa, -0x70(%rbp,%rax,4)
jl 0x7ea3
movslq -0xd4(%rbp), %rax
cmpl $0xf, -0x70(%rbp,%rax,4)
jg 0x7ea3
movq -0x128(%rbp), %rdx
movslq -0xd4(%rbp), %rax
movl -0x70(%rbp,%rax,4), %eax
addl $0x37, %eax
movsbl %al, %esi
leaq -0x118(%rbp), %rdi
callq 0x84f0
jmp 0x7e84
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x3330
leaq -0x118(%rbp), %rdi
callq 0x3190
jmp 0x7ea5
jmp 0x7ea7
movl -0xd4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x7dd2
movb $0x1, -0x22(%rbp)
testb $0x1, -0x22(%rbp)
jne 0x7ed1
movq -0x128(%rbp), %rdi
callq 0x3190
movq -0x130(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x128(%rbp), %rdi
callq 0x3190
movq -0x30(%rbp), %rdi
callq 0x3430
nopw %cs:(%rax,%rax)