I am writing some code that allows me to sum a table and then display its result using assembler language. Here is what I've come up with so far:
data segment
tab db 9 dup(3 5 8 4 7 1 6 7 0)
resultat db ?
data ends
code segment
xor di, di
mov cx, 9
Prog:
mov al, tab[di]
add ax, al
inc di
loop prog
mov resultat ,ax
mov ah, 09h
int 21h
end code
I made some changes in your code and stole proc
number2string
from another answer (full of comments to help you understand) :The proc
number2string
converts to string any number in ax and stores the result in variableresultat
(as it is defined in the data segment).Adding a sequence of BYTEs can be done this way:
This code adds CX=9 BYTE values in DX. The problem is that your "print" function does not work, because function
AH=09h of INT 21h
prints a string in DS:DX and not a number:So to print the number in
DX
you'd have to convert it to a string first.