【问题标题】:x86 assembly programming function callingx86 汇编编程函数调用
【发布时间】:2012-11-06 21:56:53
【问题描述】:

我正在处理 x86 程序集中的函数调用和返回。我似乎无法让它在不崩溃的情况下运行。我从 bit_operations 调用函数 MIRROR_BYTE。但是每次我运行代码时,它都会出现未知错误和崩溃。它仅在我 MIRROR_BYTE 完成后才发生 在这里真的迷路了,感谢您的帮助。完整代码的网址

http://codepaste.net/av7ikf

 __declspec(naked) void
 bit_operations(unsigned long inputDWord, unsigned long *outputDWord)
 {
     __asm{
         // start code for part B here

         push eax
         push ebx

         mov ebx, [esp + 12] 
         push ebx                 //move inputDword into the stack
             call MIRROR_BYTE
         pop ebx                  //pop inputDword out of the stack

         pop ebx
         pop eax

         // end code for part B here
         ret
     }
 }

 /*
     This function takes 4 bytes as input and mirrors the value of Byte 4 (leftmost).
     For example, for a byte like 10110111, the mirrored byte value is 11101101.
 */

 __declspec(naked) unsigned long
 MIRROR_BYTE( unsigned long inputDWord )
 {
     __asm{

     // not sure what to do here just return dummy al from inputDword
     mov al, byte ptr[esp +4]


     }
 }

【问题讨论】:

  • 这个可以,我试试

标签: function assembly x86 callstack


【解决方案1】:

你需要从 MIRROR_BYTE 返回!!!如果没有 ret 或 C 返回,CPU 将在 MIRROR_BYTE proc 之后继续执行代码。

【讨论】:

  • 谢谢你,这就是我所缺少的
【解决方案2】:

请注意,您的pop eax; pop ebx 应反转以匹配之前的push eax; push ebx。不过,不能说这是否会导致您的问题。

【讨论】:

  • 然后使用调试器单步调试代码,看看哪里出错了。
  • 我试过了,但它只是在程序完成镜像字节函数时冻结程序
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-13
  • 1970-01-01
  • 2020-09-23
  • 2019-02-13
  • 2013-04-21
  • 1970-01-01
  • 2014-09-30
相关资源
最近更新 更多