Jump to content

Numeros Primos 1 a 20 assembly

Recommended Posts


Boas pessoal!

estou aqui com umas duvidas relativamente ao programa referido acima que passo a mostra a seguir:

; prime.asm
; calculo dos numeros primos de 1 até 20

include "emu8086.inc"

org 100h

jmp CodeStart


        max dw 20
    space db " ", 0

    mov bx, 1  
    ;chama o procedimento eprimo e faz a verificao
    call eprimo
    ;comparacao com 0
    cmp dx, 0
    ;se igual a 0 salta para endLoop
    je EndLoop 
    ;se nao for igual a zero continua o programa
     mov ax, bx
    call print_num
    ; print a space
    mov si, offset space
    call print_string
    add bx, 1 
    cmp bx, max

    jle LoopStart

eprimo PROC  
        ;usa o ciclo loop para ver se o numero em bx e primo
        ;upon return if bx not prime dx will be 0, otherwise dx > 0
        ;we only have to test divisors from 2 to bx/2
        ;prepare to divide dx:ax / 2
        mov ax, bx   
        mov dx, 0
        mov cx, 2 
        div cx
        ; move result into si for loop
        mov si, ax
    ; assume the value is prime
    mov dx, 1
    ; start loop at 2
    mov cx, 2
    ; compare loop count(in cx) and max loop value (in si)
    cmp cx, si
    ; jump out of loop if count(cx) > si
    ja StopLabel
    ; divide test value (in bx) by loop count (in cx)
    mov ax, bx
    mov dx, 0           
    div cx  
    ; increment count
    add cx, 1
    ; check remainder (in dx), if zero then we found a divisor
    ; and the number cannot be prime
    cmp dx, 0
    jmp PrimeLoop

eprimo ENDP


neste programa ele deveria mostrar os números primosde 1 até 20 mas mostra o 1 2 3 5 7 9 11 13 15 17 19.

apenas deveria mostrar 2 3 5 7 11 13 17 19 tendo assim o 1 e o 15 a mais.

alguém da uma ajuda?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.