I tried to solve this project for school and when i use a compiler the final result is some emoticons instead of the sum of digits
I rewrote the entire code, but I get the same result
.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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With