Segmentation fault (core dumped) displayed

19 Views Asked by At

I wrote a code in Assembly x86 that is supposed to find the minimum and the maximum values of a given array and print them:

.data
    n: .long 6
    v: .long 15, 20, 11, 8, 35, 26
    formatprint: .asciz "%d : %d"

.text

.global main

main:
    lea v, %edi
    mov $0, %ecx
    mov (%edi, %ecx, 4), %eax
    mov (%edi, %ecx, 4), %ebx
    inc %ecx 
    
    for_elem_v:
        cmp n, %ecx
        je Print
        
        mov (%edi, %ecx, 4), %edx
        cmp %edx, %eax
        jl maximum
        
        cmp %edx, %ebx
        jg minimum
        
        maximum:
            mov %edx, %eax
            jmp incrementation
        
        minimum:
            mov %edx, %ebx
            jmp incrementation
        
        incrementation:
            inc %ecx
            jmp for_elem_v
            
Print:
    push %ebx
    push %eax
    push $formatprint
    call printf
    pop %ecx
    pop %ecx
    pop %ecx

    push $0
    call fflush
    pop %ecx


exit:
    mov $1, %eax
    mov $0, %ebx
    int $0x80

The problem is that it displays "Segmentation fault (core dumped)" when I try to run it. Can you help me solve it? enter image description here

0

There are 0 best solutions below