2

MASM32で3234567890に5を追加しようとしています。完全なサンプルコードは次のとおりです。

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

符号なしのdwordに何かを追加する正しい方法は何ですか?現在、負の数を取得しており、期待される結果は3234567895です。

更新: 問題は実際に使用されたMACROのどこかにありました。サンプルを最小限に編集しましたが、正しく機能しました。ここに謎はありません。:)

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

みんな、ありがとう!

4

1 に答える 1

1

このレベルでは、乗算と除算の命令を除いて、符号付きと符号なしは実際には同じものであるため、ここでの加算に問題はありません。

私が考えることができる考えられる問題:

  1. 追加の結果は本当にebx?広く使用されている2つの異なる規則があるため、どのオペランドがデスティネーションレジスタであるかについて大きな混乱がありますか?(それが問題の一部であるとしても、それは実際には結果を説明しません。それは5を与えるので、負の数ではありませんが、それでも...)

  2. このフォーラムの投稿では、udw2strの実装の問題について説明しています。

  3. 出力バッファとして使用pbufしていますが、それは十分な大きさではありません。の直前にアセンブラがメモリに配置することに依存していますbuffer

  4. printおそらくclobberebxですか?

この時点で信頼できるデバッガーを引き出し、コードを1ステップ実行します。

于 2011-01-17T16:10:32.453 に答える