简体   繁体   中英

Assembly compiler on linux. Nasm or AS?

I'm not sure if this is a repost or something but I will ask it :P

In linux I can compile C code with GCC. And I can compile asm code with NASM. BUT, when I create the output file with nasm like: nasm -f elf something.asm -o objfile this creates a object file (right?) but I can't run obviously. So, what I do is use gcc and nasm. I have objfile and then "link?" with gcc: gcc objfile -o executable

Questions: so what is the difference between make a simple C using gcc and other program with nasm? The size of the executables: (they have exactly the same thing)

-rw-r--r-- 1 int3 int3  280 Out 11 19:22 asm.asm
-rwxr-xr-x 1 int3 int3 7330 Out 11 19:22 ASMprogram
-rw-r--r-- 1 int3 int3   50 Out 11 19:08 c.c
-rwxr-xr-x 1 int3 int3 7294 Out 11 19:14 Cprogram
-rw-r--r-- 1 int3 int3  608 Out 11 19:22 objasm

How can assembly have more bytes than C program? (it has extern printf) :(

I really want to program something without using gcc and C libs. I know the interrupts of Linux, the special one is int $0x80. I could call sys_write. But it only write 1 char. I'm a bit confuse.

What do you recommend to me?

thanks and happy coding!

When compiling to assembly have you tried:

gcc -S -m32 -O1 file.c 

-S means compile to assembly but do not link to an executable. m32 means your 32 bit machine(even if you have a 64 bit this is fine) -O1 means you want to optimize it to the first level. The higher your optimization level is the harder it will be to read. After compiling you will have a .s file which is your assembly code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM