当前位置: 代码迷 >> 汇编语言 >> 请帮小弟我解释一上这个汇编:shl eax,0
  详细解决方案

请帮小弟我解释一上这个汇编:shl eax,0

热度:5254   发布时间:2013-02-26 00:00:00.0
请帮我解释一下这个汇编:shl eax,0
我写了一个测试内联函数的C++程序,然后反汇编看是否存在函数调用,但是红色这些地方我不是很懂,希望大家帮我看看:

以下是我写的源代码:
#include <iostream>
#include <cmath>
using namespace std;

void boxVolume( int length = 1, int width = 1, int height = 1 );
inline void boxVolume( int length, int width, int height )
{
int vol;
vol = length * width * height;


int main()
{
boxVolume();

boxVolume(10);

  boxVolume(10,5);

boxVolume(10,5,2);
return 0;


主函数内反汇编得到的代码是:
boxVolume();
01151027 mov eax,1  
0115102C shl eax,0 我不懂的是这里是左移0位,既然是左移0位,干嘛还要写出了,不是等于不做吗??到底什么意思?
0115102F mov dword ptr [ebp-4],eax  

boxVolume(10);
01151032 mov ecx,0Ah  
01151037 shl ecx,0
0115103A mov dword ptr [ebp-8],ecx  

  boxVolume(10,5);
0115103D mov edx,0Ah  
01151042 imul edx,edx,5  
01151045 mov dword ptr [ebp-0Ch],edx  

boxVolume(10,5,2);
01151048 mov eax,0Ah  
0115104D imul eax,eax,5  
01151050 shl eax,1  
01151052 mov dword ptr [ebp-10h],eax

------解决方案--------------------------------------------------------
因为是反汇编,当代码里面含有伪代码等时,反汇编代码会按照操作码+操作数的方式把它译成对应的汇编代码.这主要是因为汇编代码中的dd,dw,db等等伪代码,不是x86保留的操作码,所以就没有对应的操作码,反汇编后,看起来就像一些无意义的代码.比如那个shl eax,0看起来就像没意义一样,实际上应该是有用的.还有一种可能是这句代码在执行一种特殊操作,只是我们没用过这个功能而已.
------解决方案--------------------------------------------------------
楼主用的什么编译器?我用 vc2008 没有这些吗?
Assembly code
_TEXT    SEGMENT_main    PROC; File m:\kc1.cpp; Line 13    push    ebp    mov    ebp, esp; Line 14    push    1    push    1    push    1    call    ?boxVolume@@YGXHHH@Z            ; boxVolume; Line 16    push    1    push    1    push    10                    ; 0000000aH    call    ?boxVolume@@YGXHHH@Z            ; boxVolume; Line 18    push    1    push    5    push    10                    ; 0000000aH    call    ?boxVolume@@YGXHHH@Z            ; boxVolume; Line 20    push    2    push    5    push    10                    ; 0000000aH    call    ?boxVolume@@YGXHHH@Z            ; boxVolume; Line 21    xor    eax, eax; Line 22    pop    ebp    ret    0_main    ENDP; Function compile flags: /Odtp_TEXT    ENDS;    COMDAT ?boxVolume@@YGXHHH@Z_TEXT    SEGMENT_vol$ = -4                        ; size = 4_length$ = 8                        ; size = 4_width$ = 12                        ; size = 4_height$ = 16                        ; size = 4?boxVolume@@YGXHHH@Z PROC                ; boxVolume, COMDAT; Line 7    push    ebp    mov    ebp, esp    push    ecx; Line 9    mov    eax, DWORD PTR _length$[ebp]    imul    eax, DWORD PTR _width$[ebp]    imul    eax, DWORD PTR _height$[ebp]    mov    DWORD PTR _vol$[ebp], eax; Line 10    mov    esp, ebp    pop    ebp    ret    12                    ; 0000000cH?boxVolume@@YGXHHH@Z ENDP                ; boxVolume_TEXT    ENDS
------解决方案--------------------------------------------------------
探讨楼主用的什么编译器?我用 vc2008 没有这些吗?
  相关解决方案