Assembly Intro - Inline Assembly Versus Non-Inline Assembly



From a function viewpoint, function may be implmented
by inline assembly way, or by non-inline assembly way.

Example:
inline assembly function

int inline_add(int x, int y)
{
  asm volatile ("addl %%ebx,%%eax"
      :"=a"(x)
      :"a"(x), "b"(y)
      );

  return x;
}

// declare
int non_inline_add(int x, int y);

int main()
{
    int result;
 
 result = inline_add(5, 10);
 
 result = non_inline_add(5, 10);
 
 return 0;
}


// implementation

file non_inline_add.S

.globl non_inline_add

non_inline_add:
  pushq %rbp
  movq  %rsp, %rbp

  addq %rsi, %rdi
  movq %rdi, %rax

  leaveq
  retq



你可能感兴趣的:(assembly)