So I came across one example in my box for assembly 8086 and i could use some help with completing the code
So example goes like this: there is an array of integers, calculate number of even elements in the array
.model small
.stack
.data
arr dw 10 dup (1,2,3,4,5,6,7,8,9,10)
msg db 'number of even elements is:', '$'   ;;
.code
;printing
print proc a:word
        push bp
        mov bp, sp
        mov ax, a
        mov cx, 10
        mov bx, 0
        cmp ax, 0  
        jne begin
        mov dl, 0
        add dl, '0'
        mov ah, 2
        int 21h
        jmp toend
    begin: 
        cmp ax, 0
        je print
        mov dx, 0
        div cx
        push dx
        inc bx
        jmp begin
    print:   
        cmp bx, 0
        je kraj
        pop dx
        add dl, '0'
        mov ah, 2
        int 21h
        dec bx
        jmp print
toend:
        mov dl, 10 
        mov ah, 2
        int 21h
        pop bp
        ret 2
print endp
main:
    mov ax, @data
    mov ds, ax
    mov ax, ;number
    call print
    jmp fin
I looked at some previous code and somehow tried to make this work..
So my question is am I at right path at all, should I use idiv instruction or?
EDIT: I can't seem to get anything else beside "21243" as a result, and by the way i tried to calculate some other things and got lost in the process,here's the complete code:
; there is an array of integers.  calculate the number of
; even elements in the array.
.model small
.stack
.data
arr dw 10 dup (1,2,3,4,5,6,7,8,9,10)
msg db 'Average (in procents): ', '$'
msg1 db 'Average of even elements: ', '$'
msg2 db 'Sum  is:', '$'  ;;
msg3 db 'Number of even elements is :', '$'   ;;
limit dw ? ; length * 2, because we save dw (length of 2 bytes)
number dw 2345     ;;
sum dw 0   ;;
.code
print proc a:word
        push bp
        mov bp, sp
        mov ax, a
        mov cx, 10
        mov bx, 0
        cmp ax, 0  
        jne begining
        mov dl, 0
        add dl, '0'
        mov ah, 2
        int 21h
        jmp toend
    begining:
        cmp ax, 0
        je print
        mov dx, 0
        div cx
        push dx
        inc bx
        jmp begining
    print:  
        cmp bx, 0
        je toend
        pop dx
        add dl, '0'
        mov ah, 2
        int 21h
        dec bx
        jmp print
toend:
        mov dl, 10
        mov ah, 2
        int 21h
        pop bp
        ret 2
print endp
main:
    mov ax, @data
    mov ds, ax
    mov ax, number
    call print
    jmp fin
    shl ax, 1           ;mul 2
    mov limit, ax
    mov bx, 0
    mov cx, 2
poc:
    cmp bx, limit
    je k
    mov ax, arr[bx]
    ;mov dx, 0 ;
    ;div cx    ;
    cwd
    idiv cx  ;signed division
    cmp dx, 0
    jne  jumpp
    mov ax, number
    inc ax
    mov number, ax
    mov ax, sum
    add ax, arr[bx]
    mov sum, ax
jumpp:
    add bx, 2 ;because 'length' of elements is 2 bytes
    jmp poc
k:
    mov ax, 100
    mov bx, number
    mul bx
    mov dx, 0     ; xor dx, dx
    mov bx, length arr  ; length of array = 10 so this is mov bx, 10
    div bx    
    mov es, ax
    mov dl, offset msg
    mov ah, 9
    int 21h
    mov ax, es
    push ax
    call print
    ; mov dl, offset msg2
    ; mov ah, 9
    ; int 21h
    mov ax, sum
    push ax
    call print
    ; mov dl, offset msg3
    ; mov ah, 9
    ; int 21h
    mov ax, number
    push ax
    call print
    ; mov dl, offset msg1
    ; mov ah, 9
    ; int 21h
    mov ax, sum
    mov dx, 0
    cwd
    mov bx, number
    cmp bx, 0
    je here
    idiv number
    push ax
    call print
    jmp fin
here:
    mov dl, 0
    add dl, '0'
    mov ah, 2
    int 21h
fin:
    mov ah, 4ch
    int 21h
end main
 
    