Variable in memory not updated by a store to that

2020-04-27 08:18发布

问题:

When I run the emu8086, this result(ans) return to me 0 ..Why ?

data segment
ans dw ? 
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
mov ax,@data
mov dx,ax
mov ax,2
mov bl,2
mul bl
mov ans,ax
mov ax, 4c00h
int 21h  
ends
end start

回答1:

mov ax,@data
mov dx,ax

This part of the code must setup the DS segment register.
You made a typo and wrote DX instead!

mov ax, @data
mov ds, ax

Because of this error, the result of your AL * BL multiplication (4) was still written in memory by mov ans,ax but it didn't make it to the data segment. It overwrote the first word of the ProgramSegmentPrefix because that was where DS was pointing at.