For the asm emulator i'm trying to write to convert ASM code to equivalent working code just working.. best code would be the one that can either be done in one line or two-three the most, don't care about speed.
对于asm仿真器,我正在尝试编写它,将asm代码转换为等效的工作代码。最好的代码应该是可以在一行或两行中完成的,最不关心速度。
From my understanding. MOVZX would be the same as MOV.. if done in C++.
从我的理解。MOVZX和MOV一样。如果在c++中完成。
MOV
conversion.
MOV转换。
MOV ESI,DWORD PTR [ESP+8]
would be like
就像
regs.d.esi = *(unsigned int *)(regs.d.esp+0x00000008);
MOVZX
conversion.
MOVZX转换。
MOVZX EAX,BYTE PTR DS:[EDI]
would be like
就像
regs.d.eax = *(unsigned char *)(regs.d.edi);
pretty much the same thing no change what so ever.
几乎是一样的事情,不会改变什么。
Now MOVSX
i'm having trouble converting to a simple C code.. seems to be the same as the two above.. except it attempts to append as much fully set bits in front of the value moved as possible.. like
现在MOVSX我在转换成简单的C代码时遇到了麻烦。似乎和上面两个是一样的。除非它尝试在值前面添加尽可能多的集合位。就像
000000C7
becomes FFFFFFC7
000000 c7变得FFFFFFC7
2 个解决方案
#1
3
movsx
is move with sign-extend. Those set bits are a copy of the sign bit from the original value, and would be clear if the original wasn't negative. It works just like your other conversions, except you need to use a signed type instead of an unsigned one.
movsx是带有信号扩展的移动。这些集合位是来自原始值的符号位的拷贝,如果原始值不是负的,就很清楚了。它和其他转换一样,只是需要使用签名的类型而不是未签名的类型。
regs.d.eax = *(signed char *)(regs.d.edi); // movsx eax, byte ptr ds:[edi]
#2
0
The fastest way to find very fast C equivalents of MOVSX and MOVXZ is just integer variable assignment from a type with lower bits to a type with higher bits. Both variables have to be typecasted either to signed type (for MOVSX) or unsigned type (MOVZX).
找到非常快的C等价的MOVSX和MOVXZ的最快方法是将整数变量从位低的类型分配到位高的类型。这两个变量都必须为已签名的类型(用于MOVSX)或无符号类型(MOVZX)。
For example, C equivalent of "movzx ebx, al" would be:
例如,C的“movzx ebx, al”等于:
(unsigned int) ebx = (unsigned char) al;
C equivalent of "movsx ebx, al" would be:
C对应的“movsx ebx, al”为:
(signed int) ebx = (signed char) al;
Just make sure your char type is 8 bit and your int type is 32 bit, and so on.
确保你的char类型是8位,而int类型是32位,等等。
#1
3
movsx
is move with sign-extend. Those set bits are a copy of the sign bit from the original value, and would be clear if the original wasn't negative. It works just like your other conversions, except you need to use a signed type instead of an unsigned one.
movsx是带有信号扩展的移动。这些集合位是来自原始值的符号位的拷贝,如果原始值不是负的,就很清楚了。它和其他转换一样,只是需要使用签名的类型而不是未签名的类型。
regs.d.eax = *(signed char *)(regs.d.edi); // movsx eax, byte ptr ds:[edi]
#2
0
The fastest way to find very fast C equivalents of MOVSX and MOVXZ is just integer variable assignment from a type with lower bits to a type with higher bits. Both variables have to be typecasted either to signed type (for MOVSX) or unsigned type (MOVZX).
找到非常快的C等价的MOVSX和MOVXZ的最快方法是将整数变量从位低的类型分配到位高的类型。这两个变量都必须为已签名的类型(用于MOVSX)或无符号类型(MOVZX)。
For example, C equivalent of "movzx ebx, al" would be:
例如,C的“movzx ebx, al”等于:
(unsigned int) ebx = (unsigned char) al;
C equivalent of "movsx ebx, al" would be:
C对应的“movsx ebx, al”为:
(signed int) ebx = (signed char) al;
Just make sure your char type is 8 bit and your int type is 32 bit, and so on.
确保你的char类型是8位,而int类型是32位,等等。