CDECL 调用约定 引起奇怪的警告 组装 X86
CDECL Calling Convention Causing strange warnings ASSEMBLY X86
大家好,我是汇编语言x86的新手,我正在尝试从一组加密指令中生成CDECL调用约定。我相信我在执行公约时会出错。下面是作为问题给出的原始指令和功能集。还包括我的尝试(请原谅我,如果它对汇编语言来说是全新的)。我在C++开发设置中使用Visual Studio 2013。
几行给出的警告是 - 警告 C4409:非法指令大小(在指令前使用"@"符号来标记适用的行)
我还收到另外 2 个警告 - 警告 C4731:"encrypt_chars":"帧指针寄存器"ebp"由内联汇编代码修改(在适用的行之前使用"$"符号)
void encrypt_chars (int length, char EKey)
{ char temp_char; // char temporary store
for (int i = 0; i < length; i++) // encrypt characters one at a time
{ temp_char = OChars [i];
__asm {
//------------------------ORIGINAL CODE-------------------------------------------//
//--------------------------------------------------------------------------------//
//push eax // save register values on stack to be safe
//push ecx //
//movzx ecx,temp_char //
//lea eax,EKey //
//call encrypt4 // encrypt the character
//mov temp_char,al //
//pop ecx // restore original register values from stack
//pop eax //
//--------------------------------------------------------------------------------//
//---------------------------------CDECL VERSION----------------------------------//
push eax //save register values on stack
push ecx
@push EKey //save orginal values of parameters
@push temp_char
call encrypt4 //call function
add esp, 8 //clean parameters of stack
mov temp_char, al //move the temporay character into a 8bit register
@pop temp_char //recover register values
@pop EKey
pop ecx
pop eax
//--------------------------------------------------------------------------------//
}
EChars [i] = temp_char; // Store encrypted char in the encrypted chars array
}
return;
这是子例程:
encrypt4:
//-------------------------ORGINAL CODE----------------------------------------------//
//push edi
//push ecx
//not byte ptr[eax]
//add byte ptr[eax], 0x04
//movzx edi, byte ptr[eax]
//pop eax
//xor eax, edi
//pop edi
//rol al, 1
//rol al, 1
//add al, 0x04
//ret
//-----------------------------------------------------------------------------------//
//-------------------------CDECL VERSION---------------------------------------------//
push ebp //save old base pointer value
$mov ebp, esp //set new base pointer value
push edi //destination index register used for string, memory array copying, setting and for far pointer addressing with ES (push EDI onto stack)
push ecx //counter register, used as a loop counter (push 'Char' onto stack)
mov eax, [ebp +8] //move value of parameter 1 into eax
mov ecx, [ebp +12] //move valye of parameter 2 into ecx
not byte ptr[eax] //ones complement negation byte pointer used with the 'EKey' single byte location address
add byte ptr[eax], 0x04 //byte pointer used to add 4 in hexidecimal to the 'EKey' single byte location address
movzx edi, byte ptr[eax] //moves the value of 'EKey' address to EDI using zeros instead of a sign bit
pop eax //pop value of 'character to be encrypted' from stack
xor eax, edi //XOR 'character to be encrypted' with EDI value, this give the 'encrypted value of the source character'(stage 1)
pop ecx //recover register value
pop edi //pop orginal address of EDI from stack
rol al, 1 //rotates the 'encrypted value of the source character' register(stage 2) left by 1 bit, leaves a carry for my test string 'manutd$'
rol al, 1 //rotates the 'encrypted value of the source character' register(stage 3) left by 1 bit, leaves a carry for my test string 'manutd$'
add al, 0x04 //adds 4 in hexidecimal to 'encrypted value of the source character'(final stage)
mov esp, ebp //deallocate values
$pop ebp //restore callers base pointer value
ret //return from procedure
//-----------------------------------------------------------------------------------//
任何将不胜感激。谢谢
push
和pop
不能处理字节。最小大小为 16 位。
要修复第二个警告,您应该在纯汇编函数上使用__declspec(naked)
。
相关文章:
- 警告处理为错误这里有什么问题
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- cppcheck在const std::string[]上引发警告
- GCC对可能有效的代码抛出init list生存期警告
- 如何在BST的这个简单递归实现中消除警告
- 关于std::move的使用,是否有编译警告
- g++ 在某个类成员未初始化时不发出警告
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 使用typeid警告未使用的变量
- 示例C++项目编译中的警告
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- 如何修复编译器警告 C6386 和 C6385?
- 返回语句后的代码,没有警告
- 组装指令中乘法的下部和上部是什么
- 获取隐式转换溢出从无符号到已签名的警告
- 编译器警告:执行到达值返回函数的末尾而不返回值
- 在未链接的部分上生成警告
- 警告 C4552:">>":未使用表达式的结果
- 禁止显示由于常量为零而比较始终为假的警告
- CDECL 调用约定 引起奇怪的警告 组装 X86