2012-07-31 32 views
0

我剛開始玩弄MASM風格的大會,玩了足夠長的時間後,做了一個循環。這只是從修補,所以我想知道是否有人可以給我任何洞察力和解釋,如果這種代碼效率低下或如何改進。任何方式使此片段更有效?

.386 
.model flat, stdcall 
option casemap:none 
include \masm32\include\windows.inc 
include \masm32\include\masm32.inc 
include \masm32\include\user32.inc 
includelib \masm32\lib\masm32.lib 
includelib \masm32\lib\user32.lib 

.data 
MsgBxTitle db "Loop Step", NULL 

.data? 
Buff dd ? 
MsgBxBody dd ? 

.code 
start: 
XOR eax,eax 
MOV Buff, eax 
lp: 
invoke dw2hex, Buff, addr MsgBxBody 
invoke MessageBox, NULL, addr MsgBxBody, addr MsgBxTitle, MB_OKCANCEL 
.IF eax==IDCANCEL 
RET 
.ENDIF 
INC Buff 
CMP Buff,10 
JL lp 
RET 
end lp 
invoke ExitProcess, NULL 
end start 
+0

定義高效。 :-)我看到少於10條機器指令,所以沒有太多需要切斷的地方,是嗎? – 2012-07-31 23:21:25

+0

效率我的意思是無論如何,我應該格式化我的代碼,或者我應該使用任何更好的方法來實現相同的結果,例如較小的代碼 - >相同的結果 – 2012-07-31 23:33:46

回答

0

可以刮16個字節斷碼這種方式。清零一個寄存器並將其推送爲零。爲你的dword緩衝區使用一個寄存器。使用寄存器組裝成較小的操作碼,比內存(標籤)「更快」。

我個人不喜歡/使用高層次的東西。

start: 
    xor  edi, edi 
    xor  esi, esi 
    mov  ebx, 10 
lp: 
    push offset MsgBxBody 
    push edi 
    call dw2hex 

    push MB_OKCANCEL 
    push offset MsgBxTitle 
    push offset MsgBxBody 
    push esi 
    call MessageBox 
    test eax, IDCANCEL 
    jnz  Done 

    inc  edi 
    dec  ebx 
    jns  lp 

Done: 
    push esi 
    call ExitProcess 
end start 
+0

這真的很酷,謝謝。 – 2012-08-17 12:59:32

0

當用MessageBox顯示結果時,我沒有看到效率或性能是相關的。我對你的控制流程有疑問。 「RET」打算返回到哪裏?如果有的話,是否調用了ExitProcess?我不知道什麼是「部LP」呢,所以也許我失去了一些東西......

最佳, 弗蘭克