Error en programa en Ensamblador

Páginas: (1/1)

michellcrh:

Hola, estoy haciendo este programa en ensamblador para métodos de ordenamiento. Pero después de mostrar el menú me muestra el error de Violaciòn de segmento ('core' generado)
Me podrìan ayudar a saber en dónde está el error por favor?

Código
--
section .data
--
 msg1 db "Ingrese 5 números presionando [Enter] entre cada uno de ellos" , 10
--
 len1 equ $-msg1
--
 
--
 msg2 db "***MÉTODOS DE ORDENAMIENTO DISPONIBLES***", 10
--
 len2 equ $-msg2
--
 
--
 msg3 db "1. INSERTION SORT", 10
--
 len3 equ $-msg3
--
 
--
 msg4 db "2. SELECTION SORT", 10
--
 len4 equ $-msg4
--
 
--
 msg5 db "3. BUBBLE SORT", 10
--
 len5 equ $-msg5
--
 
--
 msg6 db "Ingrese el número correspondiente al método de ordenamiento deseado:", 10
--
 len6 equ $-msg6
--
 
--
 msg7 db 0xA
--
 len7 equ $-msg7
--
 
--
 array db 0,0,0,0,0
--
 la equ $-array
--
 
--
section .bss
--
 res resb 10
--
 
--
 
--
section .text
--
 global _start
--
 
--
   _start:
--
 
--
      ;Mostrar mensaje 1
--
      mov eax,4
--
      mov ebx,1
--
      mov ecx, msg1
--
      mov edx, len1
--
      int 0x80
--
 
--
      mov esi, array
--
      mov edi, 0
--
 
--
      call lee
--
 
--
 
--
      ;SALTO DE LÍNEA
--
      mov eax, 4
--
      mov ebx, 1
--
      mov ecx, msg7
--
      mov edx, len7
--
      int 0x80
--
 
--
      jmp menu
--
 
--
      jmp end
--
 
--
 
--
 
--
 
--
   ;--------------------------------------------------------------
--
   lee:
--
push ebp
--
mov ebp, esp
--
 
--
;Almacenamos los 5 números
--
    num:
--
mov eax, 3
--
mov ebx, 0
--
mov ecx, res
--
mov edx, 10
--
int 0x80
--
 
--
mov esi, res
--
call atoi
--
mov [res], eax
--
 
--
mov al, [res]
--
 
--
mov [esi], al
--
inc edi
--
inc esi
--
cmp edi, la
--
jb num
--
 
--
pop ebp
--
ret
--
 
--
   ;----------------------------------------------------------------
--
   menu:
--
      ;MOSTRANDO MENÚ
--
      ;Mostrar mensaje 2
--
      mov eax,4
--
      mov ebx,1
--
      mov ecx, msg2
--
      mov edx, len2
--
      int 0x80
--
 
--
      ;SALTO DE LÍNEA
--
      mov eax, 4
--
      mov ebx, 1
--
      mov ecx, msg7
--
      mov edx, len7
--
      int 0x80
--
 
--
      ;Mostrar mensaje 3
--
      mov eax,4
--
      mov ebx,1
--
      mov ecx, msg3
--
      mov edx, len3
--
      int 0x80
--
 
--
      ;Mostrar mensaje 4
--
      mov eax,4
--
      mov ebx,1
--
      mov ecx, msg4
--
      mov edx, len4
--
      int 0x80
--
 
--
      ;Mostrar mensaje 5
--
      mov eax,4
--
      mov ebx,1
--
      mov ecx, msg5
--
      mov edx, len5
--
      int 0x80
--
 
--
      ;SALTO DE LÍNEA
--
      mov eax, 4
--
      mov ebx, 1
--
      mov ecx, msg7
--
      mov edx, len7
--
      int 0x80
--
 
--
      ;Mostrar mensaje 6
--
      mov eax,4
--
      mov ebx,1
--
      mov ecx, msg6
--
      mov edx, len6
--
      int 0x80
--
 
--
      ;SALTO DE LÍNEA
--
      mov eax, 4
--
      mov ebx, 1
--
      mov ecx, msg7
--
      mov edx, len7
--
      int 0x80
--
   ;--------------------------------------------------------------------------------------  
--
   atoi:
--
       push ebp
--
       mov ebp, esp
--
       xor eax, eax
--
   .top:
--
       movzx ecx, byte [esi] ; obtener un caracter
--
       inc esi ; leer la siguiente dirección
--
       cmp ecx, '0' ; digito valido?
--
       jb .done
--
       cmp ecx, '9'
--
       ja .done
--
       sub ecx, '0' ; "convertir" caracter a numero
--
       imul eax, eax, 10 ; multiplicar el resultado obtenido por 10
--
       add eax, ecx ; sumatoria
--
       jmp .top ; until done
--
       .done:
--
       pop ebp
--
       ret
--
 
--
   ;------------------------------------------------------------------
--
 
--
   end:
--
      ;FINAL DEL PROGRAMA
--
      mov eax, 1
--
      xor ebx, ebx
--
      int 0x80
--


xv0:

Hola

Depura el programa con gdb o cualquier otra herramienta, para saber donde esta la violacion de segmento. Aunque diria que en la linea 154-155.

Tendrias que hacer la comparacion antes de incrementar el puntero de %esi. Ya que me has dado a entender de que puedes ingresar los numeros no?

Por otra parte, por que no haces una funcion imprimir mensaje? y no tener tanto codigo?

Por que no tomas los numeros por argv?

Saludos.

Páginas: (1/1)