EJERCICIOS EMSAMBLER

17
;;;;; 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

description

GGG

Transcript of EJERCICIOS EMSAMBLER

Page 1: 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

Page 2: EJERCICIOS EMSAMBLER

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

Page 3: EJERCICIOS EMSAMBLER

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

Page 4: EJERCICIOS EMSAMBLER

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

Page 5: EJERCICIOS EMSAMBLER

;;;;;;;;;;;;;;;;;;;

; 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

Page 6: EJERCICIOS EMSAMBLER

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

Page 7: EJERCICIOS EMSAMBLER

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

Page 8: EJERCICIOS EMSAMBLER

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

Page 9: EJERCICIOS EMSAMBLER

; 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

Page 10: EJERCICIOS EMSAMBLER

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

Page 11: EJERCICIOS EMSAMBLER

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

Page 12: EJERCICIOS EMSAMBLER

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

Page 13: EJERCICIOS EMSAMBLER

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

Page 14: EJERCICIOS EMSAMBLER

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

Page 15: EJERCICIOS EMSAMBLER

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

Page 16: EJERCICIOS EMSAMBLER

mov dl,al

mov ah,2h

int 21h

fin: mov ah, 4ch

int 21h

programa ends

end comienzo