2012-12-06 38 views
0

我不知道爲什麼這種方案不能輸出(32位組件)通指針PROC

輸出是

+4214784 + 1967600538 + 2130567168 +1638356

我想這是地址,但爲什麼?如何糾正它?

這裏是我的代碼:

include irvine32.inc 

.data 
    matrix dword 1, 2, 3, 4 

.code 
    print proto, m:ptr dword 

    main proc 
    invoke print, addr matrix 

    exit 
    main endp 

    print proc, m:ptr dword 
    mov eax, m[0 * type m] 
    call writeint 

    mov eax, m[1 * type m] 
    call writeint 

    mov eax, m[2 * type m] 
    call writeint 

    mov eax, m[3 * type m] 
    call writeint 

    ret 
    print endp 

    end main 

謝謝您的回答<(__)>

回答

0

m是在棧上傳遞一個指針。彙編程序會將m變成[ebp+8]之類的東西。索引將訪問堆棧上的項目,從那個位置開始,這不是你想要的。您需要取消引用m指針,只有在將其加載到寄存器中時才能執行該指針。

mov ecx, m ; this will be mov ecx, [ebp+8] or similar 
mov eax, [ecx + 0*4] ; first item 
call WriteInt 
mov eax, [ecx + 1*4] ; second item 
call WriteInt 
... 

我不建議初學者使用他們的彙編程序的花哨功能,而不理解代碼的精確生成。