📄 06.asm
字号:
stack segment para stack 'stack'
dw 50 dup(?)
stack ends
data segment
prtl db"The prime number of 2-1000:",0ah,0dh,"$"
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
lea dx,prtl
mov ah,09h
int 21h
mov ah,02h
or dl,32h
int 21h
mov dl,20h
int 21h
mov dl,33h
int 21h
mov dl,20h
int 21h
mov dl,20h
int 21h
mov bp,0 ;显示计数初值
mov dx,0
mov ax,3
disp2: inc ax ;修改被除数
cmp ax,1000
jb next3
jmp next1
next3: mov si,ax
mov bx,ax
shr bx,1 ;bx<-除数最大值
mov cx,2
disp1: mov ax,si
mov dx,0 ;判断被除数是否为素数
div cx
cmp dx,0
je next4 ;余数为0放弃本能测试
inc cx ;除数加1
cmp cx,bx
jbe disp1
jmp next ;在x/2没有查到可整除的数显示
next4: mov ax,si
jmp disp2
next: inc bp ;把素数转换为ASCII码并显示
cmp bp,14 ;控制每显示14个数
jbe next2
mov bp,0
mov ah,02h
mov dl,0ah
int 21h
mov ah,02h
mov dl,0dh
int 21h
next2: mov cx,si
mov dl,0
lp1: cmp cx,03e8h ;找1000位值
jnae lp2
inc dl
sub cx,03e8h
jmp lp1
lp2: or dl,30h
mov ah,02h
int 21h ;显示1000位
mov dl,0
lp3: cmp cx,64h ;找100位的值
jnae lp4
inc dl
sub cx,64h
jmp lp3
lp4: or dl,30h
mov ah,02h
int 21h ;显示100位
mov dl,0
lp5: cmp cx,0ah ;找10位的值
jnae lp6
inc dl
sub cx,0ah
jmp lp5
lp6: or dl,30h
mov ah,02h
int 21h ;显示10位
mov dl,cl
or dl,30h
mov ah,02h
int 21h ;显示个位
mov ax,si
jmp disp2
next1: mov ah,4ch
int 21h
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -