// File: 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
subq $0x3e0, %rsp            # imm = 0x3E0
movq %rdi, -0x358(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x33b0
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x1c(%rbp)
jne 0xe4a2
movq -0x358(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x368(%rbp)
callq 0x3110
movq -0x368(%rbp), %rdi
callq 0x3800
movb %al, -0x359(%rbp)
jmp 0xdafb
leaq -0x40(%rbp), %rdi
callq 0x3190
movb -0x359(%rbp), %al
testb $0x1, %al
jne 0xdb13
jmp 0xe4a0
movq -0x358(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x378(%rbp)
callq 0x3110
movq -0x378(%rbp), %rdi
callq 0x3970
movl %eax, -0x36c(%rbp)
jmp 0xdb3e
leaq -0x70(%rbp), %rdi
callq 0x3190
movl -0x36c(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x1, -0x50(%rbp)
je 0xdb66
cmpl $0x3, -0x50(%rbp)
je 0xdb66
cmpl $0x5, -0x50(%rbp)
jne 0xe49e
leaq -0x91(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x3440
movq -0x380(%rbp), %rdx
leaq 0x767b(%rip), %rsi      # 0x15202
leaq -0x90(%rbp), %rdi
callq 0x50d0
jmp 0xdb95
leaq -0x91(%rbp), %rdi
callq 0x32f0
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x388(%rbp)
callq 0x3440
movq -0x388(%rbp), %rdx
leaq 0x7640(%rip), %rsi      # 0x15202
leaq -0xb8(%rbp), %rdi
callq 0x50d0
jmp 0xdbd0
leaq -0xb9(%rbp), %rdi
callq 0x32f0
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x3440
movq -0x390(%rbp), %rdx
leaq 0x7605(%rip), %rsi      # 0x15202
leaq -0xe0(%rbp), %rdi
callq 0x50d0
jmp 0xdc0b
leaq -0xe1(%rbp), %rdi
callq 0x32f0
movq -0x10(%rbp), %rsi
movslq -0x50(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rsi
movb $0x0, -0x129(%rbp)
movb $0x0, -0x151(%rbp)
movb $0x0, -0x179(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3110
jmp 0xdc49
leaq -0x108(%rbp), %rdi
callq 0x3cc0
movb %al, -0x391(%rbp)
jmp 0xdc5d
movb -0x391(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x392(%rbp)
jne 0xdc75
jmp 0xdd52
movq -0x10(%rbp), %rcx
movslq -0x50(%rbp), %rax
shlq $0x5, %rax
leaq 0x20(%rax,%rcx), %rsi
leaq -0x128(%rbp), %rdi
callq 0x3110
jmp 0xdc94
movb $0x1, -0x129(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3cc0
movb %al, -0x393(%rbp)
jmp 0xdcaf
movb -0x393(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x392(%rbp)
jne 0xdcc7
jmp 0xdd52
movq -0x10(%rbp), %rsi
addq $0xa0, %rsi
leaq -0x150(%rbp), %rdi
callq 0x3110
jmp 0xdce0
movb $0x1, -0x151(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x3cc0
movb %al, -0x394(%rbp)
jmp 0xdcfb
movb -0x394(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x392(%rbp)
jne 0xdd10
jmp 0xdd52
movq -0x10(%rbp), %rsi
addq $0xc0, %rsi
leaq -0x178(%rbp), %rdi
callq 0x3110
jmp 0xdd29
movb $0x1, -0x179(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x3cc0
movb %al, -0x395(%rbp)
jmp 0xdd44
movb -0x395(%rbp), %al
movb %al, -0x392(%rbp)
jmp 0xdd52
movb -0x392(%rbp), %al
movb %al, -0x396(%rbp)
testb $0x1, -0x179(%rbp)
jne 0xdd69
jmp 0xdd75
leaq -0x178(%rbp), %rdi
callq 0x3190
testb $0x1, -0x151(%rbp)
jne 0xdd80
jmp 0xdd8c
leaq -0x150(%rbp), %rdi
callq 0x3190
testb $0x1, -0x129(%rbp)
jne 0xdd97
jmp 0xdda3
leaq -0x128(%rbp), %rdi
callq 0x3190
leaq -0x108(%rbp), %rdi
callq 0x3190
movb -0x396(%rbp), %al
testb $0x1, %al
jne 0xddbe
jmp 0xe436
movq -0x10(%rbp), %rdx
movslq -0x50(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdx
leaq -0x1c0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xe6b0
jmp 0xdde2
movq -0x10(%rbp), %rdx
movslq -0x50(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdx
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0xe660
jmp 0xde06
leaq -0x90(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movq %rsi, -0x3a0(%rbp)
callq 0x3330
movq -0x3a0(%rbp), %rdi
callq 0x3190
leaq -0x1c0(%rbp), %rdi
callq 0x3190
movq -0x10(%rbp), %rdx
addq $0xa0, %rdx
leaq -0x200(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xe6b0
jmp 0xde58
movq -0x10(%rbp), %rdx
addq $0xc0, %rdx
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0xe660
jmp 0xde78
leaq -0xb8(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
movq %rsi, -0x3a8(%rbp)
callq 0x3330
movq -0x3a8(%rbp), %rdi
callq 0x3190
leaq -0x200(%rbp), %rdi
callq 0x3190
movq -0x358(%rbp), %rsi
movl $0x0, -0x224(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x3110
jmp 0xdec9
leaq -0x248(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x7a50
jmp 0xdede
leaq -0x248(%rbp), %rdi
callq 0x3190
movq -0x358(%rbp), %rsi
leaq -0x268(%rbp), %rdi
callq 0x3110
jmp 0xdeff
leaq -0x268(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x7a50
jmp 0xdf14
leaq -0x268(%rbp), %rdi
callq 0x3190
movl $0x3, -0x26c(%rbp)
cmpl $0x0, -0x26c(%rbp)
jl 0xe35f
movslq -0x26c(%rbp), %rax
movl -0x210(%rbp,%rax,4), %eax
movslq -0x26c(%rbp), %rcx
addl -0x220(%rbp,%rcx,4), %eax
addl -0x224(%rbp), %eax
movl %eax, -0x270(%rbp)
cmpl $0x10, -0x270(%rbp)
jl 0xe11a
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
jmp 0xe121
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3190
jmp 0xe4ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3190
jmp 0xe4ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x32f0
jmp 0xe4ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb9(%rbp), %rdi
callq 0x32f0
jmp 0xe490
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0x32f0
jmp 0xe484
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xe478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xe095
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xe07c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xe063
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
testb $0x1, -0x179(%rbp)
jne 0xe055
jmp 0xe061
leaq -0x178(%rbp), %rdi
callq 0x3190
jmp 0xe063
testb $0x1, -0x151(%rbp)
jne 0xe06e
jmp 0xe07a
leaq -0x150(%rbp), %rdi
callq 0x3190
jmp 0xe07c
testb $0x1, -0x129(%rbp)
jne 0xe087
jmp 0xe093
leaq -0x128(%rbp), %rdi
callq 0x3190
jmp 0xe095
leaq -0x108(%rbp), %rdi
callq 0x3190
jmp 0xe478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x3190
jmp 0xe478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x3190
jmp 0xe478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x3190
jmp 0xe478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x3190
jmp 0xe478
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movl -0x270(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, -0x224(%rbp)
movl -0x270(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x270(%rbp)
cmpl $0x0, -0x270(%rbp)
jl 0xe1a0
cmpl $0x9, -0x270(%rbp)
jg 0xe1a0
movl -0x270(%rbp), %eax
addl $0x30, %eax
movsbl %al, %esi
leaq -0x290(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0x84f0
jmp 0xe17c
leaq -0xe0(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x3330
leaq -0x290(%rbp), %rdi
callq 0x3190
jmp 0xe349
movl -0x270(%rbp), %eax
addl $-0xa, %eax
movl %eax, %ecx
movq %rcx, -0x3b0(%rbp)
subl $0x5, %eax
ja 0xe347
movq -0x3b0(%rbp), %rax
leaq 0x7007(%rip), %rcx      # 0x151d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x6e89(%rip), %rsi      # 0x15062
leaq -0x2b0(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0xe8c0
jmp 0xe1ee
leaq -0xe0(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0x3330
leaq -0x2b0(%rbp), %rdi
callq 0x3190
jmp 0xe347
leaq 0x6e07(%rip), %rsi      # 0x15020
leaq -0x2d0(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0xe8c0
jmp 0xe22e
leaq -0xe0(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x3330
leaq -0x2d0(%rbp), %rdi
callq 0x3190
jmp 0xe347
leaq 0x6dbb(%rip), %rsi      # 0x15014
leaq -0x2f0(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0xe8c0
jmp 0xe26e
leaq -0xe0(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x3330
leaq -0x2f0(%rbp), %rdi
callq 0x3190
jmp 0xe347
leaq 0x6d9b(%rip), %rsi      # 0x15034
leaq -0x310(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0xe8c0
jmp 0xe2ae
leaq -0xe0(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x3330
leaq -0x310(%rbp), %rdi
callq 0x3190
jmp 0xe347
leaq 0x6d2e(%rip), %rsi      # 0x15004
leaq -0x330(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0xe8c0
jmp 0xe2eb
leaq -0xe0(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x3330
leaq -0x330(%rbp), %rdi
callq 0x3190
jmp 0xe347
leaq 0x6edd(%rip), %rsi      # 0x151f0
leaq -0x350(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0xe8c0
jmp 0xe328
leaq -0xe0(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x3330
leaq -0x350(%rbp), %rdi
callq 0x3190
jmp 0xe349
jmp 0xe34b
movl -0x26c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x26c(%rbp)
jmp 0xdf2a
xorl %eax, %eax
movl %eax, %esi
leaq -0xe0(%rbp), %rdi
callq 0x34a0
movq %rax, -0x3b8(%rbp)
jmp 0xe378
movq -0x3b8(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x3c4(%rbp)
leaq -0xe0(%rbp), %rdi
movl $0x1, %esi
callq 0x34a0
movq %rax, -0x3c0(%rbp)
jmp 0xe3a2
movl -0x3c4(%rbp), %eax
movq -0x3c0(%rbp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rdi
addq $0xa0, %rdi
movsbl %al, %esi
callq 0x3400
jmp 0xe3c9
leaq -0xe0(%rbp), %rdi
movl $0x2, %esi
callq 0x34a0
movq %rax, -0x3d0(%rbp)
jmp 0xe3e3
movq -0x3d0(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x3dc(%rbp)
leaq -0xe0(%rbp), %rdi
movl $0x3, %esi
callq 0x34a0
movq %rax, -0x3d8(%rbp)
jmp 0xe40d
movl -0x3dc(%rbp), %eax
movq -0x3d8(%rbp), %rcx
movzbl (%rcx), %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rdi
addq $0xc0, %rdi
movsbl %al, %esi
callq 0x3400
jmp 0xe434
jmp 0xe452
movq 0xcb93(%rip), %rdi      # 0x1afd0
leaq 0x6db6(%rip), %rsi      # 0x151fa
callq 0x3270
jmp 0xe44b
xorl %edi, %edi
callq 0x3320
leaq -0xe0(%rbp), %rdi
callq 0x3190
leaq -0xb8(%rbp), %rdi
callq 0x3190
leaq -0x90(%rbp), %rdi
callq 0x3190
jmp 0xe49e
leaq -0xe0(%rbp), %rdi
callq 0x3190
leaq -0xb8(%rbp), %rdi
callq 0x3190
leaq -0x90(%rbp), %rdi
callq 0x3190
jmp 0xe4ab
jmp 0xe4a0
jmp 0xe4a2
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3430
nopw %cs:(%rax,%rax)