[Tema de ensamblaje] 48 Cómo juzgar si un número entero que no exceda 65535 es un número primo

Instrucción de montaje Nombre en inglés

Precauciones

  1. Tenga en cuenta el uso de instrucciones de saltoje(jump when equal)

Código fuente

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

Supongo que te gusta

Origin blog.csdn.net/qq_43874964/article/details/109723109
Recomendado
Clasificación