汇编语言查找1000以内的素数(厄拉多塞筛法)

在这里插入代码片

include Irvine32.inc
big = 1000
small = big / 2
.data
KN byte big dup(0)
jj dword 2
jay dword big dup(0)
chou dword 1
KK dword 1
.code
main proc
  mov ecx,big
L1:push ecx
  inc KK
  mov ecx,1
L2:push ecx
  mov eax,lengthof KN - 1
  mov edx,0
  div KK
  mov jj,2
  mov ecx,eax
L3:
  mov eax,KK
  mov ebx,jj
  mul ebx
  mov KN[eax],1
  inc jj
  cmp KK,small
  je L4
  loop L3
  pop ecx
  loop L2
  pop ecx
  LOOP L1
L4:
  mov edx,offset KN
  mov ebx,offset jay
  mov ecx,big - 1
L6:
  xor dword ptr [edx], 1
  jnp L5
L7:
  add edx,1
  loop L6
  jmp L8
L5:
  mov eax,big
  sub eax,1
  sub eax,ecx
  mov [ebx],eax
  add ebx,4
  jmp L7
L8:
  exit
main endp
end main

你可能感兴趣的:(汇编语言)