// File: zerolfx[P]P-Machine/mst.cpp
// Function: Mst::execute(StackMachine*)
void Mst::execute(StackMachine *stack)
{	
	for(int i = 0; i < 5; ++i)
	{
		stack->fStore.push_back(new StackElement());
	}

	// static link
	delete stack->fStore[stack->fSP + 2];
	stack->fStore[stack->fSP + 2] = new StackAddress(stack->base(fP, stack->fMP));

	// dynamic link
	delete stack->fStore[stack->fSP + 3];
	stack->fStore[stack->fSP + 3] = new StackAddress(stack->fMP);

	// save EP
	delete stack->fStore[stack->fSP + 4];
	stack->fStore[stack->fSP + 4] = new StackAddress(stack->fEP);
	
	stack->fSP += 5;
	
	// adding cost of this instruction
	stack->fTime.count("mst");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x5, -0x14(%rbp)
jge 0x1b6ee
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x70(%rbp)
movl $0x8, %edi
callq 0x7270
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
callq 0x26c80
jmp 0x1b6af
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x20(%rbp), %rsi
callq 0xd2a0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1b682
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x8, %esi
callq 0x7280
jmp 0x1b9c8
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x1b72f
movq -0x78(%rbp), %rdi
callq 0x26ca0
movq -0x78(%rbp), %rdi
movl $0x8, %esi
callq 0x7280
movl $0x10, %edi
callq 0x7270
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x88(%rbp)
movq -0x10(%rbp), %rdi
movl 0x8(%rax), %esi
movl 0xc0(%rdi), %edx
callq 0x2d050
movl %eax, -0x7c(%rbp)
jmp 0x1b75e
movl -0x7c(%rbp), %esi
movq -0x88(%rbp), %rdi
callq 0x26800
jmp 0x1b76f
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x8e70
movq -0x88(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
addl $0x3, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x1b7e0
movq -0x90(%rbp), %rdi
callq 0x26ca0
movq -0x90(%rbp), %rdi
movl $0x8, %esi
callq 0x7280
movl $0x10, %edi
callq 0x7270
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movl 0xc0(%rax), %esi
callq 0x26800
jmp 0x1b808
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
addl $0x3, %eax
movslq %eax, %rsi
callq 0x8e70
movq -0x98(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
addl $0x4, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, %rax
je 0x1b879
movq -0xa0(%rbp), %rdi
callq 0x26ca0
movq -0xa0(%rbp), %rdi
movl $0x8, %esi
callq 0x7280
movl $0x10, %edi
callq 0x7270
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movl 0xbc(%rax), %esi
callq 0x26800
jmp 0x1b8a1
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movl 0xb4(%rax), %eax
addl $0x4, %eax
movslq %eax, %rsi
callq 0x8e70
movq -0xa8(%rbp), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %ecx
addl $0x5, %ecx
movl %ecx, 0xb4(%rax)
movq -0x10(%rbp), %rax
addq $0x78, %rax
movq %rax, -0xb8(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x74f0
movq -0xb0(%rbp), %rdx
leaq 0x1d77b(%rip), %rsi     # 0x39082
leaq -0x50(%rbp), %rdi
callq 0x8940
jmp 0x1b912
movq -0xb8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2c4d0
jmp 0x1b924
leaq -0x50(%rbp), %rdi
callq 0x7170
leaq -0x51(%rbp), %rdi
callq 0x72e0
addq $0xc0, %rsp
popq %rbp
retq
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x7280
jmp 0x1b9c8
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x7280
jmp 0x1b9c8
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x7280
jmp 0x1b9c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x1b9bf
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
movq -0x28(%rbp), %rdi
callq 0x74e0
nopw %cs:(%rax,%rax)