-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLZCNT.c
52 lines (42 loc) · 909 Bytes
/
LZCNT.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Driver.h"
#include "Parser.h"
int __stdcall LZCNTInstructionEmulator(
ParsedInstruction instruction,
CALLER_CONTEXT* context)
{
UNREFERENCED_PARAMETER(instruction);
UNREFERENCED_PARAMETER(context);
unsigned int src;
if (instruction.src1 == MEM_32 || instruction.src1 == MEM_16 )
{
src = *(unsigned int*)getEffectiveVA(instruction.mem, context);
}
else
{
src = getRegValue(instruction.src1, context);
}
unsigned int operand_size = 32;
if (instruction.dest & 0x10) // 16-bit instruction
{
operand_size = 16;
}
int temp = operand_size - 1;
int dest = 0;
while ((temp >= 0) && (((src >> temp) & 1) == 0))
{
--temp;
++dest;
}
// Set flags
context->flags &= (~FLAG_ZF) & (~FLAG_CF);
if (dest == (int)operand_size)
{
context->flags |= FLAG_CF;
}
if (dest == 0)
{
context->flags |= FLAG_ZF;
}
setRegValue(instruction.dest, dest, context);
return TRUE;
}