previous | start | next

IA32 Assembly for: accessing array elements (3)

swapElements:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %edx          ; address of array a in %edx
        movl    12(%ebp), %ecx         ; i in %ecx  
        movl    16(%ebp), %eax         ; j in %eax           
        pushl   %ebx                                                                                 
        leal    (%edx,%ecx,4), %ecx    ; address of a[i] in %ecx
        leal    (%edx,%eax,4), %eax    ; address of a[j] in %eax     
        movl    (%ecx), %ebx           ; value of a[i] in %ebx
        movl    (%eax), %edx           ; value of a[j] in %edx
        movl    %edx, (%ecx)           ; %edx stored in a[i]
        movl    %ebx, (%eax)           ; %ebx stored in a[j]
        popl    %ebx                                                                                 
        popl    %ebp                                                                                 
        ret                            ; return                              


previous | start | next