2013-02-23 30 views
0

我正在用MASM编写程序来创建和减去三个32位整数。我的问题是,从30000减去9000似乎导致27000,当21000预计。源如下:使用SUB指令时出现意外输出

TITLE Add and Subtract 

; This program adds and subtracts 32-bit integers. 

.386 
.model flat,stdcall 
.stack 4096 
ExitProcess PROTO, dwExitCode:DWORD 
DumpRegs PROTO 

.code 
main PROC 

    mov eax,50000h   ; EAX = 50000h 
    mov ebx,30000h   ; EBX = 30000h 
    mov ecx,43h    ; ECX = 43h 

    sub eax,10000h   ; EAX = 40000h 
    sub ebx,9000h   ; EBX = 21000h 
    sub ecx,1h    ; ECX = 42h 

    call DumpRegs 

    INVOKE ExitProcess,0 
main ENDP 
END main 

DumpRegs结果如下:

Unexpected result

如图所示,EBX的值是000270000021000预期。这里发生了什么?

+0

您是否熟悉十六进制? – 2013-02-23 10:33:07

+0

@OliCharlesworth:我是。我没有意识到'h'表示十六进制格式。 – 2013-02-23 10:34:23

回答

2

错误十进制数字的十六进制数字。

30000h = 196608d

9000h = 36864d

196608d - 36864d = 159744d

30000h - 9000h = 27000h = 159744d

+0

啊,这很有道理!谢谢! – 2013-02-23 10:31:33