汇编语言: 判断素数

来源:互联网 发布:查看端口有没有被占用 编辑:程序博客网 时间:2024/05/20 10:12
data segmentdata endsstacks segment stackdw 40h dup(?)top label wordstacks endscode segment     assume ds:data,cs:code,ss:stacksmain proc far    mov ax,data    mov ds,ax    mov ax,stacks    mov ss,ax    lea sp,top    mov di,13    call prime    mov dl,bl    add dl,30h    mov ah,02h    int 21h    jmp exit; in di; out bl   (0 no 1 yes)prime proc near    mov cx,2 ; 1和他本身之外l1: xor dx,dx    mov ax,di    div cx      cmp dx,0    je NotPrime    inc cx    cmp cx,di    jb l1    jmp YesPrimeNotPrime:    mov bl,0    retYesPrime:    mov bl,1    retprime endpexit:       mov ah,4ch    int 21hmain endpcode endsend main
原创粉丝点击