Guest User

Untitled

a guest
Apr 18th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ;*******************************************
  3. ;** Proyecto 2
  4. ;
  5. ;**AUTORES**
  6. ;Gonzalo Martínez Vogt | L.U. 75443
  7. ;Fernando A. Ristaño  | L.U. 76144
  8. ;
  9. ;
  10. ; Para el manejo de pila con los procedimientos, usamos callee save (Cada procedimiento guarda los parametros al arrancar)
  11. ;
  12.  
  13. section .data
  14.     ;********************************************************************
  15.     ;* Constantes de las llamadas al sistema para mejor la lectura
  16.     ;********************************************************************
  17.     sys_exit    equ 1
  18.     sys_read    equ 3
  19.     sys_write   equ 4
  20.     sys_open    equ 5
  21.     sys_close   equ 6
  22.     sys_creat   equ 7
  23.    
  24.     ;**************************
  25.     ; Constantes para stdrs
  26.     ;**************************
  27.     stdin      equ 0
  28.     stdout     equ 1
  29.     stderr     equ 2
  30.  
  31.     ;*****************************************************
  32.     ; Constates para el manejo de ficheros
  33.     ;**********************************************
  34.      open_readonly  equ 0
  35.  
  36.         ;********************************************
  37.         ;* Especifición de mensajes de ayuda
  38.         ;*******************************************
  39.     ayuda_linea1        db  '    Copyright (C) 2011.', 10
  40.     largo_ayuda_linea1  equ $ - ayuda_linea1            ;Denota el largo de la linea
  41.     ayuda_lineaGPL      db  '    This is free software and may be redistributed under the terms of the GNU GPL.',10
  42.         largo_ayuda_lineaGPL    equ $ - ayuda_lineaGPL
  43.     ayuda_modoUso       db  '    Modo de uso: enum [-h] [ archivo_entrada | archivo_entrada archivo_salida]',10
  44.         largo_ayuda_modoUso     equ $ - ayuda_modoUso
  45.  
  46.     ;********************************************
  47.     ;* Especifición de mensajes de errores
  48.     ;*******************************************
  49.     msg_no_error        db  'Exito', 10
  50.     largo_msg_no_error  equ $ - msg_no_error
  51.         msg_error_input     db  'Terminacion anormal por error en el archivo de entrada',10
  52.         largo_msg_error_input   equ $ - msg_error_input
  53.         msg_error_output        db  'Terminacion anormal por error en el archivo de salida',10
  54.         largo_msg_error_output  equ $ - msg_error_output
  55.         msg_error_other     db  'Terminacion anormal',10
  56.         largo_msg_error_other   equ $ - msg_error_other
  57.  
  58.  
  59.  
  60.  
  61.  
  62. ;section .bss
  63.  
  64. section .text
  65.     global _start           ; Inicio de programa
  66.     global _msg_ayuda       ; Muestra el mensaje de ayuda al ingresar con -h
  67.  
  68.     global _un_parametro        ; Procesa el caso de que solo se haya pasado un parametro
  69.     global _leer_stdin_mostrar_stout; Procesa las lineas ingresadas desde stdin y muestra el resultado por stdout
  70.  
  71.     global _exit_normal     ; Salida sin errores
  72.     global _exit_error_input    ; Salida anormal por error en el archivo de entrada
  73.     global _exit_error_output   ; Salida anormal por error en el archivo de salida
  74.     global _exit_error_other    ; Salida anormal por error no especificado
  75.  
  76.    
  77.     _start:
  78.         mov edi, 0          ; Inicializo el contador de lineas
  79.         pop eax             ; EAX contiene ARGC
  80.         pop ebx             ; Leo el nombre de la aplicacion
  81.         cmp eax, 2          ; IF (tiene_exactamente_1_argumento)
  82.         je _un_parametro        ; THEN proceso ese parámetro
  83. ;       jg _mas_parametros      ; ELSE if(es mayor que 1 parametro) procesa los parametros 
  84.         jmp _leer_stdin_mostrar_stout       ; ELSE Toda linea ingresada por teclado es procesada y mostrada por pantalla   
  85.        
  86.        
  87.  
  88.         ;***********************************************************
  89.         ;* Procesado de parametros de entrada                      *
  90.         ;***********************************************************
  91.     _un_parametro: 
  92.         pop ebx             ; Leo el parametro
  93.         mov al, [ebx]           ; Leo el primer caracter
  94.         cmp al, '-'             ; IF ( NO es '-')  //Suponemos que el fichero no comienza con -
  95.         jne _exit_error_input       ; THEN leo desde fichero de entrada y muestro a stdout
  96.                         ; ELSE Sigo leyendo el segundo caracter
  97.         mov al, [ebx+1]         ; Leo el segundo caracter
  98.         cmp al, 'h'             ; IF ( es 'h')
  99.         je _msg_ayuda           ; THEN muestro mensaje de ayuda y salgo sin errores
  100.         jmp _exit_error_other       ; ELSE salgo indicando error en los parametros de entrada
  101.  
  102.  
  103.         _leer_stdin_mostrar_stout:
  104.         jmp _exit_normal
  105.  
  106.  
  107.  
  108.  
  109.  
  110.     ;***********************************************************
  111.     ;* Muestra de mensajes de ayuda                            *
  112.     ;***********************************************************
  113.     _msg_ayuda:
  114.                 mov eax, 4                      ;servicio sys_write
  115.                 mov ebx, 1                      ;standard output
  116.                 mov ecx, ayuda_linea1           ;offset de mensaje
  117.                 mov edx, largo_ayuda_linea1
  118.                 int 80h                         ;invocacion al servicio
  119.                 mov eax, 4                      ;servicio sys_write
  120.                 mov ebx, 1                      ;standard output
  121.                 mov ecx, ayuda_lineaGPL         ;offset de mensaje
  122.                 mov edx, largo_ayuda_lineaGPL
  123.                 int 80h                         ;invocacion al servicio
  124.                 mov eax, 4                      ;servicio sys_write
  125.                 mov ebx, 1                      ;standard output
  126.                 mov ecx, ayuda_modoUso           ;offset de mensaje
  127.                 mov edx, largo_ayuda_modoUso
  128.                 int 80h                         ;invocacion al servicio
  129.                 mov eax, sys_exit               ; servicio sys_exit
  130.                 mov ebx, 0                      ; terminacion sin errores
  131.                 int 80h                         ; invocacion al servicio
  132.                         ;Termino la aplicacino sin errores
  133. ;       jmp _exit_normal
  134.        
  135.  
  136.  
  137.     ;***********************************************************
  138.     ;* Instrucciones de finalizacion                           *
  139.     ;***********************************************************
  140.  
  141.     _exit_normal:
  142.                 mov eax, 4                  ;servicio sys_write
  143.                 mov ebx, 1                  ;standard output
  144.                 mov ecx, msg_no_error       ;offset de mensaje
  145.         mov edx, largo_msg_no_error
  146.                 int 80h                     ;invocacion al servicio
  147.         mov eax, sys_exit       ; servicio sys_exit
  148.         mov ebx, 0          ; terminacion sin errores
  149.         int 80h             ; invocacion al servicio
  150.  
  151.         _exit_error_input:
  152.                 mov eax, 4                      ;servicio sys_write
  153.                 mov ebx, 1                      ;standard output
  154.                 mov ecx, msg_error_input           ;offset de mensaje
  155.                 mov edx, largo_msg_error_input
  156.                 int 80h    
  157.                 mov eax, sys_exit               ; servicio sys_exit
  158.                 mov ebx, 1                  ; Salida anormal por error en el archivo de entrada
  159.                 int 80h             ; invocacion al servicio
  160.  
  161.         _exit_error_output:
  162.                 mov eax, 4                      ;servicio sys_write
  163.                 mov ebx, 1                      ;standard output
  164.                 mov ecx, msg_error_output           ;offset de mensaje
  165.                 mov edx, largo_msg_error_output
  166.                 int 80h    
  167.                 mov eax, sys_exit               ; servicio sys_exit
  168.                 mov ebx, 2                  ; Salida anormal por error en el archivo de salida
  169.                 int 80h             ; invocacion al servicio
  170.  
  171.         _exit_error_other:
  172.                 mov eax, 4                      ;servicio sys_write
  173.                 mov ebx, 1                      ;standard output
  174.                 mov ecx, msg_error_other           ;offset de mensaje
  175.                 mov edx, largo_msg_error_other
  176.                 int 80h    
  177.                 mov eax, sys_exit               ; servicio sys_exit
  178.                 mov ebx, 3                  ; Salida anormal por error no especificado
  179.                 int 80h                     ; invocacion al servicio
  180.  
  181.  
  182.  
  183. ;section .stack
Add Comment
Please, Sign In to add comment