How to print an array in DOS x86 assembly?


I have this code to copy the array "NUMBERS" to "DEST" such that no number will repeat (in this case it should be : 1,2,5,4,7) The code works but now I need to print the array "DEST". How can I do that ?

data segment
NUMBERS db 1,2,1,1,1,5,5,4,7,7
DEST dt ?
data ends

code segment
assume ds:data, cs:code
start: mov ax, data
       mov ds, ax
                   mov ax, 0a0ah
                   mov di, offset NUMBERS
                   mov bx, 0h

             loop2:mov cl, [di]
                   mov si, offset DEST
                   mov ch, [si]
             loop1:cmp ch, cl
                   je dontadd
                   inc si
                   mov ch, [si]
                   dec ah
                   jnz loop1
                   mov si, offset DEST
                   add si, bx
                   inc bx
                   mov [si], cl
           dontadd:mov ah, 0ah
                   inc di
                   dec al
                   jnz loop2

       mov ah, 4ch
       int 21h
code ends
end start


You can use INT 21h, AH=02h to print a single character to STDOUT.

 MOV CX,10
 MOV DL,[si]

 JE done

 ADD DL,'0'  ; 
By : vhu

First convert numbers to string then print them.You can use this two macros for printing numbers:

printstr macro str
push ax
push dx
lea dx,str
mov ah,9
int 21h
pop dx
pop cx

printnum macro n
local o,w,s,n5,lb1,lb2,lb3
push si
push di
jmp w
s db 7 dup('$')
mov si,0
mov cx,7
o:mov s[si],'$'
inc si
loop o
mov si,0
xor ax,ax
mov ax,n
xor dx,dx
cmp ax,0
jge n5
mov bl,'-'
mov s[si],bl
inc si
neg ax
n5:mov cx,10
div cx
or dl,30h
mov s[si],dl
xor dx,dx
inc si
cmp ax,0
jne n5
mov si,0
cmp s[si],'-'
jne lb1
inc si
lb1:mov di,si
lb3:cmp s[si],'$'
je lb2
mov al,s[si]
push ax
inc si
jmp lb3
lb2:pop ax
mov s[di],al
inc di
cmp di,si
jl lb2
printstr s
pop di
pop si 
By : Ahmad

This video can help you solving your question :)
By: admin