Originally Posted by
rcgldr
Could you put an add function in the .C file and have GCC output assembly code to see what the syntax should be?
I made this C program:
Code:
// addd.c
#include <stdio.h>
int c;
int add(int x, int y);
int main(void){
int a=3, b=5;
c = add(a, b);
printf("\nsum1 = %i \n",c);
}
int add(x,y){
c = x + y;
return 0;
}
Then I used this command line:
gcc -S addd.c -o addd.asm
Which gave me this :
Code:
.file "addd.c"
.comm c,4,4
.section .rodata
.LC0:
.string "\nsum1 = %i \n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $3, -8(%rbp)
movl $5, -4(%rbp)
movl -4(%rbp), %edx
movl -8(%rbp), %eax
movl %edx, %esi
movl %eax, %edi
call add
movl %eax, c(%rip)
movl c(%rip), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.globl add
.type add, @function
add:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl -8(%rbp), %eax
movl -4(%rbp), %edx
addl %edx, %eax
movl %eax, c(%rip)
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size add, .-add
.ident "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4"
.section .note.GNU-stack,"",@progbits
But there's too much extraneous stuff and the assembly instructions are weird. I don't know what part of it too use.