// File: /workspace/github_cpp_makefile_star2_O2/zerolfx[P]P-Machine/lod.cpp
// Function: Lod::execute(StackMachine*)
void Lod::execute(StackMachine *stack)
{

	if(stack->base(fP, stack->fMP) + fQ > stack->fSP)
		throw ExecutionError("instruction lod: trying to access element above SP");
		
	StackElement *element = stack->fStore[stack->base(fP, stack->fMP) + fQ];
	
	switch(fType)
	{
		case integer:
		{
			StackInteger p;

			if(typeid(p) != typeid(*element))
			{
				strstream convertor;
				convertor << "instruction lod: element at MP + " << fQ << " you are trying to access is not of type integer.";
				throw ExecutionError(convertor.str());
			}
			else
				stack->fStore.push_back(new StackInteger(*(dynamic_cast<StackInteger*>(element))));

			break;
		}	
		case real:
		{
			StackReal p;

			if(typeid(p) != typeid(*element))
			{
				strstream convertor;
				convertor << "instruction lod: element at MP + " << fQ << " you are trying to access is not of type real.";
				throw ExecutionError(convertor.str());
			}
			else
				stack->fStore.push_back(new StackReal(*(dynamic_cast<StackReal*>(element))));


			break;
		}
		case boolean:
		{
			StackBoolean p;
			
			if(typeid(p) != typeid(*element))
			{
				strstream convertor;
				convertor << "instruction lod: element at MP + " << fQ << " you are trying to access is not of type boolean.";
				throw ExecutionError(convertor.str());
			}
			else
				stack->fStore.push_back(new StackBoolean(*(dynamic_cast<StackBoolean*>(element))));


			break;
		}
		case character:
		{
			StackCharacter p;

			if(typeid(p) != typeid(*element))
			{
				strstream convertor;
				convertor << "instruction lod: element at MP + " << fQ << " you are trying to access is not of type character.";
				throw ExecutionError(convertor.str());
			}
			else
				stack->fStore.push_back(new StackCharacter(*(dynamic_cast<StackCharacter*>(element))));


			break;
		}
		case address:
		{
			StackAddress p;
			
			if(typeid(p) != typeid(*element))
			{
				strstream convertor;
				convertor << "instruction lod: element at MP + " << fQ << " you are trying to access is not of type address.";
				throw ExecutionError(convertor.str());
			}
			else
				stack->fStore.push_back(new StackAddress(*(dynamic_cast<StackAddress*>(element))));


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

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rsi, %rbx
movq %rdi, %r15
movl 0xc(%rdi), %esi
movl 0xc0(%rbx), %edx
movq %rbx, %rdi
callq 0x1995a
addl 0x10(%r15), %eax
cmpl 0xb4(%rbx), %eax
jg 0xf567
movl 0xc(%r15), %esi
movl 0xc0(%rbx), %edx
movq %rbx, %rdi
callq 0x1995a
movl 0x8(%r15), %ecx
cmpq $0x4, %rcx
ja 0xf51b
leaq 0x18(%rbx), %r14
movslq 0x10(%r15), %rdx
cltq
addq %rdx, %rax
movq 0x18(%rbx), %rdx
movq (%rdx,%rax,8), %r12
leaq 0x10c93(%rip), %rax     # 0x1fefc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq -0x38(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x177d4
testq %r12, %r12
je 0xf5c3
movq (%r12), %rax
movq -0x8(%rax), %rsi
leaq 0x1f932(%rip), %rdi     # 0x2ebc8
callq 0x76ba
testb %al, %al
jne 0xf77c
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x1f77b(%rip), %rsi     # 0x2ea30
leaq 0x1f90c(%rip), %rdx     # 0x2ebc8
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x1f843(%rip), %rcx     # 0x2eb10
addq $0x10, %rcx
movq %rcx, (%r15)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%r15)
leaq -0x1d0(%rbp), %rsi
movq %r15, (%rsi)
movq %r14, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17802
jmp 0xf51b
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
testq %r12, %r12
je 0xf5b9
movq (%r12), %rax
movq -0x8(%rax), %rsi
leaq 0x1f63e(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0xf5d2
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x1f6ef(%rip), %rsi     # 0x2ea30
leaq 0x1f618(%rip), %rdx     # 0x2e960
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x1f54f(%rip), %rcx     # 0x2e8a8
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x1d0(%rbp), %rsi
movq %r15, (%rsi)
movq %r14, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17070
jmp 0xf51b
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x17a18
testq %r12, %r12
je 0xf5be
movq (%r12), %rax
movq -0x8(%rax), %rsi
leaq 0x1f8ee(%rip), %rdi     # 0x2ec98
callq 0x76ba
testb %al, %al
jne 0xf660
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x1f667(%rip), %rsi     # 0x2ea30
leaq 0x1f8c8(%rip), %rdx     # 0x2ec98
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x1f7ff(%rip), %rcx     # 0x2ebe0
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x1d0(%rbp), %rsi
movq %r15, (%rsi)
movq %r14, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0xf51b
leaq -0x38(%rbp), %rdi
pushq $0x61
popq %rsi
callq 0x17c08
testq %r12, %r12
je 0xf5c8
movq (%r12), %rax
movq -0x8(%rax), %rsi
leaq 0x1f935(%rip), %rdi     # 0x2ed68
callq 0x76ba
testb %al, %al
jne 0xf6ee
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x1f5de(%rip), %rsi     # 0x2ea30
leaq 0x1f90f(%rip), %rdx     # 0x2ed68
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x1f846(%rip), %rcx     # 0x2ecb0
addq $0x10, %rcx
movq %rcx, (%r15)
movb 0x8(%rax), %al
movb %al, 0x8(%r15)
leaq -0x1d0(%rbp), %rsi
movq %r15, (%rsi)
movq %r14, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0xf51b
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x175ac
testq %r12, %r12
je 0xf5cd
movq (%r12), %rax
movq -0x8(%rax), %rsi
leaq 0x1f63d(%rip), %rdi     # 0x2eaf8
callq 0x76ba
testb %al, %al
jne 0xf80a
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r15
leaq 0x1f556(%rip), %rsi     # 0x2ea30
leaq 0x1f617(%rip), %rdx     # 0x2eaf8
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x1f54e(%rip), %rcx     # 0x2ea40
addq $0x10, %rcx
movq %rcx, (%r15)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r15)
leaq -0x1d0(%rbp), %rsi
movq %r15, (%rsi)
movq %r14, %rdi
callq 0x99a0
leaq -0x38(%rbp), %rdi
callq 0x175d0
incl 0xb4(%rbx)
leaq 0x10a42(%rip), %rsi     # 0x1ff6a
leaq -0x1d0(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x72a6
addq $0x78, %rbx
leaq -0x1d0(%rbp), %rsi
movq %rbx, %rdi
callq 0x1925e
leaq -0x1d0(%rbp), %rdi
callq 0x60d0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x1099c(%rip), %rsi     # 0x1ff15
leaq -0x1d0(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x1d0(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1e4e3(%rip), %rsi     # 0x2da88
leaq 0x876e(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xf893
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
leaq -0x1d0(%rbp), %rdi
callq 0x62e0
leaq -0x1c0(%rbp), %rdi
leaq 0x1095c(%rip), %rsi     # 0x1ff48
callq 0x61b0
movl 0x10(%r15), %esi
movq %rax, %rdi
callq 0x63d0
leaq 0x11898(%rip), %rsi     # 0x20e9c
movq %rax, %rdi
callq 0x61b0
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
callq 0x6330
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
movq %rax, %rsi
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1e43c(%rip), %rsi     # 0x2da88
leaq 0x86c7(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xf893
leaq -0x1d0(%rbp), %rdi
callq 0x62e0
leaq -0x1c0(%rbp), %rdi
leaq 0x108ce(%rip), %rsi     # 0x1ff48
callq 0x61b0
movl 0x10(%r15), %esi
movq %rax, %rdi
callq 0x63d0
leaq 0x11774(%rip), %rsi     # 0x20e06
movq %rax, %rdi
callq 0x61b0
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
callq 0x6330
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
movq %rax, %rsi
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1e3ae(%rip), %rsi     # 0x2da88
leaq 0x8639(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xf893
leaq -0x1d0(%rbp), %rdi
callq 0x62e0
leaq -0x1c0(%rbp), %rdi
leaq 0x10840(%rip), %rsi     # 0x1ff48
callq 0x61b0
movl 0x10(%r15), %esi
movq %rax, %rdi
callq 0x63d0
leaq 0x11730(%rip), %rsi     # 0x20e50
movq %rax, %rdi
callq 0x61b0
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
callq 0x6330
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
movq %rax, %rsi
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1e320(%rip), %rsi     # 0x2da88
leaq 0x85ab(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xf893
leaq -0x1d0(%rbp), %rdi
callq 0x62e0
leaq -0x1c0(%rbp), %rdi
leaq 0x107b2(%rip), %rsi     # 0x1ff48
callq 0x61b0
movl 0x10(%r15), %esi
movq %rax, %rdi
callq 0x63d0
leaq 0x11611(%rip), %rsi     # 0x20dbf
movq %rax, %rdi
callq 0x61b0
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
callq 0x6330
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
movq %rax, %rsi
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1e292(%rip), %rsi     # 0x2da88
leaq 0x851d(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xf893
leaq -0x1d0(%rbp), %rdi
callq 0x62e0
leaq -0x1c0(%rbp), %rdi
leaq 0x10724(%rip), %rsi     # 0x1ff48
callq 0x61b0
movl 0x10(%r15), %esi
movq %rax, %rdi
callq 0x63d0
leaq 0x11539(%rip), %rsi     # 0x20d75
movq %rax, %rdi
callq 0x61b0
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
callq 0x6330
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
movq %rax, %rsi
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1e204(%rip), %rsi     # 0x2da88
leaq 0x848f(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xf8ac
jmp 0xf93f
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xf93f
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xf8d2
jmp 0xf950
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xf950
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xf8f2
jmp 0xf961
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xf961
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xf912
jmp 0xf972
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xf972
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xf932
jmp 0xf983
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xf983
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x6420
jmp 0xf9a8
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x6420
jmp 0xf9b6
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x6420
jmp 0xf9c4
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x6420
jmp 0xf9d2
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x6420
jmp 0xf9e0
jmp 0xf9a5
jmp 0xf9b3
jmp 0xf9c1
jmp 0xf9cf
jmp 0xf9dd
jmp 0xf9a5
jmp 0xf9b3
jmp 0xf9c1
jmp 0xf9cf
jmp 0xf9dd
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x175d0
jmp 0xfa22
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17802
jmp 0xfa22
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0xfa22
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0xfa22
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17070
jmp 0xfa22
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xfa04
jmp 0xfa22
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xfa22
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x60d0
jmp 0xfa22
movq %rax, %rbx
movq %rbx, %rdi
callq 0x63f0