为什么我得到另一个结果?

Rob*_*kov 3 assembly dos x86-16

我试图为学校解决这个项目,当我使用编译器时,最终结果是一些图释而不是数字总和

我重写了整个代码,但是得到了相同的结果

.model small  
.stack 100h  
.data 
nstr db 6 dup(' ') 
idv dw 10 
a dw 2  
b dw 9  
c dw 6 
x dw ?  ;x=a+b+c
d dw 7 
e dw 5 
y dw ?  ;y=d+e
z dw ?  ;z=x+y
.code 
.start 
mov ds, ax  
; x = a+b+c 
mov ax, a 
add ax, b 
add ax, c  
mov x, ax 
; y = d+e

mov ax, d 
add ax, e 
mov y, ax 
; z = x+y

mov ax, x 
add ax, y 
mov z , ax 
mov si,5  
mov nstr[si], '$' 
dec si 


mov ax, z 
mov dx,0

loop1: ; 
div idv  

;
add dl, '0'  
mov nstr[si],dl 

dec si 

mov dx,0 


cmp ax,0 
jne loop1  

listn:  
mov ah, 09h 
mov dx, offset nstr ;
int 21h 

stopprg:  
mov ah, 4ch 
int 21h 

end
Run Code Online (Sandbox Code Playgroud)

Mic*_*tch 5

The .start directive will produce code that will initialize the segments for the model you have chosen (in this case small). You overwrite DS with whatever happens to be in AX with mov ds, ax. That will point the data segment to a place in memory that doesn't contain your data (like nstr, idv, a ... z etc) producing incorrect results. To fix simply remove this line:

mov ds, ax
Run Code Online (Sandbox Code Playgroud)