0

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!

Edited by WolfPack: Code Tags

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by loveMii
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.