Hi! I'm still new to assembly and I'm trying to do a selection sort using assembly.. There's a problem somewhere and I can't seem to find it.. Please help me.

Here's my code so far:

.section .data

format:
	.asciz "%d\n"

values:
	.int 5, 3, 2, 4, 7

smallest:
	.int 0

.section .text

.global _start
_start:
	leal values(,  %edi,4), %esi

	movl $4, %ecx     #outer loop counter
	movl $4, %ebx     #inner loop counter

	movl (%esi), %eax
	movl %eax, smallest	
	addl $4, %esi
	dec %ebx
	jz output

loop:
	movl (%esi), %eax
	cmp smallest, %eax
	jl minimum
	jmp converge
	
minimum:
	movl %eax, smallest
	
converge:	
	dec %ebx
	addl $4, %esi
	jnz loop
	
	dec %ecx
	jz output

	addl $1, %edi
	leal values(,  %edi,4), %esi
	jmp loop

output:
	addl $0, %edi

output_loop:
	movl values(, %edi, 4), %eax
	
	push %eax
	push $format
	call printf
	addl $8, %esp
	
	cmp $4, %edi
	je end
	
	addl $1, %edi
	loop output_loop
	
end:
	movl $1, %eax
	movl $0, %ebx
	int $0x80

Thanks in advance!

What is the problem?

Whenever I try to run it, it just returns a segmentation fault message.. Is there something wrong with my code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.