Numeros primos en ensamblador
ASSUME cs:PROG,ss:PROG,ds:PROG
ORG 0100h
programa:
jmp codigo
cont2 DB 0
n DB 0
num DW 0
ind DW 1
cont DW 0
divi DB 0
cadDB 7 dup(0)
enun DB 'Introduzca el valor de n: $'
res DB 10,13,'Numeros primos hasta $'
codigo:
mov dx,OFFSET enun
mov ah,09h
int 21h
mov ah,01h
movbx,OFFSET cad
mov n,0
mov cx,4
bucle1:
int 21h
mov [bx],al
cmp al,13
jz listo
inc bx
inc n
loop bucle1
listo:
mov al,10
mov[bx],al
mov al,13
mov [bx+1],al
mov al,36
mov [bx+2],al
cmp n,0
jz codigo
mov dx,OFFSET res
mov ah,09h
int 21h
mov dx,OFFSET cadint 21h
mov al,[bx-1]
sub al,48
xor ah,ah
add num,ax
cmp n,1
jz bucle2
mov al,[bx-2]
sub al,48
mov cl,10
mul cl
addnum,ax
cmp n,2
jz bucle2
mov al,[bx-3]
sub al,48
mov cl,100
mul cl
add num,ax
cmp n,3
jz bucle2
mov al,[bx-4]
sub al,48xor ah,ah
mov cx,1000
mul cx
add num,ax
bucle2:
mov divi,0
mov cont,1
bucle3:
mov ax,ind
xor dx,dx
mov cx,cont
div cx
cmp dx,0jnz no_eq
inc divi
no_eq:
inc cont
mov ax,ind
shr ax,1
cmp cont,ax
jnbe fin3
jmp bucle3
fin3:
cmp divi,1
jnbe mayor
movax,ind
call funcion
inc cont2
cmp cont2,20
jnz mayor
mov ah,00h
int 16h
mov cont2,0
mayor:
inc ind
mov ax,ind
cmp ax,num
jnbefin2
jmp bucle2
fin2:
mov ah,00h
int 16h
mov ah,4ch
mov al,00h
int 21h
funcion PROC NEAR
xor dx,dx
mov cx,1000
div cx
mov cad,al...
Regístrate para leer el documento completo.