EJERCICIOS EMSAMBLER
-
Upload
richard-milton-yarlaque-santisteban -
Category
Documents
-
view
229 -
download
4
description
Transcript of EJERCICIOS EMSAMBLER
;;;;; imprime una cadena (impcad)
codigo segment
assume cs:codigo, ds:datos
entrada: mov ax, datos
mov ds,ax
mov dx, offset texto
mov ah, 09h
int 21h
mov ah,4ch
int 21h
codigo ends
datos segment
texto db "esta cadena ha sido", 0ah, 0dh
db "definida en un segmento de datos $"
datos ends
end entrada
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; imprime una cadena (men4)
CODIGO2 SEGMENT
ASSUME CS:CODIGO2, DS:CODIGO2
ENTRADA2: MOV AX,CS
MOV DS,AX
MOV DX, OFFSET TEXTO2
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
TEXTO2 DB "IMPRIME CADENA, VERSION 2 ", 0AH,0DH,"$"
CODIGO2 ENDS
END ENTRADA2
;;;;;;;;;;;;;;;;;;;;;;;;;;
; compara dos cadenas ingresadas x teclado
datos segment
texto db "Ingrese cadena: $"
noigual db "cadenas no son iguales $"
siigual db "cadenas son iguales $"
buf db 40 dup (?)
buf1 db 40 dup (?)
datos ends
cod segment
assume cs:cod , ds:datos
ini: mov ax,datos
mov ds,ax
mov dx, offset texto
mov ah,09h
int 21h
mov ah,0ah
mov dx,offset buf
mov bx,dx
mov byte ptr [bx],0fh
int 21h
mov cl,byte ptr [bx+1]
mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dx, offset texto
mov ah,09h
int 21h
mov ah,0ah
mov dx,offset buf1
mov si,dx
mov byte ptr [si],0fh
int 21h
;mov al,byte ptr [si+1]
cmp byte ptr [si+1],cl
jne no_igual
add bx,2
add si,2
repetir:
; mov al,byte ptr[bx]
mov dl,byte ptr[si]
cmp byte ptr[bx],dl
jne no_igual
inc si
inc bx
cmp buf1[si],0dh
je igual
jmp repetir
igual:
mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dx, offset siigual
mov ah,09h
int 21h
jmp fin
no_igual:
mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dx, offset noigual
mov ah,09h
int 21h
fin: mov ah,4ch
int 21h
cod ends
end ini
;;;;;;;;;;;;;;;;;;;
; cuenta la cantidad de palabras
datos segment
texto db " Ingrese cadena: $"
texto1 db " La cantidad de palabras en la cadenas son: $"
buf db 180 dup (?)
datos ends
cod segment
assume cs:cod , ds:datos
ini: mov ax,datos
mov ds,ax
mov dx, offset texto
mov ah,09h
int 21h
mov ah,0ah
mov dx,offset buf
mov si,dx
mov byte ptr [si],20h;32
int 21h
mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov cx,1
add si,2
bucle: mov al,byte ptr[si]
inc si
cmp buf[si],0dh
je fin
cmp al,20h
jne bucle
inc cx
jmp bucle
fin:
mov dx, offset texto1
mov ah,09h
int 21h
add cx,48
mov dl,cl
mov ah,2h
int 21h
mov ah,4ch
int 21h
cod ends
end ini
;;;;;;;;;;;;;;;;;;;;;;
compara con el 1,
datos segment
texto db "Ingrese numero de un digito comparado con 1: $"
buf db 4 dup (?)
datos ends
cod segment
assume cs:cod , ds:datos
ini: mov ax,datos
mov ds,ax
mov dx, offset texto
mov ah,09h
int 21h
mov ah,0ah
mov dx,offset buf
mov si,dx
mov byte ptr [si],2
int 21h
mov ch,0 ;sub ch,ch
mov cl,[si+2]
sub cl,"0"
cmp cx,1
jb menor
ja mayor
je igual
menor: mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dl,3ch
mov ah,2h
int 21h
mayor: mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dl,3eh
mov ah,2h
int 21h
jmp fin
igual: mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dl,3dh
mov ah,2h
int 21h
jmp fin
fin: mov ah,4ch
int 21h
cod ends
end ini
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;emite un mensaje ya definido en
; el segmento de datos (mensaje)
datos segment
texto db "esta cadena ha sido",0ah,0dh
db "definida en un segmento d datos$"
datos ends
cod segment
assume cs:cod , ds:datos
ini: mov ax,datos
mov ds,ax
mov dx, offset texto
mov ah,09h
int 21h
mov ah,4ch
int 21h
cod ends
end ini
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; compara dos numeros ya definidos
codigo segment
assume cs:codigo
inicio: mov ax,5
mov bx,3
cmp ax,bx
je igual
ja mayor
je igual
jb menor
mayor: mov dl,3eh
mov ah,2h
int 21h
jmp fin
igual: mov dl,3dh
mov ah,2h
int 21h
jmp fin
menor: mov dl,3ch
mov ah,2h
int 21h
fin: mov ah,4ch
int 21h
codigo ends
end inicio
;;;;;;;;;;;;;;;;;;;;;;;
; imprimir del 0-9 linea por linea(numeros)
codigo segment
assume cs:codigo
inicio: mov dl,30h
mov ah,2h
otra_vez: int 21h
mov bl,dl
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dl,bl
cmp dl,39h
je fin
inc dl
jmp otra_vez
fin: mov ah,4ch
int 21h
codigo ends
end inicio
;;;;; ingresar un numero
; y saber si es primo o no (primox)
datos segment
texto db "Ingrese numero: $"
buf db 40 dup (?)
num dw 0
mensaje1 db "es primo",0ah,0dh,"$"
mensaje2 db "no es primo",0ah,0dh,"$"
datos ends
programa segment
assume cs:programa, ds:datos
comienzo: mov ax,datos
mov ds,ax
mov dx, offset texto
mov ah,09h
int 21h
mov ah,0ah
mov dx,offset buf
mov si,dx
mov byte ptr [si],5
int 21h
mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov cl,48
mov ax,0
mov dl,10
mov bx,0
add si,2
bucle: mov al,byte ptr[si]
sub al,cl
; add bx,ax
inc si
cmp byte ptr[si],0dh
je finb
mul dl
mov bx,ax
mov ax,0
jmp bucle
finb: add bx,ax
mov ax,bx
mov num,ax
mov bx,02h
siguiente: cmp bx,num
je primo
mov dx,0h
mov ax,num
div bx
cmp dx,0h
je no_primo
inc bx
jmp siguiente
primo: mov dx, offset mensaje1
mov ah,09h
int 21h
jmp fin
no_primo: mov dx,offset mensaje2
mov ah,09h
int 21h
fin: mov ah, 4ch
int 21h
programa ends
end comienzo
;;imprimr letras de la a-f
;prog2
codigo segment
assume cs:codigo
inicio: mov dl,41h
mov ah,2h
otra_vez: int 21h
cmp dl,46h
je fin
inc dl
jmp otra_vez
fin: mov ah,4ch
int 21h
codigo ends
end inicio
;;imprimir de a-g
;linea x linea (prog23)
codigo segment
assume cs:codigo
inicio: mov dl,41h
mov ah,2h
otra_vez: int 21h
mov bl,dl
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dl,bl
cmp dl,47h
je fin
inc dl
jmp otra_vez
fin: mov ah,4ch
int 21h
codigo ends
end inicio
;; raiz cuadrada de un
; numero ya definido (raiz)
datos segment
num dw 9
raiz dw 0
datos ends
programa segment
assume cs:programa, ds:datos
comienzo: mov ax,datos
mov ds,ax
sig: inc raiz
mov ax,raiz
mul ax
cmp ax,num
jbe sig
dec raiz
mov ax,raiz
add al,30h
mov dl,al
mov ah,2h
int 21h
fin: mov ah, 4ch
int 21h
programa ends
end comienzo