documentation of gnu assembler directives

冷暖自知 提交于 2020-04-13 04:09:17

问题


I'm trying to learn mips assembly at the moment. To that end, I wrote a very simple c program...

int main(){}

...and compiled it on a mips machine with the -S option to gcc to generate assembly code. Here is what the beginning of the main function looks like:

    .ent   main
main:
    .frame $fp,8,$31
    .mask  0x40000000,-8
    .fmask 0x00000000,0

I then tried to figure out what this all means by looking at the documentation for gas, but I couldn't find any of these directives there. So what do they mean? Where can I find more information?


回答1:


I know my answer is kind of late. Better late than never.

When you compile an assembly file, two kinds of directives may show up in the code.

  1. One kind is the directives supported by your assembler, in your situation, it isGNU as directives.

  2. The other kind depends on you assembly language, and because you are apparently using mips assembly here, the .ent is actually a mips assembly directive.

Here is the guide where you can find .ent .frame .fmask .mask directives: they are all mips assembly directives. Or you can just Google MIPS Assembly Language Programmer’s Guide. Navigate to chapter 8, Pseudo Op-Codes and you will get all you need.

You may wonder how GNU as can support mips directives? Type Info as, navigate to chapter Machine Dependent Features, then navigate to subchapter MIPS-Dependent. But still, you can't find .ent directive here, nor .frame .fmask .mask. That is because info as is not a mips assembly guide and can not be that much comprehensive.

By the way, nasm, the assembler which many programmer are familiar with, has its own directives and syntax (Intel style) which are different from those of GNU as (derived from ancient AT&T style). Similarly, different assembly language may have their own unique directives (but not syntax) supported by assemblers that can assemble them too. That's why two source of directives may show up in an assembly file. Now, the GNU as assembler can even support Intel syntax. And furthermore, there are tools to translate between AT&T and Intel syntax. However, you should remember that directives are different from syntax. Frankly speaking, I am confused about this too.



来源:https://stackoverflow.com/questions/730587/documentation-of-gnu-assembler-directives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!