简体   繁体   English

Linux上的汇编编译器。 还是AS?

[英]Assembly compiler on linux. Nasm or AS?

I'm not sure if this is a repost or something but I will ask it :P 我不确定这是转发还是其他内容,但我会问:P

In linux I can compile C code with GCC. 在Linux中,我可以使用GCC编译C代码。 And I can compile asm code with NASM. 而且我可以用NASM编译asm代码。 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. 但是,当我使用nasm创建输出文件时: nasm -f elf something.asm -o objfile会创建一个目标文件(对吗?),但我显然无法运行。 So, what I do is use gcc and nasm. 因此,我要做的是使用gcc和nasm。 I have objfile and then "link?" 我有objfile,然后单击“链接”? with gcc: gcc objfile -o executable 与gcc:gcc objfile -o可执行文件

Questions: so what is the difference between make a simple C using gcc and other program with nasm? 问题:那么使用gcc和其他带有nasm的程序制作简单的C有什么区别? 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? 汇编如何比C程序具有更多的字节? (it has extern printf) :( (它有extern printf):(

I really want to program something without using gcc and C libs. 我真的很想在不使用gcc和C库的情况下进行编程。 I know the interrupts of Linux, the special one is int $0x80. 我知道Linux的中断,特殊中断是int $ 0x80。 I could call sys_write. 我可以打电话给sys_write。 But it only write 1 char. 但是它只写1个字符。 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. -S表示编译为程序集,但不链接至可执行文件。 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. m32表示您的32位计算机(即使您使用64位也可以)-O1表示您要将其优化到第一级。 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. 编译后,您将有一个.s文件,这是您的汇编代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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