am developing an assembly language program that will check whether an inputted number is divisible by 3 or not, now I am struggling to get things correct but my code is running..and it seems like dx register always have content zero even after div has been executed..

 org 100h

jmp main

msg_prpt:     db 'Enter a number (1-9): $'
msg_err:      db 0dh, 0ah, 'Number out of range. $'

msg_1:     db 0dh, 0ah, 'Number is divisible by 3. $'
msg_2:     db 0dh, 0ah, 'Number is not divisible by 3. $'

num:          db ?
num1 dw ?

display:
    mov ah, 9h              ; "display string" function for int 21h
    int 21h
    ret

dsp_prpt:
    mov dx, msg_prpt        ; copy contents of msg_prompt to dx 
    call display

    ret

dsp_err:
    mov dx, msg_err         ; copy contents of msg_err to dx
    call display
    ret

get_num:
     mov ah, 1h              ; "character input" function for int 21h (stored in al)
    int 21h
    mov [num], al           ; copy contents of al to space at address [num] 
    mov num1,num
    ret 


;checking if the inputted number is divisible by 3  
validateDivisibleby3:

     mov dx,0
     mov ax,num             ; copy character to ax for comparison  
     mov bx,03h
     idiv bx
     cmp dx,0
     je isMultipleof3:   
     call isNotMultipleof3
    ret



convert:
    sub al, 30h             ; subtract 30h from input to get numeric from ascii
    ret

isMultipleof3:
; print the result:
 mov dx, msg_1       ; copy contents of msg_prompt to dx
    call display
    ret
isNotMultipleof3:
; print the result:
 mov dx, msg_2       ; copy contents of msg_prompt to dx
    call display
    ret  
exit:

; wait for any key press:
mov ah, 0
int 16h

ret   ; return control to operating system.
main: 
    call dsp_prpt
    call get_num
    call validateDivisibleby3
    call convert
    call exit

I will really appreciate your help..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.