In the following code
data segment
; add your data here!
num db 0,0,0,0
sum db 0
str db "Sum is : $"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
;;read array from input
mov cx,4;set loop counter
L1:
mov ah,7;interupt 7 use for reading character without echo
int 21h
mov num,al;mov al to num
add sum,al
inc num;nex element
LOOP L1
sub num,4;go to first position
;;;;;;;;;;;;;;;;;;;;;;;;
;;show sum
lea dx,str;;-----------------I'm changing this line-----------------------
mov ah,9;interupt 9 for writing string
int 21h
;;;;;;;;;;;
mov ax, 4c00h ; exit to operating system.
int 21h
ends
end start ; set entry point and stop the assembler.
if I change dx to ax
lea dx,str --> lea ax,str
The out put become 1 'Sum is
But if I use lea ax,str
It is correct > Sum is :
I cant figure out the reason !
Why changing dx to ax causes the wrong output ?
You should not randomly exchange AX for DX. The DOS function to print a string uses DX and that's final!
From your program I see that nothing you do with inputting and summing has any effect on the string you display afterwards.
If with your assembler mov num,al
changes the content at the address of 'num' then the line inc num;nex element
will certainly not advance to the next element but rather augment the content by 1. The same applies to sub num,4;go to first position