// File: zerolfx[P]P-Machine/chk.cpp
// Function: Chk::execute(StackMachine*)
void Chk::execute(StackMachine *stack)
{
	StackInteger p;
	if(typeid(p) != typeid(*(stack->fStore[stack->fSP])))
	{
		throw ExecutionError("instruction chk: STORE[SP] does not contain element of type integer.");
	}
	
	if((stack->fStore[stack->fSP]->getValue() < fP) || (stack->fStore[stack->fSP]->getValue() > fQ))
	{
		throw ExecutionError("instruction chk: value out of range.");
	}
	
	// adding cost of this instruction
	stack->fTime.count("chk");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
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, -0xb0(%rbp)
cmpq $0x0, %rax
jne 0xa8c8
callq 0x7300
jmp 0xa8c8
movq -0xb0(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x40213(%rip), %rdi     # 0x4aaf0
callq 0x9370
testb $0x1, %al
jne 0xa8eb
jmp 0xa9b4
movb $0x1, -0x52(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0xc8(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x74f0
movq -0xc0(%rbp), %rdx
leaq 0x2caca(%rip), %rsi     # 0x373e8
leaq -0x50(%rbp), %rdi
callq 0x8940
jmp 0xa929
movq -0xc8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x283d0
jmp 0xa93b
movq -0xc8(%rbp), %rdi
movb $0x0, -0x52(%rbp)
leaq 0x3f133(%rip), %rsi     # 0x49a80
leaq 0x1daac(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0xabab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0xab99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0xa992
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 0xa9a3
jmp 0xa9af
movq -0xc8(%rbp), %rdi
callq 0x71c0
jmp 0xab99
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rdi
movq (%rdi), %rax
movq 0x68(%rax), %rax
callq *%rax
movl %eax, -0xcc(%rbp)
jmp 0xa9df
movl -0xcc(%rbp), %eax
movq -0xb8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jl 0xaa32
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rdi
movq (%rdi), %rax
movq 0x68(%rax), %rax
callq *%rax
movl %eax, -0xd0(%rbp)
jmp 0xaa1c
movl -0xd0(%rbp), %eax
movq -0xb8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jle 0xaaea
movb $0x1, -0x7a(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0xe0(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x74f0
movq -0xd8(%rbp), %rdx
leaq 0x2c9c8(%rip), %rsi     # 0x3742d
leaq -0x78(%rbp), %rdi
callq 0x8940
jmp 0xaa70
movq -0xe0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x283d0
jmp 0xaa82
movq -0xe0(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x3efec(%rip), %rsi     # 0x49a80
leaq 0x1d965(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0xabab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0xaac8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x7170
leaq -0x79(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x7a(%rbp)
jne 0xaad9
jmp 0xaae5
movq -0xe0(%rbp), %rdi
callq 0x71c0
jmp 0xab99
movq -0x10(%rbp), %rax
addq $0x78, %rax
movq %rax, -0xf0(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x74f0
movq -0xe8(%rbp), %rdx
leaq 0x2c938(%rip), %rsi     # 0x37452
leaq -0xa0(%rbp), %rdi
callq 0x8940
jmp 0xab28
movq -0xf0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2c4d0
jmp 0xab3d
leaq -0xa0(%rbp), %rdi
callq 0x7170
leaq -0xa1(%rbp), %rdi
callq 0x72e0
leaq -0x20(%rbp), %rdi
callq 0x27380
addq $0xf0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0xab8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7170
leaq -0xa1(%rbp), %rdi
callq 0x72e0
leaq -0x20(%rbp), %rdi
callq 0x27380
movq -0x28(%rbp), %rdi
callq 0x74e0
nopl (%rax,%rax)