AS directives: .frame, .mask and .fmask

   high memory   +------------------------+
                 |          ....          |
                 |          ....          |
virtual frame    |       argument n       |
pointer $(fp) ->/+------------------------+\
               / |                        | \
  frame offset   |   local & temporaries  |  \
               \ |                        |   \
                \+------------------------+    \
                 |     saved registers    |      frame size
                 |  (including returnreg) |    /
                 +------------------------+   /
                 |          ....          |  /
   stack         |     argument build     | /
pointer $(sp) -> +------------------------+/
 (framereg)      |          ....          |
                 |          ....          |
                 |                        |
                 |                        |
                 |                        |
    low memory   +------------------------+

.frame framereg, framesize, returnreg
The virtual frame pointer is a frame pointer as used in other compiler systems but has no register allocated for it. It consists of the framereg ($sp, in most cases) added to the framesize. The returnreg specifies the register containing the return address (usually $ra).

.mask bitmask, frameoffset
The .mask directive specifies the registers to be stored and where they are stored. A bit should be on in bitmask for each register saved (for example, if register $31 is saved, bit 31 should be ‘1’ in bitmask. Bits are set in bitmask in little-endian order, even if the machine configuration is big-endian).The frameoffset is the offset from the virtual frame pointer (this number is usually negative).

.fmask bitmask, frameoffset
Notice that saving floating-point registers is identical to saving general registers except we use the .fmask pseudo-op instead of .mask, and the stores are of floating-point singles or doubles.

        .text
        .cfi_sections   .debug_frame
        .align  2
        .globl  main
        .cfi_startproc
        .ent    main
        .type   main, @function
main:
        .frame  $fp,32,$31 # vars= 16, regs= 1/0, args= 0, gp= 0
        .mask   0x40000000,-8
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        daddiu  $sp,$sp,-32
        .cfi_def_cfa_offset 32
        sd      $fp,24($sp)
        .cfi_offset 30, -8
        move    $fp,$sp
        .cfi_def_cfa_register 30
        move    $2,$4
        sd      $5,8($fp)
        sll     $2,$2,0
        sw      $2,0($fp)
        .loc 1 6 12
        move    $2,$0
        .loc 1 7 1
        move    $sp,$fp
        .cfi_def_cfa_register 29
        ld      $fp,24($sp)
        daddiu  $sp,$sp,32
        .cfi_restore 30
        .cfi_def_cfa_offset 0
        jr      $31
        nop
        .set    macro
        .set    reorder
        .end    main
        .cfi_endproc
        .size   main, .-main

References
From: http://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf

Leave a Reply

Your email address will not be published. Required fields are marked *