Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimal example to compile & run assembly with gcc?

int main(int argc, char* argv[])
{
  return 0;
}

what's the shortest assembly example to do the same that can be compiled into an executable by gcc?

I came across this example but there're too many tags like hi_temp:,.data etc,what's the minimal version?

like image 353
R__ Avatar asked Feb 23 '23 17:02

R__


2 Answers

.text
    .align 4
    .globl main
main:
     pushl %ebp
     movl %esp,%ebp
     xorl %eax,%eax
     leave
     ret

To compile and run:

$ gcc -m32 asm.S
$ ./a.out
like image 156
Paul R Avatar answered Feb 26 '23 19:02

Paul R


.text
    .globl main
main:
     xorl %eax,%eax ;return 0
     ret
like image 43
Jens Björnhager Avatar answered Feb 26 '23 19:02

Jens Björnhager