我是装配新手,并且一直坚持使用这个程序,其中使用了一个简单的添加功能,它接受两个输入并给出总和。 我现在得到的输出总是0。 我认为这与数据类型的处理方式有关。 任何帮助表示赞赏。
注意:程序在没有功能的情况下工作正常
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
msg1 db "Please enter first number ",0
msg2 db "Pleae enter second number ",0
input1 db 10 DUP(0)
input2 db 10 DUP(0)
sum dword 0
sums db 10 DUP(0)
msg3 db "The sum of your numbers is :",0
temp1 dword 0
temp2 dword 0
fsum PROTO :dword, :dword, :dword
.code
start:
invoke StdOut , addr msg1
invoke StdIn , addr input1,10
invoke StdOut , addr msg2
invoke StdIn , addr input2,10
;Strip CRLF
invoke StripLF, addr input1
invoke StripLF, addr input2
;string to int
invoke atodw, addr input1
mov temp1,eax
invoke atodw , addr input2
mov temp2,eax
;Function CALL
invoke fsum, addr temp1,addr temp2,addr sum
;int to string
invoke dwtoa,sum, addr sums
;Printing OUTPUT
invoke StdOut, addr msg3
invoke StdOut, addr sums
invoke ExitProcess, 0
;Function Definition
fsum PROC x:DWORD , y:DWORD , z:DWORD
mov eax,x
add eax,y
mov z,eax
ret
fsum endp
end start
答案 0 :(得分:0)
通过地址传递前两个参数毫无意义。当你只能返回结果时,输出参数也没有任何实际意义。
因此,更合理的方法是:
invoke fsum, temp1, temp2
; The sum is now in eax
...
fsum PROC x:DWORD , y:DWORD
mov eax,x
add eax,y
ret
fsum endp
如果你绝对坚持输出参数,你仍然需要做一些小改动:
; First two arguments are passed by value; last one by address
invoke fsum, temp1,temp2,addr sum
...
fsum PROC x:DWORD , y:DWORD , z:DWORD
mov eax,x
add eax,y
mov edx,z ; Get the address to write to
mov [edx],eax ; ..and write to it.
ret
fsum endp