Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

documentation of gnu assembler directives

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?

like image 398
Kim Stebel Avatar asked Apr 08 '09 15:04

Kim Stebel


1 Answers

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.

like image 136
Han XIAO Avatar answered Oct 02 '22 12:10

Han XIAO