// File: 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
subq $0x120, %rsp            # imm = 0x120
movq %rdx, -0x120(%rbp)
movq %rsi, -0x118(%rbp)
movq %rdi, -0x108(%rbp)
movb %r8b, %al
movq %rdi, %r8
movq %r8, -0x110(%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, -0x100(%rbp)
callq 0x3440
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rdx
leaq 0xd297(%rip), %rsi      # 0x15202
callq 0x50d0
jmp 0x7f72
leaq -0x23(%rbp), %rdi
callq 0x32f0
movq -0x118(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x3110
jmp 0x7f8d
leaq -0x78(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x7a50
jmp 0x7f9c
leaq -0x78(%rbp), %rdi
callq 0x3190
movq -0x120(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x3110
jmp 0x7fba
leaq -0x98(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x7a50
jmp 0x7fcc
leaq -0x98(%rbp), %rdi
callq 0x3190
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x8059
movl -0x40(%rbp), %eax
addl $0x10, %eax
subl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x8062
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x23(%rbp), %rdi
callq 0x32f0
jmp 0x8263
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x8257
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3190
jmp 0x8257
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3190
jmp 0x8257
movl -0x40(%rbp), %eax
subl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x808c
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x807e
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
movl -0x44(%rbp), %eax
addl $0x10, %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x8095
movl -0x44(%rbp), %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
shll $0x4, %eax
addl -0x50(%rbp), %eax
movl %eax, -0x38(%rbp)
movslq -0x38(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x83f0
leaq -0xa0(%rbp), %rdi
callq 0x8440
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x80e0
cmpl $0x0, -0x3c(%rbp)
je 0x80e0
movq -0x20(%rbp), %rax
movb $0x1, 0x2(%rax)
jmp 0x80e8
movq -0x20(%rbp), %rax
movb $0x0, 0x2(%rax)
leaq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x7, %edx
callq 0x8460
jmp 0x8102
leaq -0xb0(%rbp), %rdi
callq 0x84a0
movb %al, %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x7(%rax)
leaq -0xb0(%rbp), %rdi
callq 0x84e0
cmpl $0x0, -0x3c(%rbp)
jne 0x8136
movq -0x20(%rbp), %rax
movb $0x1, 0x6(%rax)
jmp 0x813e
movq -0x20(%rbp), %rax
movb $0x0, 0x6(%rax)
movl $0x1, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jl 0x8231
movslq -0xb4(%rbp), %rax
cmpl $0x0, -0x54(%rbp,%rax,4)
jl 0x81b8
movslq -0xb4(%rbp), %rax
cmpl $0x9, -0x54(%rbp,%rax,4)
jg 0x81b8
movq -0x108(%rbp), %rdx
movslq -0xb4(%rbp), %rax
movl -0x54(%rbp,%rax,4), %eax
addl $0x30, %eax
movsbl %al, %esi
leaq -0xd8(%rbp), %rdi
callq 0x84f0
jmp 0x8197
movq -0x108(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x3330
leaq -0xd8(%rbp), %rdi
callq 0x3190
jmp 0x821b
movslq -0xb4(%rbp), %rax
cmpl $0xa, -0x54(%rbp,%rax,4)
jl 0x8219
movslq -0xb4(%rbp), %rax
cmpl $0xf, -0x54(%rbp,%rax,4)
jg 0x8219
movq -0x108(%rbp), %rdx
movslq -0xb4(%rbp), %rax
movl -0x54(%rbp,%rax,4), %eax
addl $0x37, %eax
movsbl %al, %esi
leaq -0xf8(%rbp), %rdi
callq 0x84f0
jmp 0x81fa
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x3330
leaq -0xf8(%rbp), %rdi
callq 0x3190
jmp 0x821b
jmp 0x821d
movl -0xb4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x8148
movb $0x1, -0x22(%rbp)
testb $0x1, -0x22(%rbp)
jne 0x8247
movq -0x108(%rbp), %rdi
callq 0x3190
movq -0x110(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x108(%rbp), %rdi
callq 0x3190
movq -0x30(%rbp), %rdi
callq 0x3430
nopl (%rax)