title Is specified num complete number
stack segment para stack 'stack'
dw 32 dup(0)
stack ends
dataseg segment para 'data'
k dw 0
COMPLETE db "complete",'$'
NOTCOMPLETE db "not complete",'$'
num dw 26
dataseg ends
codsg segment para 'code'
main proc far
assume cs:codsg,ds:dataseg,ss:stack
    mov ah,6h ;clear the screen
    mov al,25
    mov ch,0
    mov cl,0
    mov dh,24
    mov dl,79
    mov bh,7
    int 10h ;end of clearing
    mov bx,num
    mov cx,bx
    mov dx,bx
  l1:mov ax,bx
    dec cx
    cmp cx,0
    jnz  l2
    div cx
    cmp ah,0
    jz l2
    add k,cx
    jmp l1
  l2:cmp bx,k;compare the sumation with the num
    jz l3
    mov dl,COMPLETE;print message
    mov ah,9h
    int 21h
    jmp l4
  l3:mov dl,NOTCOMPLETE;print message
    mov ah,9h
    int 21h
    main endp
    codsg ends
    end main

Posted on 2005-07-02 08:33:03 by silvercover
i believe the problem may lie in the line:
div cx
This leaves the remainder in dx; ah would contain the remainder after a div r8, such as div cl or div ch.

i think there may also have something to do with the
add k,cx
cmp bx,k
jz l3

i think what you're trying to do here (but i could be wrong) is testing to see if the divisors of the number are 1 and itself, though it doesn't appear to do that (also, the number is never tested against itself since cx is decremented on entry to the loop.

The line jnz l2 also causes the program to end the first time it enters the loop if dw!=1.? It should probably say:
dec cx
cmp cx,1
jz l2

Hope that helps; i don't have an assembler to test this with  ;)
Posted on 2005-07-02 10:04:34 by jademtech
I coded a relatively nice and optimized solution for generating random 32 and 16bit prime numbers
The IsPrimeNum function takes a DWORD and returns true or false Prime or Not.

The source code is FASM.
But I have the awful habit of not using macros in my code and data sections so it should be very easy to port/translate to masm.

There's the link hope it's relevant.
Posted on 2005-07-02 20:13:35 by r22