You are on page 1of 18

Ejercicios Ensamblador Unidad II

Instrucciones: Forme Grupos de 5 personas y desarrolle cada uno de los ejercicios propuestos a continuacin. El cdigo deber estar ordenado y completamente documentado, explicando el propsito de cada sentencia. Fecha de presentacin: jueves, 10 de Junio del 2011. 1. Crear un programa que asigne un valor al Registro DX y muestre en pantalla si es par o impar 2. Crear un programa que permita multiplicar VAR1 por VAR2, utilizando el mtodo de sumas sucesivas, almacenado el resultado en la variable RESULTADO (prohibido utilizar MUL). Las variables sern inicializadas en cdigo. 3. Crear un programa que permita dividir VAR1 entre VAR2, utilizando el mtodo de Euclides (prohibido utilizar DIV). Las variables sern inicializadas en cdigo. Almacenar COCIENTE y RESTO. 4. Codificar el algoritmo que dadas 2 variables T1 y T2. Asigne el valor correspondiente a las variables MAYOR y MENOR. 5. Crear un programa que les de la bienvenida a partir de leer sus apellidos y Nombres. 6. Crear un programa que calcule el factorial de un nmero (del 0 al 9) contenido en la variable NumA y lo almacene en la variable Factorial. 7. Crear un programa que muestre la serie de Fibonacci: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 8. Codificar un programa que permita calcular X elevado a la N y almacenarlo en Potencia, variables inicializadas en cdigo. 9. Crear un programa que compare 2 cadenas (comparar letra por letra) y muestre la mayor (cadenas inicializadas en cdigo). 10. Codificar el algoritmo que permita sumar 2 vectores, VectorA y VectorB, de 15 elementos cada uno y almacene el resultado en el vector Suma. 11. Codificar el algoritmo que permita multiplicar 2 vectores, VectorA y VectorB, de 10 elementos cada uno y almacene el resultado en Producto. 12. Codificar un programa que permita leer 5 nmeros enteros (de 1 digito) y muestre su promedio (basta con mostrar el cociente).

Resultados: EJERCICIO N1: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" msnPar db "Numero Par ", 10, 13, "$" msnImpar db "Numero Impar ", 10, 13, "$" Dividendo dw 350 ; Divisor db 2 ; 0..255 ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here ; mov dx, 0 mov dx, Dividendo ; Asigna "Dividendo" a "dx" (asi lo pide el enunciado) mov ax, bx ; Asignamos "dx" a "ax" para realizar la division mov bl, Divisor ; asignamos el "Divisor" a "bl" div dl ; realizamos la division: ax/dl ; cociente se guarda en "al" ; resto se guarda en "ah" Inicio_si: cmp ah, 0 ; compara "ah" (el resto) con 0, si son iguales ; el "flag Z" asume el valor de 1 JZ Verdadero ; JZ: salta a "Verdadero" si "flag Z" es 1

Falso: ; Numero Impar lea dx, msnImpar mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h JMP Fin_Si Verdadero: ; Numero par lea dx, msnPar mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h Fin_Si:

lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler.

EJERCICIO N2: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" VAR1 dw 10 VAR2 dw 5 RESULTADO dw 0 ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here MOV AX, 0 MOV CX, VAR2 Repetir: ADD AX, VAR1 LOOP Repetir MOV RESULTADO, AX

lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h

mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler.

EJERCICIO N4: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" t1 db 5 t2 db 6 mayor db ? menor db ? ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here mov bl,t1 mov dl,t2 cmp bl,dl jg almayor jl almenor almayor: mov mayor,bl

mov menor,dl jmp fin almenor: mov mayor,dl mov menor,bl

fin: lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler. EJERCICIO N 5: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$"

msg1 db " Ingresa tus Datos: $" s1 db 100,?, 100 dup(' ') msg db ' de un .....Bienvenida.....', 0 ;msg" a db print_new_line macro ;msg agrega " Permite el ingreso

mov dl, 13 mov ah, 2 int 21h mov dl, 10 mov ah, 2 int 21h endm

ends stack segment dw 128 dup(0) ends code segment start: mov ax, data mov ds, ax mov es, ax

mov dx, offset msg1 mov ah, 9 int 21h ;cierra el estring mov dx, offset s1 mov ah, 0ah int 21h ; muestar la palabra actual: xor cx, cx mov cl, s1[1] print_new_line mov bx, offset s1[2] print_char: mov dl, [bx] mov ah, 2 int 21h

inc bx loop print_char print_new_line mov next_char: mov al, msg[si] ;mueve msg[si]+0 si, 0 ;Mueve 0 a si.

cmp al, 0 ; je stop ; hace un alto a cada letra mov ah, 0eh ;Mueve 0eh a ah int 10h ; muestar en pantalla la letra inc jmp si ; inicialisa si ; salta a nex_char

next_char

stop: mov ah, 0 ; espera a que presine una tecla mov ax, 4c00h ; exit to operating system. int 21h ret ends end start ; set entry point and stop the assembler. EJERCICIO N 6: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" NumA dw 6 Factorial dw 0

ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here MOV AX, 1 MOV BX, NumA MOV CX, NumA Repetir: MUL BX sub BX,1 LOOP Repetir MOV Factorial, AX lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler.

EJERCICIO N7: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" var dw 10 resultado dw 0 ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here Mov AX,0 ;AX=0 Mov BX,1 ;BX=1 Estos son los dos primeros elementos 0+1=1 Mov CX,10 ;Repetir 10 veces Repite: Mov DX,AX ;DX=AX Add DX,BX ;DX=AX+BX Mov AX,BX ;Avanzar AX Mov BX,DX ;Avanzar BX Loop Repite ;siguiente nmero mov resultado, AX lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1

int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler. EJERCICIO N8: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" NumX dw 7 NumN dw 3 Potencia dw 0 ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here MOV AX, 1 MOV BX, 0 MOV CX, NumN Repetir: MUL NumX LOOP Repetir MOV Potencia, AX

lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler.

EJERCICIO N 10: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" VectorA db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 VectorB db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 Suma db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here mov cx,15 ;movemos a cx el valor de las repeticiones requeridas

mov SI, 0 ;inicializamos en 0 nuestro puntero SI

Repetir: mov al, VectorA[SI] ; movemos el valor de la posicion indicada del vector a "al" mov bl, VectorB[SI] ; movemos el valor de la posicion indicada del vector a "bl" add al, bl ; agregamos bl a al(suma) mov Suma[SI],al; movemos el resultado de la sum a la posicion indicada del vector inc SI ; incrementamos en 1 Loop Repetir

lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler. EJERCICIO N 11: ; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" VectorA db 1,2,3,4,5,4,3,2,1,1

VectorB db 1,2,3,4,5,4,3,2,1,1 Producto 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 ; add your code here MOV dl, 0 mov cx,10 ;movemos a cx el valor de las repeticiones requeridas mov SI, 0 ;inicializamos en 0 nuestro puntero SI

Repetir: mov al, VectorA[SI] ; movemos el valor de la posicion indicada del vector a "al" mov bl, VectorB[SI] ; movemos el valor de la posicion indicada del vector a "bl" mul bl add dl,al inc SI ; incrementamos en 1 Loop Repetir mov Producto,dl

lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1

int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler.

EJERCICIO 12 ; multi-segment executable file template.

data segment ; add your data here! pkey db "press any key...$"

Array db 10,5,8,7,3 Suma db 0 Promedio db 0 ends

stack segment dw ends 128 dup(0)

code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax

; add your code here

mov cx,5 ;inicializando en 5 repeticiones mov SI,0 ; inicializamos en 0 el puntero mov bl,0 ;inicializamos en 0 bl

Repetir:

mov al,Array[SI] ;movemos al al valor de la posicion indicada add bl ,al ; mov Suma,bl inc SI

Loop Repetir

mov ax,0 ; limpiamos ax mov bx,0 ; limpiamos bx

mov al,Suma mov bl,5

;movemos el valor de Suma a al como diviendo

;movemos 5 al bl como divisor

div bl

;dividimos(el cociente se guarda en al y el residuo en ah)

mov Promedio,al ;movemos el cociente a promedio

lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx

; wait for any key.... mov ah, 1 int 21h

mov ax, 4c00h ; exit to operating system. int 21h ends

end start ; set entry point and stop the assembler.

You might also like