// File: /workspace/github_cpp_makefile_star2_O1/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, -0xf0(%rbp)
movq %rsi, -0x30(%rbp)
movq 0x8(%rdi), %rdx
cmpl $0x1, %edx
jne 0x9e74
movq %rdi, %r15
leaq -0x1e0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rdi), %rsi
addq %rsi, %rdx
leaq -0x1f0(%rbp), %r12
movq %r12, %rdi
callq 0x3224
movq %r12, %rdi
callq 0x265c
movl %eax, %r12d
movq -0x1f0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9821
movq -0x1e0(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r12b, %r12b
je 0x9e74
leaq -0x1c0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x1d0(%rbp), %r12
movq %r12, %rdi
callq 0x3224
movq %r12, %rdi
callq 0x2778
movl %eax, %r12d
movq -0x1d0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9874
movq -0x1c0(%rbp), %rsi
incq %rsi
callq 0x2210
cmpl $0x5, %r12d
ja 0x9e74
movl $0x2a, %eax
btl %r12d, %eax
jae 0x9e74
leaq -0xd0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x4963(%rip), %rdx      # 0xe202
leaq -0xe0(%rbp), %rdi
movq %rdx, %rsi
callq 0x32be
leaq -0xb0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x4942(%rip), %rdx      # 0xe202
leaq -0xc0(%rbp), %rdi
movq %rdx, %rsi
callq 0x32be
leaq -0x90(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x4921(%rip), %rdx      # 0xe202
leaq -0xa0(%rbp), %rdi
movq %rdx, %rsi
callq 0x32be
movl %r12d, %r12d
shlq $0x5, %r12
leaq -0x1a0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x30(%rbp), %rax
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0x1b0(%rbp), %rdi
callq 0x3224
leaq -0x1b0(%rbp), %rdi
callq 0x294d
movb %al, -0x58(%rbp)
addq -0x30(%rbp), %r12
cmpb $0x0, -0x58(%rbp)
je 0x99f5
leaq -0x180(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
addq %rsi, %rdx
leaq -0x190(%rbp), %rdi
callq 0x3224
leaq -0x190(%rbp), %rdi
callq 0x294d
testb %al, %al
je 0x99f5
leaq -0x120(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x30(%rbp), %rax
movq 0xa0(%rax), %rsi
movq 0xa8(%rax), %rdx
addq %rsi, %rdx
leaq -0x130(%rbp), %rdi
callq 0x3224
leaq -0x130(%rbp), %rdi
callq 0x294d
testb %al, %al
je 0x9e86
leaq -0x100(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x30(%rbp), %rax
movq 0xc0(%rax), %rsi
movq 0xc8(%rax), %rdx
addq %rsi, %rdx
leaq -0x110(%rbp), %rdi
callq 0x3224
leaq -0x110(%rbp), %rdi
callq 0x294d
movl %eax, %r13d
movb $0x1, %r14b
movb $0x1, %al
jmp 0x99fd
xorl %r14d, %r14d
xorl %eax, %eax
xorl %r13d, %r13d
testb %al, %al
je 0x9a20
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9a20
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r14b, %r14b
je 0x9a44
leaq -0x120(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9a44
movq -0x120(%rbp), %rsi
incq %rsi
callq 0x2210
cmpb $0x0, -0x58(%rbp)
je 0x9a69
leaq -0x180(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9a69
movq -0x180(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x1b0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9a84
movq -0x1a0(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r13b, %r13b
je 0x9e8e
leaq -0x80(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movq %r12, %rdx
callq 0xa216
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq -0x80(%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 0x9ad6
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x9add
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 -0xe0(%rbp), %rdi
movq %r12, %rsi
callq 0x2270
movq (%r12), %rdi
cmpq %r14, %rdi
je 0x9b1d
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x70(%rbp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
movq -0x30(%rbp), %r12
je 0x9b3a
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2210
leaq 0xa0(%r12), %r13
leaq -0x80(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movq %r13, %rdx
callq 0xa216
movq 0xc0(%r12), %rsi
movq 0xc8(%r12), %rdx
leaq -0x80(%rbp), %rdi
callq 0x20b0
movq %r14, -0x50(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq %r13, -0x58(%rbp)
je 0x9b92
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x9b99
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 -0xc0(%rbp), %rdi
movq %r13, %rsi
callq 0x2270
movq (%r13), %rdi
cmpq %r14, %rdi
je 0x9bd8
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x80(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9bed
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x160(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x170(%rbp), %rdi
callq 0x3224
leaq -0x170(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x475e
movq -0x170(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9c39
movq -0x160(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x140(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x150(%rbp), %rdi
callq 0x3224
leaq -0x150(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x475e
movq -0x150(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9c88
movq -0x140(%rbp), %rsi
incq %rsi
callq 0x2210
leaq 0xc0(%r12), %rax
movq %rax, -0xe8(%rbp)
xorl %r12d, %r12d
movl $0x3, %ebx
leaq -0xa0(%rbp), %r15
movl -0x200(%rbp,%rbx,4), %ecx
addl -0x80(%rbp,%rbx,4), %r12d
leal (%r12,%rcx), %eax
cmpl $0x10, %eax
movq -0xf0(%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 0x9d1c
orb $0x30, %al
movsbl %al, %esi
movq %r13, %rdi
movq %r15, %rdx
callq 0x4c11
movq %r15, %rdi
movq %r13, %rsi
callq 0x2270
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x9d0d
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
sarl $0x4, %r12d
addq $-0x1, %rbx
jb 0x9ca6
jmp 0x9db8
addl $-0xa, %eax
cmpl $0x5, %eax
ja 0x9d0d
leaq 0x44a5(%rip), %rcx      # 0xe1d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, %rdi
leaq 0x4324(%rip), %rsi      # 0xe062
movq %r15, %rdx
callq 0xa2f9
jmp 0x9ced
movq %r13, %rdi
leaq 0x42b2(%rip), %rsi      # 0xe004
movq %r15, %rdx
callq 0xa2f9
jmp 0x9ced
movq %r13, %rdi
leaq 0x42ae(%rip), %rsi      # 0xe014
movq %r15, %rdx
callq 0xa2f9
jmp 0x9ced
movq %r13, %rdi
leaq 0x42b7(%rip), %rsi      # 0xe034
movq %r15, %rdx
callq 0xa2f9
jmp 0x9ced
movq %r13, %rdi
leaq 0x428c(%rip), %rsi      # 0xe020
movq %r15, %rdx
callq 0xa2f9
jmp 0x9ced
movq %r13, %rdi
leaq 0x4445(%rip), %rsi      # 0xe1f0
movq %r15, %rdx
callq 0xa2f9
jmp 0x9ced
movq -0xa0(%rbp), %rax
movb 0x1(%rax), %cl
addb (%rax), %cl
movq -0x30(%rbp), %rbx
movq 0xa8(%rbx), %rdx
movsbl %cl, %r8d
movl $0x1, %ecx
movq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x2360
movq -0xa0(%rbp), %rax
movb 0x3(%rax), %cl
addb 0x2(%rax), %cl
movq 0xc8(%rbx), %rdx
movsbl %cl, %r8d
movl $0x1, %ecx
movq -0xe8(%rbp), %rdi
xorl %esi, %esi
callq 0x2360
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x9e30
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x9e52
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x9e74
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2210
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %r14b
jmp 0x99f8
movq 0x813b(%rip), %rdi      # 0x11fd0
leaq 0x435e(%rip), %rsi      # 0xe1fa
callq 0x21f0
xorl %edi, %edi
callq 0x2260
movq %rax, %r15
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x9ed2
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x9ed2
movq %rax, %r15
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
cmpq %rax, %rdi
je 0x9ef9
movq -0x120(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x9ef9
movq %rax, %r15
movq -0x190(%rbp), %rdi
cmpq %r14, %rdi
je 0x9fc4
movq -0x180(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x9fc4
movq %rax, %r15
movq -0x150(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa00c
movq -0x140(%rbp), %rsi
jmp 0x9fd7
movq %rax, %r15
movq -0x170(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa00c
movq -0x160(%rbp), %rsi
jmp 0x9fd7
movq %rax, %r15
movq -0x80(%rbp), %rdi
cmpq %rbx, %rdi
jne 0x9f82
jmp 0xa00c
jmp 0xa009
movq %rax, %r15
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa00c
movq -0x70(%rbp), %rsi
jmp 0x9fd7
jmp 0xa009
movq %rax, %r15
jmp 0xa02e
movq %rax, %r15
jmp 0xa050
movq %rax, %r15
jmp 0xa072
movq %rax, %r15
movq -0x1d0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa072
movq -0x1c0(%rbp), %rsi
jmp 0xa06a
movq %rax, %r15
movq -0x1b0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa00c
movq -0x1a0(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0xa00c
jmp 0xa009
jmp 0xa009
jmp 0xa009
jmp 0xa009
jmp 0xa009
jmp 0xa009
jmp 0xa009
movq %rax, %r15
movq -0x1f0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa072
movq -0x1e0(%rbp), %rsi
jmp 0xa06a
jmp 0xa009
movq %rax, %r15
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0xa02e
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0xa050
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0xa072
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2210
movq %r15, %rdi
callq 0x2320