Documentos de Académico
Documentos de Profesional
Documentos de Cultura
LENGUAJE ENSAMBLADOR
EJERCICIOS:
SOLUCIONES:
data segment
MENSAJE db "HOLA MUNDO$" ; TODA CADENA SE TERMINARA EN
"escribe_tu_cadena..$"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
mov ax, data
mov ds, ax
mov es, ax
; DX ES UN REGISTRO DE 16 BITS
;......................................
lea dx, MENSAJE ;INSTRUCCION EN LA QUE EN DX ALMACENAMOS LA CADENA
[MENSAJE]
mov ah, 9 ;INSTRUCCION QUE IMPRIME LA CADENA
int 21h ;INTERRUPCION 21H
;---------------------------------------
mov ax, 4c00h ; exit
int 21h
ends
end start ;
ENDM
espacioElineas MACRO cad2
push ax
push dx
lea dx,cad2
mov ah,09h
int 21h
pop dx
pop ax
ENDM
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
MOSTRAR_CADENA men1
;LEEMOS N-------------------------------------------------------
bucle:
call LEER ; en dig esta el numero ascii
cmp dig,0Dh
je salir2
sub dig, 30h
mov al,1010b
mul NN
add al,dig
mov NN,al ; en NN esta el numero fromado
jmp bucle
salir2:
;-------------------------------------------------------
SALTO_LINEA
add NN,01h ;le sumamos una unidad al numero
mov cl,00h ; si es i=0 -- i<n=3
fori:
cmp cl,NN ; n=3 -- i<n
jge endfori
mov ch,00h; di es 'j' ->j=0
forj:
cmp ch,cl ;m=3 -- j<m
jge endforj
;-------------------------------------------------------
cmp sw,00h
je sw0
jne sw1
sw0:
MOSTRAR_NUMERO 02h
mov sw,01h
espacioElineas espacio
jmp salir
sw1:
add impares,03h
imprimirNnum impares,aa,bb
espacioElineas espacio
mov sw,00h
salir:
;-------------------------------------------------------
inc ch ;j++
jmp forj
endforj:;por falso si ponemos esto fuera de exit
; se repetira innitamente
inc cl
jmp fori
endfori:;por falso si ponemos esto fuera de exit
; se repetira innitamente
;exit
mov ax, 4c00h ; exit to operating system.
int 21h
;------------------------------********************----------------
LEER:
mov ah, 01h
int 21h
mov dig,al
ret
ends
; serien 2,5,2,8,2,11,2,14
espacioElineas MACRO cad2
push ax
push dx
lea dx,cad2
mov ah,09h
int 21h
pop dx
pop ax
ENDM
data segment
sw db 00h
n dw 05h ;tamno n
aa db 0 ;unidad
bb db 0 ;decena
impares db 02h
espacio db " $"
men1 db "N=5 $"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
MOSTRAR_CADENA men1
add n,01h ;le sumamos una unidad al numero
mov si,00h ; si es i=0 -- i<n=3
fori:
cmp si,n ; n=3 -- i<n
jge endfori
mov di,00h; di es 'j' ->j=0
forj:
cmp di,si ;m=3 -- j<m
jge endforj
;-------------------------------------------------------
cmp sw,00h
je sw0
jne sw1
sw0:
MOSTRAR_NUMERO 02h
mov sw,01h
espacioElineas espacio
jmp salir
sw1:
add impares,03h
imprimirNnum impares,aa,bb
espacioElineas espacio
mov sw,00h
salir:
;-------------------------------------------------------
inc di ;j++
jmp forj
endforj:;por falso si ponemos esto fuera de exit
; se repetira innitamente
inc si
jmp fori
endfori:;por falso si ponemos esto fuera de exit
; se repetira innitamente
;exit
mov ax, 4c00h ; exit to operating system.
int 21h
;exit
ends
data segment
sw db 00h
n dw 05h ;tamno n
aa db 0 ;unidad
bb db 0 ;decena
impares db 02h
espacio db " $"
men1 db "N=5 $"
pares db 00h
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
MOSTRAR_CADENA men1
add n,01h ;le sumamos una unidad al numero
mov si,00h ; si es i=0 -- i<n=3
fori:
cmp si,n ; n=3 -- i<n
jge endfori
mov di,00h; di es 'j' ->j=0
forj:
cmp di,si ;m=3 -- j<m
jge endforj
;-------------------------------------------------------
cmp sw,00h
je sw0
jne sw1
sw0:
add pares,02h
imprimirNnum pares,aa,bb
mov sw,01h
espacioElineas espacio
jmp salir
sw1:
add impares,03h
imprimirNnum impares,aa,bb
espacioElineas espacio
mov sw,00h
salir:
;-------------------------------------------------------
inc di ;j++
jmp forj
endforj:;por falso si ponemos esto fuera de exit
; se repetira innitamente
inc si
jmp fori
endfori:;por falso si ponemos esto fuera de exit
; se repetira innitamente
;exit
mov ax, 4c00h ; exit to operating system.
int 21h
;exit
ends
; SERIE 1, 2, 3, 5, 5, 8, 7, 11, 9, 14
data segment
sw db 00h
n dw 05h ;tamno n
aa db 0 ;unidad
bb db 0 ;decena
impares3 db 02h
espacio db " $"
men1 db "N=5 $"
impares2 db 01h
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
MOSTRAR_CADENA men1
add n,01h ;le sumamos una unidad al numero
mov si,00h ; si es i=0 -- i<n=3
fori:
cmp si,n ; n=3 -- i<n
jge endfori
mov di,00h; di es 'j' ->j=0
forj:
cmp di,si ;m=3 -- j<m
jge endforj
;-------------------------------------------------------
cmp sw,00h
je sw0
jne sw1
sw0:
imprimirNnum impares2,aa,bb
add impares2,02h
mov sw,01h
espacioElineas espacio
jmp salir
sw1:
imprimirNnum impares3,aa,bb
add impares3,03h
espacioElineas espacio
mov sw,00h
salir:
;-------------------------------------------------------
inc di ;j++
jmp forj
endforj:;por falso si ponemos esto fuera de exit
; se repetira innitamente
inc si
jmp fori
endfori:;por falso si ponemos esto fuera de exit
; se repetira innitamente
;exit
mov ax, 4c00h ; exit to operating system.
int 21h
;exit
ends
data segment
sw db 00h
n dw 05h ;tamno n
aa db 0 ;unidad
bb db 0 ;decena
impares3 db 02h
espacio db " $"
men1 db "N=5 $"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
MOSTRAR_CADENA men1
add n,01h ;le sumamos una unidad al numero
mov si,00h ; si es i=0 -- i<n=3
fori:
cmp si,n ; n=3 -- i<n
jge endfori
mov di,00h; di es 'j' ->j=0
forj:
cmp di,si ;m=3 -- j<m
jge endforj
;-------------------------------------------------------
cmp sw,00h
je sw0
jne sw1
sw0:
MOSTRAR_NUMERO 01h
mov sw,01h
espacioElineas espacio
jmp salir
sw1:
imprimirNnum impares3,aa,bb
add impares3,03h
espacioElineas espacio
mov sw,00h
salir:
;-------------------------------------------------------
inc di ;j++
jmp forj
endforj:;por falso si ponemos esto fuera de exit
; se repetira innitamente
inc si
jmp fori
endfori:;por falso si ponemos esto fuera de exit
; se repetira innitamente
;exit
mov ax, 4c00h ; exit to operating system.
int 21h
;exit
ends
data segment
sw db 00h
n dw 05h ;tamno n
aa db 0 ;unidad
bb db 0 ;decena
pares db 00h
espacio db " $"
men1 db "N=5 $"
pares2 db 01h
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
MOSTRAR_CADENA men1
add n,01h ;le sumamos una unidad al numero
mov si,00h ; si es i=0 -- i<n=3
fori:
cmp si,n ; n=3 -- i<n
jge endfori
mov di,00h; di es 'j' ->j=0
forj:
cmp di,si ;m=3 -- j<m
jge endforj
;-------------------------------------------------------
cmp sw,00h
je sw0
jne sw1
sw0:
imprimirNnum pares,aa,bb
add pares,02h
mov sw,01h
espacioElineas espacio
jmp salir
sw1:
imprimirNnum pares2,aa,bb
add pares2,03h
espacioElineas espacio
mov sw,00h
salir:
;-------------------------------------------------------
inc di ;j++
jmp forj
endforj:;por falso si ponemos esto fuera de exit
; se repetira innitamente
inc si
jmp fori
endfori:;por falso si ponemos esto fuera de exit
; se repetira innitamente
;exit
mov ax, 4c00h ; exit to operating system.
int 21h
;exit
ends
SALTO_LINEA MACRO
PUSH AX
PUSH DX
mov dl, 0dh
mov ah, 02h
int 21h
; salto de linea
mov dl, 0ah
mov ah, 02h
int 21h
POP DX
POP AX
ENDM
MOSTRAR_CADENA MACRO cad
PUSH AX
PUSH DX
LEA DX,cad
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
espacioElineas MACRO cad2
push ax
push dx
lea dx,cad2
mov ah,09h
int 21h
pop dx
pop ax
ENDM
imprimirNUM MACRO numm,uni,dece,cen
push ax
push dx
mov al,numm ; en F<-bl
aam ;ajusta el valor en AL por: AH=23 Y AL=4
mov uni,al ; Respaldo 4 en unidades
mov al,ah ;muevo lo que tengo en AH a AL para poder volver a separar los números
aam ; separa lo qe hay en AL por: AH=2 Y AL=3
mov cen,ah ;respaldo las centenas en cen en este caso 2
mov dece,al ;respaldo las decenas en dec, en este caso 3
;Imprimos los tres valores empezando por centenas, decenas y unidades.
mov ah,02h
mov dl,cen
add dl,30h
int 21h
mov dl,dece
add dl,30h
int 21h
mov dl,uni
add dl,30h
int 21h
pop ax
pop dx
ENDM
data segment
NN db 0 ;tamno n
men1 db "Digite N = $"
aa db 0
bb db 0
cc db 0
dig db 0
espacio db " $"
F db 1h
aux db -1h
a db 1h
fibo db 0
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
mov ax, 4c00h
int 21h
LEER:
mov ah, 01h
int 21h
mov dig,al
ret
ends
end start
data segment
NN db 0
dig db 0
aux db 0
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
bucle:
call leer3 ; en dig esta el numero ascii
cmp dig,0Dh
je salir
sub dig, 30h
mov al,1010b
mul NN
add al,dig
mov NN,al
jmp bucle
mov ax, 4c00h ; exit to operating system.
int 21h
;PROCESOS
salir:
call mostrar3
mov ax, 4c00h
int 21h
ret
mostrar3:
mov cx,08h
bucle2:
rol nn,01h
adc aux,00h
mov dl, aux
add dl,30h
mov ah,02h
int 21h
mov aux,00h
loop bucle2
ret
leer3:
mov ah, 01h
int 21h
mov dig,al
ret
ends
pop dx
pop ax
ENDM
data segment
men1 db " N=15 $"
men2 db " $"
nn dw 0fh
aa db 0
bb db 0
cc db 0
S db 0
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
data segment
N DB 14h
nom db "JOSE ALFONSO RIVERA LIMA $"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
;DIVISION-----------------------------------------------
xor ax,ax ;limpiamos el registro ax.
mov bl,02h ; 2
mov al,N ;el N
div bl ; divide AX/BX el resultado lo almacena en AX, el residuo queda en DX
mov N,al ; en AL esta el resultado de N/2
;--------------------------------------------------
mov cl,N
mov ch,00h
bucle:
lea dx,nom
mov ah,09h
int 21h
cmp cx,00h
sub cx,01h
jnz bucle
mov ax, 4c00h ; exit to operating system.
int 21h
ends
Comentarios
1.
SALTO_LINEA MACRO
PUSH AX
PUSH DX
mov dl, 0dh
mov ah, 02h
int 21h
; salto de linea
mov dl, 0ah
mov ah, 02h
int 21h
POP DX
POP AX
ENDM
MOSTRAR_CADENA MACRO cad
PUSH AX
PUSH DX
LEA DX,cad
MOV AH,09H
INT 21H
POP DX
POP AX
ENDM
espacioElineas MACRO cad2
push ax
push dx
lea dx,cad2
mov ah,09h
int 21h
pop dx
pop ax
ENDM
imprimirNUM MACRO numm,uni,dece,cen
push ax
push dx
mov al,numm ; en F<-bl
aam ;ajusta el valor en AL por: AH=23 Y AL=4
mov uni,al ; Respaldo 4 en unidades
mov al,ah ;muevo lo que tengo en AH a AL para poder volver a separar
los números
aam ; separa lo qe hay en AL por: AH=2 Y AL=3
mov cen,ah ;respaldo las centenas en cen en este caso 2
mov dece,al ;respaldo las decenas en dec, en este caso 3
;Imprimos los tres valores empezando por centenas, decenas y unidades.
mov ah,02h
mov dl,cen
add dl,30h
int 21h
mov dl,dece
add dl,30h
int 21h
mov dl,uni
add dl,30h
int 21h
pop ax
pop dx
ENDM
data segment
NN db 0 ;tamno n
men1 db "Digite N = $"
aa db 0
bb db 0
cc db 0
dig db 0
espacio db " $"
F db 1h
aux db -1h
a db 1h
fibo db 0
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
MOSTRAR_CADENA men1
;LEEMOS N-------------------------------------------------------
bucle:
call LEER ; en dig esta el numero ascii
cmp dig,0Dh
je salir2
sub dig, 30h
mov al,1010b
mul NN
add al,dig
mov NN,al ; en NN esta el numero formado
jmp bucle
salir2:
;-------------------------------------------------------
SALTO_LINEA
;-----------------------------------------------
inc cl ;incremento de cl++
jmp while
finWhile:
LEER:
mov ah, 01h
int 21h
mov dig,al
ret
ends
end start