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

			if(typeid(p) != typeid(*stack->fStore[stack->fSP]))
				throw ExecutionError("instruction str: element you are trying to access is not of type integer.");

			break;
		}	
		case real:
		{
			StackReal p;

			if(typeid(p) != typeid(*stack->fStore[stack->fSP]))
				throw ExecutionError("instruction str: element you are trying to access is not of type real.");


			break;
		}
		case boolean:
		{
			StackBoolean p;
			
			if(typeid(p) != typeid(*stack->fStore[stack->fSP]))
				throw ExecutionError("instruction str: element you are trying to access is not of type boolean.");

			break;
		}
		case character:
		{
			StackCharacter p;

			if(typeid(p) != typeid(*stack->fStore[stack->fSP]))
				throw ExecutionError("instruction str: element you are trying to access is not of type character.");

			break;
		}
		case address:
		{
			StackAddress p;
			
			if(typeid(p) != typeid(*stack->fStore[stack->fSP]))
				throw ExecutionError("instruction str: element you are trying to access is not of type address.");

			break;
		}
	}
	
	int newaddress = stack->base(fP, stack->fMP) + fQ;
	
	if((newaddress > stack->fSP) || (newaddress < 0))
		throw ExecutionError("instruction str: trying to access element above SP or < 0.");
	
	delete stack->fStore[newaddress];
	stack->fStore[newaddress] = stack->fStore[stack->fSP];
	stack->fStore.pop_back();
	
	--stack->fSP;
	
	// adding cost of this instruction
	stack->fTime.count("str");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
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 0x22fd1
movq -0x190(%rbp), %rax
leaq 0x17424(%rip), %rcx     # 0x39d44
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x27340
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
cmpq $0x0, %rax
jne 0x22963
callq 0x7300
jmp 0x22963
movq -0x1a0(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x28178(%rip), %rdi     # 0x4aaf0
callq 0x9370
testb $0x1, %al
jne 0x22986
jmp 0x22a49
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 0x173a4(%rip), %rsi     # 0x39d5d
leaq -0x50(%rbp), %rdi
callq 0x8940
jmp 0x229c4
movq -0x1b0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x283d0
jmp 0x229d6
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x52(%rbp)
leaq 0x27098(%rip), %rsi     # 0x49a80
leaq 0x5a11(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x2323b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22a57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22a2a
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 0x22a3b
jmp 0x22a47
movq -0x1b0(%rbp), %rdi
callq 0x71c0
jmp 0x22a57
leaq -0x20(%rbp), %rdi
callq 0x27380
jmp 0x22fd1
leaq -0x20(%rbp), %rdi
callq 0x27380
jmp 0x23232
leaq -0x68(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x27840
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
jne 0x22aa0
callq 0x7300
jmp 0x22aa0
movq -0x1b8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x2810b(%rip), %rdi     # 0x4abc0
callq 0x9370
testb $0x1, %al
jne 0x22ac3
jmp 0x22b9e
movb $0x1, -0x8a(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x1c8(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x74f0
movq -0x1c0(%rbp), %rdx
leaq 0x172ab(%rip), %rsi     # 0x39da7
leaq -0x88(%rbp), %rdi
callq 0x8940
jmp 0x22b0a
movq -0x1c8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x283d0
jmp 0x22b1f
movq -0x1c8(%rbp), %rdi
movb $0x0, -0x8a(%rbp)
leaq 0x26f4c(%rip), %rsi     # 0x49a80
leaq 0x58c5(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x2323b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22bac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22b79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x7170
leaq -0x89(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x8a(%rbp)
jne 0x22b90
jmp 0x22b9c
movq -0x1c8(%rbp), %rdi
callq 0x71c0
jmp 0x22bac
leaq -0x68(%rbp), %rdi
callq 0x27880
jmp 0x22fd1
leaq -0x68(%rbp), %rdi
callq 0x27880
jmp 0x23232
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x27d20
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x1d0(%rbp)
cmpq $0x0, %rax
jne 0x22bf7
callq 0x7300
jmp 0x22bf7
movq -0x1d0(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x28084(%rip), %rdi     # 0x4ac90
callq 0x9370
testb $0x1, %al
jne 0x22c1a
jmp 0x22cf5
movb $0x1, -0xc2(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x1e0(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x74f0
movq -0x1d8(%rbp), %rdx
leaq 0x1719b(%rip), %rsi     # 0x39dee
leaq -0xc0(%rbp), %rdi
callq 0x8940
jmp 0x22c61
movq -0x1e0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x283d0
jmp 0x22c76
movq -0x1e0(%rbp), %rdi
movb $0x0, -0xc2(%rbp)
leaq 0x26df5(%rip), %rsi     # 0x49a80
leaq 0x576e(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x2323b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22d06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22cd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x7170
leaq -0xc1(%rbp), %rdi
callq 0x72e0
testb $0x1, -0xc2(%rbp)
jne 0x22ce7
jmp 0x22cf3
movq -0x1e0(%rbp), %rdi
callq 0x71c0
jmp 0x22d06
leaq -0xa0(%rbp), %rdi
callq 0x27d70
jmp 0x22fd1
leaq -0xa0(%rbp), %rdi
callq 0x27d70
jmp 0x23232
leaq -0xd8(%rbp), %rdi
movl $0x61, %esi
callq 0x28170
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x1e8(%rbp)
cmpq $0x0, %rax
jne 0x22d57
callq 0x7300
jmp 0x22d57
movq -0x1e8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x27ff4(%rip), %rdi     # 0x4ad60
callq 0x9370
testb $0x1, %al
jne 0x22d7a
jmp 0x22e55
movb $0x1, -0xfa(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x1f8(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x74f0
movq -0x1f0(%rbp), %rdx
leaq 0x17085(%rip), %rsi     # 0x39e38
leaq -0xf8(%rbp), %rdi
callq 0x8940
jmp 0x22dc1
movq -0x1f8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x283d0
jmp 0x22dd6
movq -0x1f8(%rbp), %rdi
movb $0x0, -0xfa(%rbp)
leaq 0x26c95(%rip), %rsi     # 0x49a80
leaq 0x560e(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x2323b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22e66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22e30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x7170
leaq -0xf9(%rbp), %rdi
callq 0x72e0
testb $0x1, -0xfa(%rbp)
jne 0x22e47
jmp 0x22e53
movq -0x1f8(%rbp), %rdi
callq 0x71c0
jmp 0x22e66
leaq -0xd8(%rbp), %rdi
callq 0x281b0
jmp 0x22fd1
leaq -0xd8(%rbp), %rdi
callq 0x281b0
jmp 0x23232
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
callq 0x26800
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x200(%rbp)
cmpq $0x0, %rax
jne 0x22eb4
callq 0x7300
jmp 0x22eb4
movq -0x200(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x27a8f(%rip), %rdi     # 0x4a958
callq 0x9370
testb $0x1, %al
jne 0x22ed7
jmp 0x22fb2
movb $0x1, -0x132(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x210(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x74f0
movq -0x208(%rbp), %rdx
leaq 0x16f74(%rip), %rsi     # 0x39e84
leaq -0x130(%rbp), %rdi
callq 0x8940
jmp 0x22f1e
movq -0x210(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x283d0
jmp 0x22f33
movq -0x210(%rbp), %rdi
movb $0x0, -0x132(%rbp)
leaq 0x26b38(%rip), %rsi     # 0x49a80
leaq 0x54b1(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x2323b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22fc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x22f8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x7170
leaq -0x131(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x132(%rbp)
jne 0x22fa4
jmp 0x22fb0
movq -0x210(%rbp), %rdi
callq 0x71c0
jmp 0x22fc0
leaq -0x110(%rbp), %rdi
callq 0x26840
jmp 0x22fd1
leaq -0x110(%rbp), %rdi
callq 0x26840
jmp 0x23232
movq -0x198(%rbp), %rax
movq -0x10(%rbp), %rdi
movl 0xc(%rax), %esi
movq -0x10(%rbp), %rax
movl 0xc0(%rax), %edx
callq 0x2d050
movq -0x198(%rbp), %rcx
addl 0x10(%rcx), %eax
movl %eax, -0x138(%rbp)
movl -0x138(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xb4(%rcx), %eax
jg 0x2301d
cmpl $0x0, -0x138(%rbp)
jge 0x230ed
movb $0x1, -0x15a(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x220(%rbp)
leaq -0x159(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x74f0
movq -0x218(%rbp), %rdx
leaq 0x16e78(%rip), %rsi     # 0x39ece
leaq -0x158(%rbp), %rdi
callq 0x8940
jmp 0x23064
movq -0x220(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x283d0
jmp 0x23079
movq -0x220(%rbp), %rdi
movb $0x0, -0x15a(%rbp)
leaq 0x269f2(%rip), %rsi     # 0x49a80
leaq 0x536b(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x2323b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x230c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x7170
leaq -0x159(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x15a(%rbp)
jne 0x230dc
jmp 0x230e8
movq -0x220(%rbp), %rdi
callq 0x71c0
jmp 0x23232
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movslq -0x138(%rbp), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x228(%rbp)
cmpq $0x0, %rax
je 0x2312e
movq -0x228(%rbp), %rdi
callq 0x26ca0
movq -0x228(%rbp), %rdi
movl $0x8, %esi
callq 0x7280
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x240(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movslq -0x138(%rbp), %rsi
callq 0x8e70
movq -0x240(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
callq 0x8e90
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %ecx
decl %ecx
movl %ecx, 0xb4(%rax)
movq -0x10(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x238(%rbp)
leaq -0x181(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x74f0
movq -0x230(%rbp), %rdx
leaq 0x16d4d(%rip), %rsi     # 0x39f09
leaq -0x180(%rbp), %rdi
callq 0x8940
jmp 0x231ca
movq -0x238(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x2c4d0
jmp 0x231df
leaq -0x180(%rbp), %rdi
callq 0x7170
leaq -0x181(%rbp), %rdi
callq 0x72e0
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x23226
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
nopl (%rax,%rax)