[Assembly Topic] 48 How to judge whether an integer not exceeding 65535 is a prime number

Assembly instruction English name

Precautions

  1. Note the use of jump instructionsje(jump when equal)

Source code

assume cs:codes,ds:datas

;description
datas SEGMENT 
    yes db 'Yes','$'
    no db 'No','$'
    buf dw 60000
datas ENDS


;description
codes SEGMENT 
start:
    mov ax,datas
    mov ds,ax

    mov bx,buf
    dec bx
next:
    cmp bx,1
    je yes0             ;if bx=1, then jump 
    mov ax,buf          
    mov dx,0
    div bx              ;buf/bx,余数存在dx中
    cmp dx,0            
    je no0              ;如果余数为0,跳转并输出No
    dec bx              ;bx自减一
    jmp next            ;继续循环
no0:
    lea dx,no
    mov ah,09h
    int 21h
    jmp exit
yes0:
    lea dx,yes
    mov ah,09h
    int 21h
    jmp exit
exit:
    mov ah,4ch
    int 21h
codes ENDS
    end start

Guess you like

Origin blog.csdn.net/qq_43874964/article/details/109723109