使用SUB指令时出现意外输出

时间:2013-02-23 10:26:47

标签: assembly x86 masm subtraction

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

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出现时,00027000的值为0021000。这是怎么回事?

1 个答案:

答案 0 :(得分:2)

您将十六进制数字误认为是十进制数。

30000h = 196608d

9000h = 36864d

196608d - 36864d = 159744d

30000h - 9000h = 27000h = 159744d