All pastes #795726 Raw Edit

moxjet

public text v1 · immutable
#795726 ·published 2007-11-24 11:28 UTC
rendered paste body
#This is a function that takes an address to a list in the first parameter and list length in second parameter, and doubles each element
#extern void doubleli( int li[], int length )

# x86 at&t syntax

    .globl doubleli

    doubleli:
	pushl %ebp
	movl %esp, %ebp
	movl 8(%ebp), %ebx  # ebx holds the list's starting address
	movl $0, %ecx	    # ecx goes from [0 ... length - 1]
    doubleelem:
#How can I write these three rows in one?
	movl (%ebx, %ecx, 4), %eax
	addl %eax, %eax
	movl %eax, (%ebx, %ecx, 4)
#------
	incl %ecx
	cmp %ecx, 12(%ebp)
	jne doubleelem
	movl %ebp, %esp
	popl %ebp
	ret