Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;*******************************************
- ;** Proyecto 2
- ;
- ;**AUTORES**
- ;Gonzalo Martínez Vogt | L.U. 75443
- ;Fernando A. Ristaño | L.U. 76144
- ;
- ;
- ; Para el manejo de pila con los procedimientos, usamos callee save (Cada procedimiento guarda los parametros al arrancar)
- ;
- section .data
- ;********************************************************************
- ;* Constantes de las llamadas al sistema para mejor la lectura
- ;********************************************************************
- sys_exit equ 1
- sys_read equ 3
- sys_write equ 4
- sys_open equ 5
- sys_close equ 6
- sys_creat equ 7
- ;**************************
- ; Constantes para stdrs
- ;**************************
- stdin equ 0
- stdout equ 1
- stderr equ 2
- ;*****************************************************
- ; Constates para el manejo de ficheros
- ;**********************************************
- open_readonly equ 0
- ;********************************************
- ;* Especifición de mensajes de ayuda
- ;*******************************************
- ayuda_linea1 db ' Copyright (C) 2011.', 10
- largo_ayuda_linea1 equ $ - ayuda_linea1 ;Denota el largo de la linea
- ayuda_lineaGPL db ' This is free software and may be redistributed under the terms of the GNU GPL.',10
- largo_ayuda_lineaGPL equ $ - ayuda_lineaGPL
- ayuda_modoUso db ' Modo de uso: enum [-h] [ archivo_entrada | archivo_entrada archivo_salida]',10
- largo_ayuda_modoUso equ $ - ayuda_modoUso
- ;********************************************
- ;* Especifición de mensajes de errores
- ;*******************************************
- msg_no_error db 'Exito', 10
- largo_msg_no_error equ $ - msg_no_error
- msg_error_input db 'Terminacion anormal por error en el archivo de entrada',10
- largo_msg_error_input equ $ - msg_error_input
- msg_error_output db 'Terminacion anormal por error en el archivo de salida',10
- largo_msg_error_output equ $ - msg_error_output
- msg_error_other db 'Terminacion anormal',10
- largo_msg_error_other equ $ - msg_error_other
- ;section .bss
- section .text
- global _start ; Inicio de programa
- global _msg_ayuda ; Muestra el mensaje de ayuda al ingresar con -h
- global _un_parametro ; Procesa el caso de que solo se haya pasado un parametro
- global _leer_stdin_mostrar_stout; Procesa las lineas ingresadas desde stdin y muestra el resultado por stdout
- global _exit_normal ; Salida sin errores
- global _exit_error_input ; Salida anormal por error en el archivo de entrada
- global _exit_error_output ; Salida anormal por error en el archivo de salida
- global _exit_error_other ; Salida anormal por error no especificado
- _start:
- mov edi, 0 ; Inicializo el contador de lineas
- pop eax ; EAX contiene ARGC
- pop ebx ; Leo el nombre de la aplicacion
- cmp eax, 2 ; IF (tiene_exactamente_1_argumento)
- je _un_parametro ; THEN proceso ese parámetro
- ; jg _mas_parametros ; ELSE if(es mayor que 1 parametro) procesa los parametros
- jmp _leer_stdin_mostrar_stout ; ELSE Toda linea ingresada por teclado es procesada y mostrada por pantalla
- ;***********************************************************
- ;* Procesado de parametros de entrada *
- ;***********************************************************
- _un_parametro:
- pop ebx ; Leo el parametro
- mov al, [ebx] ; Leo el primer caracter
- cmp al, '-' ; IF ( NO es '-') //Suponemos que el fichero no comienza con -
- jne _exit_error_input ; THEN leo desde fichero de entrada y muestro a stdout
- ; ELSE Sigo leyendo el segundo caracter
- mov al, [ebx+1] ; Leo el segundo caracter
- cmp al, 'h' ; IF ( es 'h')
- je _msg_ayuda ; THEN muestro mensaje de ayuda y salgo sin errores
- jmp _exit_error_other ; ELSE salgo indicando error en los parametros de entrada
- _leer_stdin_mostrar_stout:
- jmp _exit_normal
- ;***********************************************************
- ;* Muestra de mensajes de ayuda *
- ;***********************************************************
- _msg_ayuda:
- mov eax, 4 ;servicio sys_write
- mov ebx, 1 ;standard output
- mov ecx, ayuda_linea1 ;offset de mensaje
- mov edx, largo_ayuda_linea1
- int 80h ;invocacion al servicio
- mov eax, 4 ;servicio sys_write
- mov ebx, 1 ;standard output
- mov ecx, ayuda_lineaGPL ;offset de mensaje
- mov edx, largo_ayuda_lineaGPL
- int 80h ;invocacion al servicio
- mov eax, 4 ;servicio sys_write
- mov ebx, 1 ;standard output
- mov ecx, ayuda_modoUso ;offset de mensaje
- mov edx, largo_ayuda_modoUso
- int 80h ;invocacion al servicio
- mov eax, sys_exit ; servicio sys_exit
- mov ebx, 0 ; terminacion sin errores
- int 80h ; invocacion al servicio
- ;Termino la aplicacino sin errores
- ; jmp _exit_normal
- ;***********************************************************
- ;* Instrucciones de finalizacion *
- ;***********************************************************
- _exit_normal:
- mov eax, 4 ;servicio sys_write
- mov ebx, 1 ;standard output
- mov ecx, msg_no_error ;offset de mensaje
- mov edx, largo_msg_no_error
- int 80h ;invocacion al servicio
- mov eax, sys_exit ; servicio sys_exit
- mov ebx, 0 ; terminacion sin errores
- int 80h ; invocacion al servicio
- _exit_error_input:
- mov eax, 4 ;servicio sys_write
- mov ebx, 1 ;standard output
- mov ecx, msg_error_input ;offset de mensaje
- mov edx, largo_msg_error_input
- int 80h
- mov eax, sys_exit ; servicio sys_exit
- mov ebx, 1 ; Salida anormal por error en el archivo de entrada
- int 80h ; invocacion al servicio
- _exit_error_output:
- mov eax, 4 ;servicio sys_write
- mov ebx, 1 ;standard output
- mov ecx, msg_error_output ;offset de mensaje
- mov edx, largo_msg_error_output
- int 80h
- mov eax, sys_exit ; servicio sys_exit
- mov ebx, 2 ; Salida anormal por error en el archivo de salida
- int 80h ; invocacion al servicio
- _exit_error_other:
- mov eax, 4 ;servicio sys_write
- mov ebx, 1 ;standard output
- mov ecx, msg_error_other ;offset de mensaje
- mov edx, largo_msg_error_other
- int 80h
- mov eax, sys_exit ; servicio sys_exit
- mov ebx, 3 ; Salida anormal por error no especificado
- int 80h ; invocacion al servicio
- ;section .stack
Add Comment
Please, Sign In to add comment