Skip to content

Instantly share code, notes, and snippets.

@fsouza
Last active December 16, 2015 14:18
Show Gist options
  • Select an option

  • Save fsouza/5447326 to your computer and use it in GitHub Desktop.

Select an option

Save fsouza/5447326 to your computer and use it in GitHub Desktop.
Swap example.
.globl _swap
_swap:
movl (%rdi), %ebx
movl (%rsi), %eax
movl %eax, (%rdi)
movl %ebx, (%rsi)
retq
.globl _swap
_swap:
pushl %ebp
movl %esp, %ebp
pushl %ebx
movl 12(%ebp), %ecx
movl 8(%ebp), %edx
movl (%ecx), %eax
movl (%edx), %ebx
movl %eax, (%edx)
movl %ebx, (%ecx)
movl -4(%ebp),%ebx
movl %ebp,%esp
popl %ebp
ret
OBJECTS=asm_swap.o swap.o
all: $(OBJECTS)
$(CC) -o swap $(OBJECTS)
clean:
rm -f swap *.o
#include <stdio.h>
extern void swap(int *p, int *q);
int
main(void)
{
int p, q;
p = 10;
q = 20;
swap(&p, &q);
printf("p=%d\nq=%d\n", p, q);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment