Untitled

 avatar
unknown
plain_text
2 years ago
1.1 kB
6
Indexable
.model small
.data
msg db "Enter Binary Value: $"
msg1 db "Output: $"
even_msg db "Even$"
odd_msg db "Odd$"

.code
main proc
    mov ax, @data
    mov ds, ax

    mov ah, 9
    lea dx, msg
    int 21h

    mov bx, 0
    mov cx, 16

input_:
    mov ah, 01h
    int 21h
    cmp al, 13 ; cmp AL, 0DH
    je output_

    and al, 0Fh
    shl bx, 1
    or bl, al
    loop input_

output_:
    mov dl, 10 ; MOV DL, 0DH
    mov ah, 2
    int 21h
    mov dl, 13 ; MOV DL, 0AH
    int 21h
    mov ah, 9
    lea dx, msg1
    int 21h

    ; Count the number of '1's
    mov cx, 16   ; MAXIMUM 16 INPUT
    mov ax, bx
    mov dx, 0
count_ones_loop:
    test ax, 1
    jz zero
    inc dx
zero:
    shr ax, 1
    loop count_ones_loop

    ; Check if the count is even or odd
    test dl, 1
    jz even_count
    jmp odd_count

even_count:
    ; Print "Even"
    mov ah, 9
    lea dx, even_msg
    int 21h
    jmp exit_program

odd_count:
    ; Print "Odd"
    mov ah, 9
    lea dx, odd_msg
    int 21h

exit_program:
    ; Exit the program
    mov ah, 4Ch
    int 21h

end main
Editor is loading...
Leave a Comment