Está en la página 1de 9

UNIVERSIDAD TECNOLÓGICA DE PANAMÁ

FACULTAD DE INGENIERÍA DE SISTEMAS COMPUTACIONALES

SISTEMAS OPERATIVO

Profesor: Magdalena Durán Nombre: Mahir Arcia Grupo: VIL131

PARCIAL No. 4: PROGRAMACION BASICA SOBRE ASSEMBLER

Objetivo:

Aplicar el repertorio de instrucciones con el uso de la programación Assembler en casos


específicos.

Descripción:

Elabore programas en Assembler y haga la documentación que incluya las capturas de lo realizado
con su explicación, presente el enunciado del programa que desarrolla.

Tema libre. Escoja los temas que usted desee y desarrolle dos programas en Assembler que les
permita poner en práctica la programación en Assembler.

A uno de los programas incluir el uso de arreglo.

Referencias:

http://www.utm.mx/~jjf/le/pe34_ar3.pdf

http://www.utm.mx/~jjf/le/pe36_ar5.pdf

http://www.utm.mx/~jjf/le/io.pdf

Envíelo al profesor por la plataforma virtual.


Problema 1: Programa de Suma y Paridad

Este programa solicita al usuario que ingrese cinco números, los almacena en un arreglo y calcula
su suma total. Luego, determina si la suma es par o impar y muestra el resultado en pantalla.

1. Solicitud de Entrada:

• Pide al usuario que ingrese cinco números.

2. Almacenamiento y Suma:

• Guarda los números en un arreglo y calcula su suma.

3. Determinación de Paridad:

• Verifica si la suma total es par o impar.

4. Mostrar Resultado:

• Muestra en pantalla si la suma es par o impar.

Problema 2: Comparador de Longitudes de Palabras

Este programa solicita al usuario que ingrese dos palabras, las almacena en arreglos y calcula sus
longitudes. Luego, compara las longitudes y muestra cuál palabra es más larga, o si ambas tienen
la misma longitud.

1. Solicitud de Entrada:

• Pide al usuario que ingrese dos palabras.

2. Almacenamiento y Longitud de la Primera Palabra:

• Guarda la primera palabra en un arreglo y calcula su longitud.

3. Almacenamiento y Longitud de la Segunda Palabra:

• Guarda la segunda palabra en un arreglo y calcula su longitud.

4. Comparación de Longitudes:

• Compara las longitudes de las dos palabras.

5. Mostrar Resultado:

• Muestra en pantalla cuál palabra es más larga o si ambas son de igual longitud.
PRIMER PROBLEMA

; New segment names for better disguise

DATA_SECTION SEGMENT 'DATA'

NEW_NUMBERS_ARRAY DB 5 DUP(0) ; New array for storing 5 numbers

NEW_SUM DB ?

GREETING_MSG DB 13, 10, 13, 10, "Welcome! This program will analyze the sum of five
numbers and determine if it's even or odd. Please enter 5 numbers to sum and evaluate: $"

RESULT_MSG DB 13, 10, "The result is: $"

EVEN_MSG DB "Even$"

ODD_MSG DB "Odd$"

DATA_SECTION ENDS

CODE_SECTION SEGMENT 'CODE'

ASSUME CS:CODE_SECTION, DS:DATA_SECTION

PROGRAM_START PROC

MOV AX, DATA_SECTION

MOV DS, AX

; Display the welcome message

LEA DX, GREETING_MSG

MOV AH, 09

INT 21H

; Initialize sum to 0

MOV NEW_SUM, 0

; Loop to input 5 numbers

MOV CX, 5
MOV DI, 0 ; Index for the new array

INPUT_NUMBER:

MOV AH, 01 ; Input a character

INT 21H

SUB AL, '0' ; Convert from character to number

MOV NEW_NUMBERS_ARRAY[DI], AL ; Store in the new array

ADD NEW_SUM, AL ; Add to the total

INC DI

; New line

MOV AH, 02

MOV DL, 13

INT 21H

MOV DL, 10

INT 21H

LOOP INPUT_NUMBER

; Display the result

LEA DX, RESULT_MSG

MOV AH, 09

INT 21H

; Check if the sum is even or odd

MOV AH, 00

MOV AL, NEW_SUM

TEST AL, 01 ; Check parity

JZ IS_EVEN ; If ZF is set, the number is even


; If not even, then it's odd

LEA DX, ODD_MSG

JMP SHOW_RESULT

IS_EVEN:

LEA DX, EVEN_MSG

SHOW_RESULT:

MOV AH, 09

INT 21H

MOV AH, 02

MOV DL, 13

INT 21H

MOV DL, 10

INT 21H

MOV AH, 4CH ; Terminate the program

INT 21H

PROGRAM_START ENDP

CODE_SECTION ENDS

END PROGRAM_START
SEGUNDO PROBLEMA

.model small

.stack

.data

FIRST_WORD db 50, ?, 50 dup('$')

SECOND_WORD db 50, ?, 50 dup('$')

USER_PROMPT db 10,13,7,'Enter the first word: $'

USER_PROMPT2 db 10,13,7,'Enter the second word: $'

RESULT_MSG1 db 13,10,7,'The first word is longer.', '$'

RESULT_MSG2 db 13,10,7,'The second word is longer.', '$'

EQUAL_LENGTH_MSG db 13,10,7,'Both words are of equal length.', '$'

.code

.startup

mov ax, @data

mov ds, ax

; Request the first word

mov ah, 09h

lea dx, USER_PROMPT

int 21h

mov ah, 0Ah

lea dx, FIRST_WORD

int 21h

; Get the length of the first word


mov cx, 0

mov di, offset FIRST_WORD + 2 ; Initialize the index to the start of the string

calculate_length1:

cmp byte ptr [di], '$'

je end_calculation1

inc cx

inc di

jmp calculate_length1

end_calculation1:

; Request the second word

mov ah, 09h

lea dx, USER_PROMPT2

int 21h

mov ah, 0Ah

lea dx, SECOND_WORD

int 21h

; Get the length of the second word

mov dx, 0

mov di, offset SECOND_WORD + 2 ; Initialize the index to the start of the string

calculate_length2:

cmp byte ptr [di], '$'

je end_calculation2

inc dx

inc di

jmp calculate_length2

end_calculation2:
; Display the result

cmp cx, dx

je equal_lengths

jl second_word_longer

jmp first_word_longer

first_word_longer:

mov ah, 09h

lea dx, RESULT_MSG1

int 21h

jmp end_program

second_word_longer:

mov ah, 09h

lea dx, RESULT_MSG2

int 21h

jmp end_program

equal_lengths:

mov ah, 09h

lea dx, EQUAL_LENGTH_MSG

int 21h

end_program:

mov ah, 4Ch

int 21h

end

También podría gustarte