我正在尝试在 MASM32 中将 5 添加到 3234567890。这是完整的示例代码:
;--------------------------------------------------------------------------
include \masm32\include\masm32rt.inc
.data
;--------------------------------------------------------------------------
.code
start:
call main ; branch to the "main" procedure
exit
main proc
local pbuf: DWORD
local buffer[32]: BYTE
mov pbuf, ptr$(buffer)
mov ecx, uval("5") ; converting string to unsigned dword and storing in ecx
mov ebx, uval("3234567890") ; converting string to unsigned dword and storing in ebx
invoke udw2str, ebx, pbuf ; converting unsigned value to string and storing results in pbuf
print pbuf, 13,10 ; everything is fine so far - 3234567890
add ecx, ebx
invoke udw2str, ebx, pbuf ; once again coverting
print pbuf, 13,10 ; negative number
ret
main endp
end start ; Tell MASM where the program ends
向 unsigned dword 添加内容的正确方法是什么?现在我得到负数,预期结果是 3234567895。
更新: 问题确实出在使用的宏中。我已经将样本编辑到最低限度并且它工作正常。这里没有什么神秘之处。:)
;--------------------------------------------------------------------------
include \masm32\include\masm32rt.inc
.data
;--------------------------------------------------------------------------
.code
start:
call main ; branch to the "main" procedure
exit
main proc
local pbuf: DWORD
local buffer[40]: BYTE
local nNumber: DWORD
mov pbuf, ptr$(buffer)
mov ecx, 5 ; no need to convert anything at this point
mov ebx, 3234567890 ; no need to convert anything at this point
add ebx, ecx
invoke udw2str, ebx, pbuf ; now converting result in ebx to the string (pointed by pbuf)
print pbuf, 13, 10 ; printing pbuf, success
ret
main endp
end start ; Tell MASM where the program ends
感谢大家!