// File: zerolfx[P]P-Machine/ldc.cpp
// Function: Ldc::execute(StackMachine*)
void Ldc::execute(StackMachine *stack)
{
	switch(fType)
	{
		case integer:
		{
			StackInteger p1;

			// check if constant is of type integer
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type integer.");
			}
			else
			{
				stack->fStore.push_back(new StackInteger(*(dynamic_cast<StackInteger*>(fConstant))));
			}
				
			break;
		}	
		case real:
		{
			StackReal p1;
			// check if constant is of type real
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type real.");
			}
			else
			{
				stack->fStore.push_back(new StackReal(*(dynamic_cast<StackReal*>(fConstant))));
			}

			break;
		}
		case boolean:
		{
			StackBoolean p1;
			
			// check if constant is of type boolean
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type boolean.");
			}
			else
			{
				stack->fStore.push_back(new StackBoolean(*(dynamic_cast<StackBoolean*>(fConstant))));
			}

			break;
		}
		case character:
		{
			StackCharacter p1;
			
			// check if constant is of type character
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type character.");
			}
			else
			{
				stack->fStore.push_back(new StackCharacter(*(dynamic_cast<StackCharacter*>(fConstant))));
			}

			break;
		}
		case address:
		{
			StackAddress p1;

			// check if constant is of type address
			
			if(typeid(p1) != typeid(*fConstant))
			{
				throw ExecutionError("instruction ldc: type of constant is not of type address.");
			}
			else
			{
				stack->fStore.push_back(new StackAddress(*(dynamic_cast<StackAddress*>(fConstant))));
			}

			break;
		}
	}
	
	// fSP = fSP + 1
	++stack->fSP;
	
	// adding cost of this instruction
	stack->fTime.count("ldc");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x198(%rbp)
movl 0x8(%rax), %eax
movq %rax, -0x190(%rbp)
subq $0x4, %rax
ja 0x14b6d
movq -0x190(%rbp), %rax
leaq 0x244bc(%rip), %rcx     # 0x3867c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x27340
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x1a0(%rbp)
cmpq $0x0, %rax
jne 0x141f3
callq 0x7300
jmp 0x141f3
movq -0x1a0(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x368e8(%rip), %rdi     # 0x4aaf0
callq 0x9370
testb $0x1, %al
jne 0x14216
jmp 0x142df
movb $0x1, -0x52(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x1b0(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x74f0
movq -0x1a8(%rbp), %rdx
leaq 0x2444c(%rip), %rsi     # 0x38695
leaq -0x50(%rbp), %rdi
callq 0x8940
jmp 0x14254
movq -0x1b0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x283d0
jmp 0x14266
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x52(%rbp)
leaq 0x35808(%rip), %rsi     # 0x49a80
leaq 0x14181(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x14c2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x1438b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x142bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x7170
leaq -0x51(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x52(%rbp)
jne 0x142ce
jmp 0x142da
movq -0x1b0(%rbp), %rdi
callq 0x71c0
jmp 0x1438b
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x1c0(%rbp)
movl $0x10, %edi
callq 0x7270
movq %rax, -0x1b8(%rbp)
jmp 0x14301
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, %rax
je 0x14340
movq -0x1c8(%rbp), %rdi
leaq 0x36701(%rip), %rsi     # 0x4aa28
leaq 0x367c2(%rip), %rdx     # 0x4aaf0
xorl %eax, %eax
movl %eax, %ecx
callq 0x7320
movq %rax, -0x1d0(%rbp)
jmp 0x1434b
xorl %eax, %eax
movq %rax, -0x1d0(%rbp)
jmp 0x1434b
movq -0x1b8(%rbp), %rdi
movq -0x1d0(%rbp), %rsi
callq 0xd2d0
movq -0x1b8(%rbp), %rax
movq -0x1c0(%rbp), %rdi
movq %rax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0xd2a0
jmp 0x1437b
jmp 0x1437d
leaq -0x20(%rbp), %rdi
callq 0x27380
jmp 0x14b6d
leaq -0x20(%rbp), %rdi
callq 0x27380
jmp 0x14c25
leaq -0x70(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x27840
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x1d8(%rbp)
cmpq $0x0, %rax
jne 0x143c4
callq 0x7300
jmp 0x143c4
movq -0x1d8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x367e7(%rip), %rdi     # 0x4abc0
callq 0x9370
testb $0x1, %al
jne 0x143e7
jmp 0x144c8
movb $0x1, -0x92(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x1e8(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x74f0
movq -0x1e0(%rbp), %rdx
leaq 0x242af(%rip), %rsi     # 0x386cf
leaq -0x90(%rbp), %rdi
callq 0x8940
jmp 0x1442e
movq -0x1e8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x283d0
jmp 0x14443
movq -0x1e8(%rbp), %rdi
movb $0x0, -0x92(%rbp)
leaq 0x35628(%rip), %rsi     # 0x49a80
leaq 0x13fa1(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x14c2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x1457a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x144a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x7170
leaq -0x91(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x92(%rbp)
jne 0x144b7
jmp 0x144c3
movq -0x1e8(%rbp), %rdi
callq 0x71c0
jmp 0x1457a
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x1f8(%rbp)
movl $0x10, %edi
callq 0x7270
movq %rax, -0x1f0(%rbp)
jmp 0x144ea
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x200(%rbp)
cmpq $0x0, %rax
je 0x14529
movq -0x200(%rbp), %rdi
leaq 0x36518(%rip), %rsi     # 0x4aa28
leaq 0x366a9(%rip), %rdx     # 0x4abc0
xorl %eax, %eax
movl %eax, %ecx
callq 0x7320
movq %rax, -0x208(%rbp)
jmp 0x14534
xorl %eax, %eax
movq %rax, -0x208(%rbp)
jmp 0x14534
movq -0x1f0(%rbp), %rdi
movq -0x208(%rbp), %rsi
callq 0xd320
movq -0x1f0(%rbp), %rax
movq -0x1f8(%rbp), %rdi
movq %rax, -0xa0(%rbp)
leaq -0xa0(%rbp), %rsi
callq 0xd2a0
jmp 0x1456a
jmp 0x1456c
leaq -0x70(%rbp), %rdi
callq 0x27880
jmp 0x14b6d
leaq -0x70(%rbp), %rdi
callq 0x27880
jmp 0x14c25
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x27d20
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x210(%rbp)
cmpq $0x0, %rax
jne 0x145b5
callq 0x7300
jmp 0x145b5
movq -0x210(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x366c6(%rip), %rdi     # 0x4ac90
callq 0x9370
testb $0x1, %al
jne 0x145d8
jmp 0x146b9
movb $0x1, -0xd2(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x220(%rbp)
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x74f0
movq -0x218(%rbp), %rdx
leaq 0x240f5(%rip), %rsi     # 0x38706
leaq -0xd0(%rbp), %rdi
callq 0x8940
jmp 0x1461f
movq -0x220(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x283d0
jmp 0x14634
movq -0x220(%rbp), %rdi
movb $0x0, -0xd2(%rbp)
leaq 0x35437(%rip), %rsi     # 0x49a80
leaq 0x13db0(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x14c2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x1476e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x14691
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x7170
leaq -0xd1(%rbp), %rdi
callq 0x72e0
testb $0x1, -0xd2(%rbp)
jne 0x146a8
jmp 0x146b4
movq -0x220(%rbp), %rdi
callq 0x71c0
jmp 0x1476e
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x230(%rbp)
movl $0x10, %edi
callq 0x7270
movq %rax, -0x228(%rbp)
jmp 0x146db
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x238(%rbp)
cmpq $0x0, %rax
je 0x1471a
movq -0x238(%rbp), %rdi
leaq 0x36327(%rip), %rsi     # 0x4aa28
leaq 0x36588(%rip), %rdx     # 0x4ac90
xorl %eax, %eax
movl %eax, %ecx
callq 0x7320
movq %rax, -0x240(%rbp)
jmp 0x14725
xorl %eax, %eax
movq %rax, -0x240(%rbp)
jmp 0x14725
movq -0x228(%rbp), %rdi
movq -0x240(%rbp), %rsi
callq 0xd370
movq -0x228(%rbp), %rax
movq -0x230(%rbp), %rdi
movq %rax, -0xe0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0xd2a0
jmp 0x1475b
jmp 0x1475d
leaq -0xb0(%rbp), %rdi
callq 0x27d70
jmp 0x14b6d
leaq -0xb0(%rbp), %rdi
callq 0x27d70
jmp 0x14c25
leaq -0xf0(%rbp), %rdi
movl $0x61, %esi
callq 0x28170
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x248(%rbp)
cmpq $0x0, %rax
jne 0x147af
callq 0x7300
jmp 0x147af
movq -0x248(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x3659c(%rip), %rdi     # 0x4ad60
callq 0x9370
testb $0x1, %al
jne 0x147d2
jmp 0x148b3
movb $0x1, -0x112(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x258(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x74f0
movq -0x250(%rbp), %rdx
leaq 0x23f35(%rip), %rsi     # 0x38740
leaq -0x110(%rbp), %rdi
callq 0x8940
jmp 0x14819
movq -0x258(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x283d0
jmp 0x1482e
movq -0x258(%rbp), %rdi
movb $0x0, -0x112(%rbp)
leaq 0x3523d(%rip), %rsi     # 0x49a80
leaq 0x13bb6(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x14c2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x14968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x1488b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x7170
leaq -0x111(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x112(%rbp)
jne 0x148a2
jmp 0x148ae
movq -0x258(%rbp), %rdi
callq 0x71c0
jmp 0x14968
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x268(%rbp)
movl $0x10, %edi
callq 0x7270
movq %rax, -0x260(%rbp)
jmp 0x148d5
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x270(%rbp)
cmpq $0x0, %rax
je 0x14914
movq -0x270(%rbp), %rdi
leaq 0x3612d(%rip), %rsi     # 0x4aa28
leaq 0x3645e(%rip), %rdx     # 0x4ad60
xorl %eax, %eax
movl %eax, %ecx
callq 0x7320
movq %rax, -0x278(%rbp)
jmp 0x1491f
xorl %eax, %eax
movq %rax, -0x278(%rbp)
jmp 0x1491f
movq -0x260(%rbp), %rdi
movq -0x278(%rbp), %rsi
callq 0xd3c0
movq -0x260(%rbp), %rax
movq -0x268(%rbp), %rdi
movq %rax, -0x120(%rbp)
leaq -0x120(%rbp), %rsi
callq 0xd2a0
jmp 0x14955
jmp 0x14957
leaq -0xf0(%rbp), %rdi
callq 0x281b0
jmp 0x14b6d
leaq -0xf0(%rbp), %rdi
callq 0x281b0
jmp 0x14c25
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
callq 0x26800
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x280(%rbp)
cmpq $0x0, %rax
jne 0x149a6
callq 0x7300
jmp 0x149a6
movq -0x280(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x35f9d(%rip), %rdi     # 0x4a958
callq 0x9370
testb $0x1, %al
jne 0x149c9
jmp 0x14aaa
movb $0x1, -0x152(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x290(%rbp)
leaq -0x151(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x74f0
movq -0x288(%rbp), %rdx
leaq 0x23d7a(%rip), %rsi     # 0x3877c
leaq -0x150(%rbp), %rdi
callq 0x8940
jmp 0x14a10
movq -0x290(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x283d0
jmp 0x14a25
movq -0x290(%rbp), %rdi
movb $0x0, -0x152(%rbp)
leaq 0x35046(%rip), %rsi     # 0x49a80
leaq 0x139bf(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x14c2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x14b5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x14a82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x7170
leaq -0x151(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x152(%rbp)
jne 0x14a99
jmp 0x14aa5
movq -0x290(%rbp), %rdi
callq 0x71c0
jmp 0x14b5c
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x2a0(%rbp)
movl $0x10, %edi
callq 0x7270
movq %rax, -0x298(%rbp)
jmp 0x14acc
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x2a8(%rbp)
cmpq $0x0, %rax
je 0x14b0b
movq -0x2a8(%rbp), %rdi
leaq 0x35f36(%rip), %rsi     # 0x4aa28
leaq 0x35e5f(%rip), %rdx     # 0x4a958
xorl %eax, %eax
movl %eax, %ecx
callq 0x7320
movq %rax, -0x2b0(%rbp)
jmp 0x14b16
xorl %eax, %eax
movq %rax, -0x2b0(%rbp)
jmp 0x14b16
movq -0x298(%rbp), %rdi
movq -0x2b0(%rbp), %rsi
callq 0xd410
movq -0x298(%rbp), %rax
movq -0x2a0(%rbp), %rdi
movq %rax, -0x160(%rbp)
leaq -0x160(%rbp), %rsi
callq 0xd2a0
jmp 0x14b4c
jmp 0x14b4e
leaq -0x130(%rbp), %rdi
callq 0x26840
jmp 0x14b6d
leaq -0x130(%rbp), %rdi
callq 0x26840
jmp 0x14c25
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %ecx
incl %ecx
movl %ecx, 0xb4(%rax)
movq -0x10(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x2c0(%rbp)
leaq -0x181(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x74f0
movq -0x2b8(%rbp), %rdx
leaq 0x23c07(%rip), %rsi     # 0x387b6
leaq -0x180(%rbp), %rdi
callq 0x8940
jmp 0x14bbd
movq -0x2c0(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x2c4d0
jmp 0x14bd2
leaq -0x180(%rbp), %rdi
callq 0x7170
leaq -0x181(%rbp), %rdi
callq 0x72e0
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x14c19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x7170
leaq -0x181(%rbp), %rdi
callq 0x72e0
movq -0x28(%rbp), %rdi
callq 0x74e0
nop