2

I have an assembly function like so

rfact: pushl %ebp movl %esp, %ebp pushl %ebx subl $4, %esp movl 8(%ebp), %ebx movl $1, %eax cmpl $1, %ebx jle .L53 leal -1(%ebx), %eax movl %eax, (%esp) call rfact imull %ebx, %eax .L53: addl $4, %esp popl %ebx popl %ebp ret 

I understand I can't just save this as rfact.s and compile it. There has to be certain items (such as .text) appended to the top of the assembly. What are these for a linux system? And I'd like to call this function from a main function written in normal c file called rfactmain.c

1
  • Sorry about that. I didn't realized it got mangled when I pasted it. I have fixed it now! Commented Feb 13, 2014 at 23:44

1 Answer 1

3

Here's a 'minimal' prefix of directives - for ELF/SysV i386, and GNU as:

.text .p2align 4 .globl rfact .type rfact, @function 

I'd also recommend appending a function size directive at the end:

.size rfact, .-rfact 

The easiest way to compile is with: gcc [-m32] -c -P rfact.S
With the -P option, you can use C-style comments and not have to worry about line number output, etc. This results in an object file you can link with. The -m32 flag is required if gcc targets x86-64 by default.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.