0

我不知道为什么这个程序不能输出

+1 +2 +3 +4

输出是

+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

谢谢你的回答<(__)>

4

1 回答 1

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
...

我不建议初学者在不了解确切生成的代码的情况下使用其汇编程序的花哨功能。

于 2012-12-06T12:38:18.287 回答