// File: /workspace/github_cpp_makefile_star2_O2/zerolfx[P]P-Machine/movs.cpp
// Function: Movs::execute(StackMachine*)
void Movs::execute(StackMachine *stack)
{	
	StackAddress p;
	
	if((stack->fSP < 0) || (typeid(p) != typeid(*(stack->fStore[stack->fSP]))))
		throw ExecutionError("instruction movs: highest stackposition expected to be of type address.");
		
	int newaddress = stack->fStore[stack->fSP]->getValue();

	delete stack->fStore[stack->fSP];
	stack->fStore[stack->fSP] = 0;
	stack->fStore.pop_back();
	
	if(newaddress < 0)
	{	
		// copying a block from the heapspace to the top of the stack
		// pay attention to the reverse with respect to what the book describes on p50
	
		StackInteger p1;
		StackBoolean p2;
		StackAddress p3;
		StackCharacter p4;
		StackReal p5;
		StackElement p6;
				
		for(int i = 0; i <= fQ - 1; ++i)
		{
			if(typeid(p1) == typeid(*stack->fHeap[- i - newaddress - 1]))
				stack->fStore.push_back(new StackInteger(*(dynamic_cast<StackInteger*>(stack->fHeap[i - newaddress]))));
			if(typeid(p2) == typeid(*stack->fHeap[- i - newaddress - 1]))
				stack->fStore.push_back(new StackBoolean(*(dynamic_cast<StackBoolean*>(stack->fHeap[i - newaddress]))));
			if(typeid(p3) == typeid(*stack->fHeap[- i - newaddress - 1]))
				stack->fStore.push_back(new StackAddress(*(dynamic_cast<StackAddress*>(stack->fHeap[i - newaddress]))));			
			if(typeid(p4) == typeid(*stack->fHeap[- i - newaddress - 1]))
				stack->fStore.push_back(new StackCharacter(*(dynamic_cast<StackCharacter*>(stack->fHeap[i - newaddress]))));
			if(typeid(p5) == typeid(*stack->fHeap[- i - newaddress - 1]))
				stack->fStore.push_back(new StackReal(*(dynamic_cast<StackReal*>(stack->fHeap[i - newaddress]))));
			if(typeid(p6) == typeid(*stack->fHeap[- i - newaddress - 1]))
				stack->fStore.push_back(new StackElement(*(dynamic_cast<StackElement*>(stack->fHeap[i - newaddress]))));
		}
	}
	else
	{
		// copying a block from the stackspace to the top of the stack
		// pay attention to the reverse with respect to what the book describes on p50

		StackInteger p1;
		StackBoolean p2;
		StackAddress p3;
		StackCharacter p4;
		StackReal p5;
		StackElement p6;
	
		for(int i = 0; i <= fQ - 1; ++i)
		{
			if(typeid(p1) == typeid(*stack->fStore[i + newaddress]))
				stack->fStore.push_back(new StackInteger(*(dynamic_cast<StackInteger*>(stack->fStore[i + newaddress]))));
			if(typeid(p2) == typeid(*stack->fStore[i + newaddress]))
				stack->fStore.push_back(new StackBoolean(*(dynamic_cast<StackBoolean*>(stack->fStore[i + newaddress]))));
			if(typeid(p3) == typeid(*stack->fStore[i + newaddress]))
				stack->fStore.push_back(new StackAddress(*(dynamic_cast<StackAddress*>(stack->fStore[i + newaddress]))));			
			if(typeid(p4) == typeid(*stack->fStore[i + newaddress]))
				stack->fStore.push_back(new StackCharacter(*(dynamic_cast<StackCharacter*>(stack->fStore[i + newaddress]))));
			if(typeid(p5) == typeid(*stack->fStore[i + newaddress]))
				stack->fStore.push_back(new StackReal(*(dynamic_cast<StackReal*>(stack->fStore[i + newaddress]))));
			if(typeid(p6) == typeid(*stack->fStore[i + newaddress]))
				stack->fStore.push_back(new StackElement(*(dynamic_cast<StackElement*>(stack->fStore[i + newaddress]))));
		}
	}
	
	stack->fSP = stack->fSP + fQ - 1;
	
	// adding cost of this instruction
	stack->fTime.count("movs");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %rbx
movq %rdi, -0x78(%rbp)
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
movslq 0xb4(%rbx), %rax
testq %rax, %rax
js 0x10f31
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x10f81
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1e25e(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0x10f31
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, %r12d
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r14
testq %r14, %r14
je 0x10743
movq %r14, %rdi
callq 0x17248
leaq 0x18(%rbx), %r15
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x61e0
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
andq $0x0, (%rcx,%rax,8)
movq %rbx, -0x38(%rbp)
addq $-0x8, 0x20(%rbx)
movl %r12d, %r14d
testl %r12d, %r12d
js 0x10ad0
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
callq 0x175ac
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x17a18
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
leaq -0xc8(%rbp), %rdi
pushq $0x61
popq %rsi
callq 0x17c08
leaq -0xb8(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x177d4
leaq -0x48(%rbp), %rdi
callq 0x17238
movl %r14d, %r12d
shlq $0x3, %r12
xorl %r14d, %r14d
leaq 0x1e31f(%rip), %rbx     # 0x2eaf8
leaq 0x1e260(%rip), %rax     # 0x2ea40
addq $0x10, %rax
movq %rax, -0x40(%rbp)
leaq 0x1e3f1(%rip), %rax     # 0x2ebe0
addq $0x10, %rax
movq %rax, -0x70(%rbp)
leaq 0x1e0aa(%rip), %rax     # 0x2e8a8
addq $0x10, %rax
movq %rax, -0x68(%rbp)
leaq 0x1e4a3(%rip), %rax     # 0x2ecb0
addq $0x10, %rax
movq %rax, -0x60(%rbp)
leaq 0x1e2f4(%rip), %rax     # 0x2eb10
addq $0x10, %rax
movq %rax, -0x58(%rbp)
leaq 0x1e14d(%rip), %rax     # 0x2e978
addq $0x10, %rax
movq %rax, -0x50(%rbp)
movq -0x78(%rbp), %rax
movslq 0x8(%rax), %rax
cmpq %rax, %r14
jge 0x10e70
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f27
movq (%rax), %rax
movq -0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x76c8
testb %al, %al
je 0x108af
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rdi
leaq 0x1e1aa(%rip), %rsi     # 0x2ea30
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x6230
movq -0x40(%rbp), %rcx
movq %rcx, (%r13)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f27
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1e3c8(%rip), %rdi     # 0x2ec98
callq 0x76c8
testb %al, %al
je 0x10922
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rdi
leaq 0x1e13b(%rip), %rsi     # 0x2ea30
leaq 0x1e39c(%rip), %rdx     # 0x2ec98
xorl %ecx, %ecx
callq 0x6230
movq -0x70(%rbp), %rcx
movq %rcx, (%r13)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f27
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1e01d(%rip), %rdi     # 0x2e960
callq 0x76c8
testb %al, %al
je 0x10995
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rdi
leaq 0x1e0c8(%rip), %rsi     # 0x2ea30
leaq 0x1dff1(%rip), %rdx     # 0x2e960
xorl %ecx, %ecx
callq 0x6230
movq -0x68(%rbp), %rcx
movq %rcx, (%r13)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f27
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1e3b2(%rip), %rdi     # 0x2ed68
callq 0x76c8
testb %al, %al
je 0x10a08
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rdi
leaq 0x1e055(%rip), %rsi     # 0x2ea30
leaq 0x1e386(%rip), %rdx     # 0x2ed68
xorl %ecx, %ecx
callq 0x6230
movq -0x60(%rbp), %rcx
movq %rcx, (%r13)
movb 0x8(%rax), %al
movb %al, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f27
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1e19f(%rip), %rdi     # 0x2ebc8
callq 0x76c8
testb %al, %al
je 0x10a7f
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rdi
leaq 0x1dfe2(%rip), %rsi     # 0x2ea30
leaq 0x1e173(%rip), %rdx     # 0x2ebc8
xorl %ecx, %ecx
callq 0x6230
movq -0x58(%rbp), %rcx
movq %rcx, (%r13)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq (%r15), %rax
addq %r12, %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f27
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1df90(%rip), %rdi     # 0x2ea30
callq 0x76c8
testb %al, %al
je 0x10ac8
pushq $0x8
popq %rdi
callq 0x61d0
movq -0x50(%rbp), %rcx
movq %rcx, (%rax)
movq %rax, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
incq %r14
jmp 0x10833
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
callq 0x175ac
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x17a18
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
leaq -0xc8(%rbp), %rdi
pushq $0x61
popq %rsi
callq 0x17c08
leaq -0xb8(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x177d4
leaq -0x48(%rbp), %rdi
callq 0x17238
movslq %r14d, %rax
notl %r14d
shlq $0x3, %rax
negq %rax
movq %rax, -0x40(%rbp)
xorl %r12d, %r12d
leaq 0x1df04(%rip), %rax     # 0x2ea40
addq $0x10, %rax
movq %rax, -0x70(%rbp)
leaq 0x1e095(%rip), %rax     # 0x2ebe0
addq $0x10, %rax
movq %rax, -0x68(%rbp)
leaq 0x1dd4e(%rip), %rax     # 0x2e8a8
addq $0x10, %rax
movq %rax, -0x60(%rbp)
leaq 0x1e147(%rip), %rax     # 0x2ecb0
addq $0x10, %rax
movq %rax, -0x58(%rbp)
leaq 0x1df98(%rip), %rax     # 0x2eb10
addq $0x10, %rax
movq %rax, -0x50(%rbp)
leaq 0x1ddf1(%rip), %rax     # 0x2e978
addq $0x10, %rax
movq %rax, -0xe0(%rbp)
movq -0x78(%rbp), %rax
movslq 0x8(%rax), %rax
cmpq %rax, %r12
jge 0x10e70
movl %r14d, %ebx
movslq %r14d, %r14
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f2c
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1df2c(%rip), %rdi     # 0x2eaf8
callq 0x76c8
testb %al, %al
je 0x10c24
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rdi
leaq 0x1de39(%rip), %rsi     # 0x2ea30
leaq 0x1defa(%rip), %rdx     # 0x2eaf8
xorl %ecx, %ecx
callq 0x6230
movq -0x70(%rbp), %rcx
movq %rcx, (%r13)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f2c
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1e051(%rip), %rdi     # 0x2ec98
callq 0x76c8
testb %al, %al
je 0x10c9f
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rdi
leaq 0x1ddbe(%rip), %rsi     # 0x2ea30
leaq 0x1e01f(%rip), %rdx     # 0x2ec98
xorl %ecx, %ecx
callq 0x6230
movq -0x68(%rbp), %rcx
movq %rcx, (%r13)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f2c
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1dc9e(%rip), %rdi     # 0x2e960
callq 0x76c8
testb %al, %al
je 0x10d1a
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rdi
leaq 0x1dd43(%rip), %rsi     # 0x2ea30
leaq 0x1dc6c(%rip), %rdx     # 0x2e960
xorl %ecx, %ecx
callq 0x6230
movq -0x60(%rbp), %rcx
movq %rcx, (%r13)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f2c
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1e02b(%rip), %rdi     # 0x2ed68
callq 0x76c8
testb %al, %al
je 0x10d95
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rdi
leaq 0x1dcc8(%rip), %rsi     # 0x2ea30
leaq 0x1dff9(%rip), %rdx     # 0x2ed68
xorl %ecx, %ecx
callq 0x6230
movq -0x58(%rbp), %rcx
movq %rcx, (%r13)
movb 0x8(%rax), %al
movb %al, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f2c
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1de10(%rip), %rdi     # 0x2ebc8
callq 0x76c8
testb %al, %al
je 0x10e14
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r13
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rdi
leaq 0x1dc4d(%rip), %rsi     # 0x2ea30
leaq 0x1ddde(%rip), %rdx     # 0x2ebc8
xorl %ecx, %ecx
callq 0x6230
movq -0x50(%rbp), %rcx
movq %rcx, (%r13)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%r13)
movq %r13, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x10f2c
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1dbf9(%rip), %rdi     # 0x2ea30
callq 0x76c8
testb %al, %al
movl %ebx, %r14d
je 0x10e65
pushq $0x8
popq %rdi
callq 0x61d0
movq -0xe0(%rbp), %rcx
movq %rcx, (%rax)
movq %rax, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x99a0
incq %r12
decl %r14d
jmp 0x10b92
leaq -0x48(%rbp), %rdi
callq 0x17248
leaq -0xb8(%rbp), %rdi
callq 0x17802
leaq -0xc8(%rbp), %rdi
callq 0x17c2c
leaq -0xd8(%rbp), %rdi
callq 0x17070
leaq -0x88(%rbp), %rdi
callq 0x17a3c
leaq -0xa8(%rbp), %rdi
callq 0x175d0
movq -0x38(%rbp), %rbx
movl 0xb4(%rbx), %eax
movq -0x78(%rbp), %rcx
movl 0x8(%rcx), %ecx
leal -0x1(%rax,%rcx), %eax
movl %eax, 0xb4(%rbx)
leaq 0xf19a(%rip), %rsi      # 0x20071
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x72a6
addq $0x78, %rbx
leaq -0xa8(%rbp), %rsi
movq %rbx, %rdi
callq 0x1925e
leaq -0xa8(%rbp), %rdi
callq 0x60d0
leaq -0xf0(%rbp), %rdi
callq 0x17070
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6220
callq 0x6220
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0xf0e6(%rip), %rsi      # 0x20029
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0xa8(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1cb16(%rip), %rsi     # 0x2da88
leaq 0x6da1(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
callq 0x6220
jmp 0x10f92
jmp 0x10f9a
jmp 0x10fa2
jmp 0x10faa
jmp 0x10fb2
jmp 0x10fd4
movq %rax, %rbx
jmp 0x11025
movq %rax, %rbx
jmp 0x11031
movq %rax, %rbx
jmp 0x1103d
movq %rax, %rbx
jmp 0x11049
movq %rax, %rbx
jmp 0x11055
jmp 0x10fd4
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x60d0
jmp 0x11061
jmp 0x10fd4
jmp 0x10fd4
movq %rax, %rbx
jmp 0x11061
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x10ff5
jmp 0x11061
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x11061
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
jmp 0x11019
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x17248
leaq -0xb8(%rbp), %rdi
callq 0x17802
leaq -0xc8(%rbp), %rdi
callq 0x17c2c
leaq -0xd8(%rbp), %rdi
callq 0x17070
leaq -0x88(%rbp), %rdi
callq 0x17a3c
leaq -0xa8(%rbp), %rdi
callq 0x175d0
leaq -0xf0(%rbp), %rdi
callq 0x17070
movq %rbx, %rdi
callq 0x63f0
nop