// File: /workspace/github_cpp_makefile_star2_O2/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, -0x68(%rbp)
cmpl $0x1, 0x8(%rdi)
jne 0x6f96
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x200(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x2280
movq %r15, %rdi
callq 0x262c
movl %eax, %r15d
leaq -0x200(%rbp), %rdi
callq 0x20f0
testb %r15b, %r15b
je 0x6f96
leaq -0x1e0(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x2280
movq %r15, %rdi
callq 0x2740
movl %eax, %r15d
leaq -0x1e0(%rbp), %rdi
callq 0x20f0
cmpl $0x5, %r15d
ja 0x6f96
pushq $0x2a
popq %rax
btl %r15d, %eax
jae 0x6f96
leaq 0x35dc(%rip), %rsi      # 0xa202
leaq -0x148(%rbp), %rdi
leaq -0xc8(%rbp), %rdx
callq 0x2f1e
leaq 0x35c2(%rip), %rsi      # 0xa202
leaq -0xc8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x2f1e
leaq 0x35a8(%rip), %rsi      # 0xa202
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x2f1e
movl %r15d, %r15d
shlq $0x5, %r15
addq %rbx, %r15
leaq -0x128(%rbp), %rdi
movq %r15, %rsi
callq 0x2280
leaq -0x128(%rbp), %rdi
callq 0x28cb
testb %al, %al
je 0x6fc0
leaq 0x20(%r15), %rsi
leaq -0x108(%rbp), %rdi
callq 0x2280
leaq -0x108(%rbp), %rdi
callq 0x28cb
testb %al, %al
je 0x6fb4
leaq 0xa0(%rbx), %r14
leaq -0xe8(%rbp), %rdi
movq %r14, %rsi
callq 0x2280
leaq -0xe8(%rbp), %rdi
callq 0x28cb
testb %al, %al
je 0x6fa8
addq $0xc0, %rbx
leaq -0x1c0(%rbp), %rdi
movq %rbx, %rsi
callq 0x2280
leaq -0x1c0(%rbp), %rdi
callq 0x28cb
movl %eax, %r13d
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
leaq -0xe8(%rbp), %rdi
callq 0x20f0
leaq -0x108(%rbp), %rdi
callq 0x20f0
leaq -0x128(%rbp), %rdi
callq 0x20f0
testb %r13b, %r13b
je 0x6fcc
leaq -0x50(%rbp), %rdi
leaq -0x148(%rbp), %rsi
movq %r15, %rdx
callq 0x71f4
leaq -0xa8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %r15, %rdx
callq 0x71cb
leaq -0x148(%rbp), %rdi
leaq -0xa8(%rbp), %r15
movq %r15, %rsi
callq 0x2250
movq %r15, %rdi
callq 0x20f0
leaq -0x50(%rbp), %rdi
callq 0x20f0
leaq -0x50(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
movq %r14, %rdx
callq 0x71f4
leaq -0xa8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %rbx, %rdx
callq 0x71cb
leaq -0xc8(%rbp), %rdi
movq %r15, %rsi
callq 0x2250
movq %r15, %rdi
callq 0x20f0
leaq -0x50(%rbp), %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rdi
movq %r12, %rsi
callq 0x2280
leaq -0x1a0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3d02
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
leaq -0x180(%rbp), %rdi
movq %r12, %rsi
callq 0x2280
movq %r14, -0x58(%rbp)
movq %rbx, -0x60(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x3d02
leaq -0x180(%rbp), %rdi
callq 0x20f0
pushq $0x3
popq %rbx
xorl %r15d, %r15d
pushq $0x10
popq %r14
leaq -0xa8(%rbp), %r12
leaq -0x88(%rbp), %r13
testl %ebx, %ebx
js 0x6f41
movl %ebx, %eax
addl -0x50(%rbp,%rax,4), %r15d
addl -0x160(%rbp,%rax,4), %r15d
cmpl $0x10, %r15d
movq -0x68(%rbp), %rax
setge (%rax)
movl %r15d, %eax
cltd
idivl %r14d
movl %eax, %r15d
cmpl $0x9, %edx
ja 0x6eab
orb $0x30, %dl
movsbl %dl, %esi
movq %r12, %rdi
movq %r13, %rdx
callq 0x4059
movq %r13, %rdi
movq %r12, %rsi
callq 0x2250
movq %r12, %rdi
callq 0x20f0
decl %ebx
jmp 0x6e52
addl $-0xa, %edx
cmpl $0x5, %edx
ja 0x6ea7
leaq 0x3316(%rip), %rcx      # 0xa1d0
movslq (%rcx,%rdx,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, %rdi
leaq 0x3195(%rip), %rsi      # 0xa062
movq %r13, %rdx
callq 0x72e1
jmp 0x6e94
movq %r12, %rdi
leaq 0x3123(%rip), %rsi      # 0xa004
movq %r13, %rdx
callq 0x72e1
jmp 0x6e94
movq %r12, %rdi
leaq 0x311f(%rip), %rsi      # 0xa014
movq %r13, %rdx
callq 0x72e1
jmp 0x6e94
movq %r12, %rdi
leaq 0x312b(%rip), %rsi      # 0xa034
movq %r13, %rdx
callq 0x72e1
jmp 0x6e94
movq %r12, %rdi
leaq 0x3103(%rip), %rsi      # 0xa020
movq %r13, %rdx
callq 0x72e1
jmp 0x6e94
movq %r12, %rdi
leaq 0x32bc(%rip), %rsi      # 0xa1f0
movq %r13, %rdx
callq 0x72e1
jmp 0x6e94
movq -0x88(%rbp), %rax
movb 0x1(%rax), %cl
addb (%rax), %cl
movsbl %cl, %esi
movq -0x58(%rbp), %rdi
callq 0x22f0
movq -0x60(%rbp), %rdi
movq -0x88(%rbp), %rax
movb 0x3(%rax), %cl
addb 0x2(%rax), %cl
movsbl %cl, %esi
callq 0x22f0
leaq -0x88(%rbp), %rdi
callq 0x20f0
leaq -0xc8(%rbp), %rdi
callq 0x20f0
leaq -0x148(%rbp), %rdi
callq 0x20f0
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0xe8(%rbp), %rdi
callq 0x20f0
leaq -0x108(%rbp), %rdi
callq 0x20f0
leaq -0x128(%rbp), %rdi
callq 0x20f0
movq 0x6ffd(%rip), %rdi      # 0xdfd0
leaq 0x3220(%rip), %rsi      # 0xa1fa
callq 0x21e0
xorl %edi, %edi
callq 0x2240
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
jmp 0x706b
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
jmp 0x706b
jmp 0x7005
jmp 0x708e
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x706b
jmp 0x708e
movq %rax, %rbx
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
jmp 0x7042
movq %rax, %rbx
jmp 0x709d
movq %rax, %rbx
jmp 0x70a9
movq %rax, %rbx
jmp 0x70b5
movq %rax, %rbx
leaq -0x1e0(%rbp), %rdi
jmp 0x70b0
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x20f0
jmp 0x7053
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x20f0
jmp 0x7064
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x20f0
jmp 0x7091
jmp 0x708e
jmp 0x708e
jmp 0x708e
jmp 0x708e
jmp 0x708e
jmp 0x708e
movq %rax, %rbx
leaq -0x200(%rbp), %rdi
jmp 0x70b0
jmp 0x708e
jmp 0x708e
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x20f0
leaq -0xc8(%rbp), %rdi
callq 0x20f0
leaq -0x148(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310