0

This code is written in x86 assembly language and appears to find the maximum sum of even digits in an array of words. It defines two procedures: "addev" for calculating the sum of even digits in a word and "maxArray" for finding the word in the array with the maximum sum of even digits. The array and its length are passed as parameters to "maxArray," which iterates through the array, calculates the sum of even digits for each word using the "addev" procedure, and keeps track of the word with the maximum sum. Finally, it returns the word with the maximum sum of even digits in ax.

.model small
.stack 100h
.data
A dw 1489, 32661, 31248, 24788, 13499, 28
N dw 6
.code
mov ax, @data
mov ds, ax
push offset A
push N
call maxArray


.exit
addev proc near
    push bp
    mov bp, sp
    mov ax, [bp + 4]
    mov bx, 10
    mov cx, 0
next:
    mov dx, 0
    div bx
    mov dh, dl
    and dl, 1
    jnz cont
    mov dl, dh
    mov dh, 0
    add cx, dx
cont:
    cmp ax, 0
    jne next
    mov ax, cx
    mov ah, 0
    pop bp
    ret 2
addev endp

maxArray proc near
    push bp
    mov bp, sp
    mov bx, 0
    mov cx, 0
    mov di, [bp + 6]
    mov si, di 
next1:
    push bx
    push [di]
    call addev
    pop bx
    pop [di]
    mov bx, [di]
    inc di
    inc di
    cmp cl, [bp + 4]
    je ext
    cmp ch, al
    ja cont2
    cmp ch, al
    jne check
    cmp bx, [si]
    jae cont2
    mov si, di
cont2:
    inc cl
    cmp cl, [bp + 4]
    jmp next1
check:
    mov ch, al
    jmp cont2
ext:
    mov ax, [si] 
    pop bp
    ret 4
maxArray endp
end

i tried to debugg it and it doesnt show any value in ax it only shows that ax is equal to 0

New contributor
P.I.S is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.