// File: /workspace/github_cpp_makefile_star2_O3/sthapliyal37[P]Microprocessor_8085_Updated/arithmetic.cpp
// Function: DAD(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*)
void DAD(string instruction,string* registers,bool* flag)
{
	int length = instruction.length();
	if(length == 1){
	
		if(validityRegisters(instruction)){
		
			int registerID = registerNumber(instruction);
			if(registerID == 1 || registerID == 3 || registerID == 5){
				
				string data16bit = "";
				string data16bitHL = "";
				string resultant = "";
				if(validityData(registers[registerID]) && validityData(registers[registerID+1]) && validityData(registers[5]) && validityData(registers[6])){
				
					data16bit = data16bit + registers[registerID] + registers[registerID];
					data16bitHL = data16bitHL + registers[5] + registers[6];
					int value16bit[4];
					int value16bitHL[4];
					int carry = 0;
					hexToDecimal(instruction,value16bit);
					hexToDecimal(instruction,value16bitHL);	  
					for(int i = 3;i>=0;i--){
					
						int value = value16bit[i] + value16bitHL[i] + carry;
						if(value >= 16)
							flag[0] = true;
						else
							flag[0] = false;
						carry = value / 16;
						value = value % 16;
						if(value>=0 && value<=9)
							resultant = (char)('0' + value) + resultant;
						else{
							switch(value){
							
								case 10:
									resultant = "A" + resultant;
									break;
								case 11:
									resultant = "B" + resultant;
									break;
								case 12:
									resultant = "C" + resultant;
									break;
								case 13:
									resultant = "D" + resultant;
									break;
								case 14:
									resultant = "E" + resultant;
									break;
								case 15:
									resultant = "F" + resultant;
									break;	
							}
						}
					}
					
					registers[5] = resultant[0] + resultant[1];
					registers[6] = resultant[2] + resultant[3];	
				}		
				else{
					cout<<"Error: \n";
					exit(0);
				}
			}

			}
		}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdx, -0x128(%rbp)
movq 0x8(%rdi), %rdx
cmpl $0x1, %edx
jne 0x9dec
movq %rsi, %r14
movq %rdi, %r15
leaq -0x1d8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rdi), %rsi
addq %rsi, %rdx
leaq -0x1e8(%rbp), %r12
movq %r12, %rdi
callq 0x31ec
movq %r12, %rdi
callq 0x265c
movl %eax, %r12d
movq -0x1e8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x97b1
movq -0x1d8(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r12b, %r12b
je 0x9dec
leaq -0x1b8(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x1c8(%rbp), %r12
movq %r12, %rdi
callq 0x31ec
movq %r12, %rdi
callq 0x2778
movl %eax, %r12d
movq -0x1c8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9804
movq -0x1b8(%rbp), %rsi
incq %rsi
callq 0x2210
cmpl $0x5, %r12d
ja 0x9dec
movl $0x2a, %eax
btl %r12d, %eax
jae 0x9dec
leaq -0xc0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x49d3(%rip), %rdx      # 0xe202
leaq -0xd0(%rbp), %rdi
movq %rdx, %rsi
callq 0x328a
leaq -0xa0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x49b2(%rip), %rdx      # 0xe202
leaq -0xb0(%rbp), %rdi
movq %rdx, %rsi
callq 0x328a
movq %r14, -0x30(%rbp)
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x4990(%rip), %rdx      # 0xe202
leaq -0x90(%rbp), %rdi
movq %rdx, %rsi
callq 0x328a
movl %r12d, %r12d
shlq $0x5, %r12
leaq -0x198(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x30(%rbp), %rax
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x31ec
leaq -0x1a8(%rbp), %rdi
callq 0x294d
addq -0x30(%rbp), %r12
testb %al, %al
je 0x999a
leaq -0x178(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
addq %rsi, %rdx
leaq -0x188(%rbp), %rdi
callq 0x31ec
leaq -0x188(%rbp), %rdi
callq 0x294d
testb %al, %al
je 0x999f
leaq -0x100(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x30(%rbp), %rax
movq 0xa0(%rax), %rsi
movq 0xa8(%rax), %rdx
addq %rsi, %rdx
leaq -0x110(%rbp), %rdi
callq 0x31ec
leaq -0x110(%rbp), %rdi
callq 0x294d
testb %al, %al
je 0x99a4
leaq -0xe0(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x30(%rbp), %rax
movq 0xc0(%rax), %rsi
movq 0xc8(%rax), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x31ec
leaq -0xf0(%rbp), %rdi
callq 0x294d
movl %eax, %r13d
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x99a7
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x99a7
xorl %r13d, %r13d
jmp 0x99e4
xorl %r13d, %r13d
jmp 0x99c9
xorl %r13d, %r13d
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x99c9
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x188(%rbp), %rdi
cmpq %rbx, %rdi
je 0x99e4
movq -0x178(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x1a8(%rbp), %rdi
cmpq %r14, %rdi
je 0x99ff
movq -0x198(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r13b, %r13b
movq -0x30(%rbp), %r13
je 0x9dfe
leaq -0x70(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
movq %r12, %rdx
callq 0xa180
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq -0x70(%rbp), %rdi
callq 0x20b0
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9a55
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x9a5c
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0xd0(%rbp), %rdi
movq %r12, %rsi
callq 0x2270
movq (%r12), %rdi
cmpq %r14, %rdi
je 0x9a9c
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x60(%rbp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x9ab5
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
leaq 0xa0(%r13), %rdx
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movq %rdx, -0x120(%rbp)
callq 0xa180
movq 0xc0(%r13), %rsi
movq 0xc8(%r13), %rdx
leaq -0x70(%rbp), %rdi
callq 0x20b0
movq %r14, -0x50(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
movq %r13, %r12
cmpq %rcx, %rdx
je 0x9b0d
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x9b14
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %r13
movq %rdx, 0x8(%r13)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0xb0(%rbp), %rdi
movq %r13, %rsi
callq 0x2270
movq (%r13), %rdi
cmpq %r14, %rdi
je 0x9b53
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9b68
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x158(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x168(%rbp), %rdi
callq 0x31ec
leaq -0x168(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x46ea
movq -0x168(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9bb4
movq -0x158(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x138(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x148(%rbp), %rdi
callq 0x31ec
leaq -0x148(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x46ea
movq -0x148(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9c03
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x2210
leaq 0xc0(%r12), %rax
movq %rax, -0x118(%rbp)
xorl %r12d, %r12d
movl $0x3, %ebx
leaq -0x90(%rbp), %r15
movl -0x200(%rbp,%rbx,4), %ecx
addl -0x70(%rbp,%rbx,4), %r12d
leal (%r12,%rcx), %eax
cmpl $0x10, %eax
movq -0x128(%rbp), %rdx
setge (%rdx)
addl %ecx, %r12d
addl $0xf, %r12d
testl %eax, %eax
cmovnsl %eax, %r12d
movl %r12d, %ecx
andl $-0x10, %ecx
subl %ecx, %eax
cmpl $0x9, %eax
ja 0x9c97
orb $0x30, %al
movsbl %al, %esi
movq %r13, %rdi
movq %r15, %rdx
callq 0x4bc8
movq %r15, %rdi
movq %r13, %rsi
callq 0x2270
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x9c88
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
sarl $0x4, %r12d
addq $-0x1, %rbx
jb 0x9c21
jmp 0x9d33
addl $-0xa, %eax
cmpl $0x5, %eax
ja 0x9c88
leaq 0x452a(%rip), %rcx      # 0xe1d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, %rdi
leaq 0x43a9(%rip), %rsi      # 0xe062
movq %r15, %rdx
callq 0xa263
jmp 0x9c68
movq %r13, %rdi
leaq 0x4337(%rip), %rsi      # 0xe004
movq %r15, %rdx
callq 0xa263
jmp 0x9c68
movq %r13, %rdi
leaq 0x4333(%rip), %rsi      # 0xe014
movq %r15, %rdx
callq 0xa263
jmp 0x9c68
movq %r13, %rdi
leaq 0x433c(%rip), %rsi      # 0xe034
movq %r15, %rdx
callq 0xa263
jmp 0x9c68
movq %r13, %rdi
leaq 0x4311(%rip), %rsi      # 0xe020
movq %r15, %rdx
callq 0xa263
jmp 0x9c68
movq %r13, %rdi
leaq 0x44ca(%rip), %rsi      # 0xe1f0
movq %r15, %rdx
callq 0xa263
jmp 0x9c68
movq -0x90(%rbp), %rax
movb 0x1(%rax), %cl
addb (%rax), %cl
movq -0x30(%rbp), %rbx
movq 0xa8(%rbx), %rdx
movsbl %cl, %r8d
movl $0x1, %ecx
movq -0x120(%rbp), %rdi
xorl %esi, %esi
callq 0x2360
movq -0x90(%rbp), %rax
movb 0x3(%rax), %cl
addb 0x2(%rax), %cl
movq 0xc8(%rbx), %rdx
movsbl %cl, %r8d
movl $0x1, %ecx
movq -0x118(%rbp), %rdi
xorl %esi, %esi
callq 0x2360
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x9da8
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x9dca
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x9dec
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2210
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x81cb(%rip), %rdi      # 0x11fd0
leaq 0x43ee(%rip), %rsi      # 0xe1fa
callq 0x21f0
xorl %edi, %edi
callq 0x2260
movq %rax, %r15
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x9e42
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x9e42
movq %rax, %r15
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x9e69
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x9e69
movq %rax, %r15
movq -0x188(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9f34
movq -0x178(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x9f34
movq %rax, %r15
movq -0x148(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9f7c
movq -0x138(%rbp), %rsi
jmp 0x9f47
movq %rax, %r15
movq -0x168(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9f7c
movq -0x158(%rbp), %rsi
jmp 0x9f47
movq %rax, %r15
movq -0x70(%rbp), %rdi
cmpq %rbx, %rdi
jne 0x9ef2
jmp 0x9f7c
jmp 0x9f79
movq %rax, %r15
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9f7c
movq -0x60(%rbp), %rsi
jmp 0x9f47
jmp 0x9f79
movq %rax, %r15
jmp 0x9f98
movq %rax, %r15
jmp 0x9fba
movq %rax, %r15
jmp 0x9fdc
movq %rax, %r15
movq -0x1c8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9fdc
movq -0x1b8(%rbp), %rsi
jmp 0x9fd4
movq %rax, %r15
movq -0x1a8(%rbp), %rdi
cmpq %r14, %rdi
je 0x9f7c
movq -0x198(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x9f7c
jmp 0x9f79
jmp 0x9f79
jmp 0x9f79
jmp 0x9f79
jmp 0x9f79
jmp 0x9f79
jmp 0x9f79
movq %rax, %r15
movq -0x1e8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9fdc
movq -0x1d8(%rbp), %rsi
jmp 0x9fd4
jmp 0x9f79
movq %rax, %r15
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x9f98
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x9fba
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x9fdc
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2210
movq %r15, %rdi
callq 0x2320