Hi Spoomyfly,
I distinctly remember answering this the other day. Perhaps I shouldn't have made the nasty remark about "Captcha".
org 100h
mov ax, 780 ;testing number
mov bx, 1 ;first prime number to divide
petla:
cmp ax, 1 ;if testing number less than 1 break
jbe Break
; I'm thinking we don't want to increment bx in
; some circumstances.
; If ax is not 1, we may want to try the same bx.
; but we do want to increment bx if bx was 1.
; Do we want to start with bx=2?
ja again ; if ax is not yet 1, try the same bx?
inc bx
again:
mov cx, ax ;saving number in cx
mov dx, 0
div bx
mov ax, cx
test dx, dx ;is there any remainder
jnz petla ;if no - change divisor
push ax ;
mov ax, bx
call Show_AX
pop ax
push ax
push dx
mov ah, 09h
lea dx, [CrLf]
int 21h
pop dx
pop ax
;do "petla" until we get a remainder
Divide:
mov cx, ax
mov dx, 0
div bx
jmp petla
Break:
mov ax, 4c00h
int 20h
; strictly speaking, if we're going to use int 20h
; we don't need 4ch in ah.
; perhaps better to use int 21h here.
; this isn't actually a problem
Show_AX:
push ax
push bx
push cx
push dx
push di
mov cx, 10
xor di, di
or ax, ax
jns Conv
push ax
mov dx, '-'
mov ah, 2
int 21h
pop ax
neg ax
Conv:
xor dx, dx
div cx
add dl, '0'
inc di
push dx
or ax, ax
jnz Conv
Show:
pop dx
mov ah, 2
int 21h
dec di
jnz Show
pop di
pop dx
pop cx
pop bx
pop ax
ret
; X dw 15 ;testing number as a variable
CrLf db 0Dh, 0Ah, '$'
Unfortunately, I'm not in a position to test this conveniently at the moment. I may have steered you into an infinite loop, or worse. I don't think my first answer was any better. I think I suggested letting it only print a factor once, but that isn't really what you want (?). In any case, I'm pretty sure if you skip incrementing bx "sometimes" it'll do what you want.
Sorry for the untested code.
Best,
Frank