Anatomy of Echo.asm


We will study the previous program line by line. The name of a MIPS assembly program is usually ended in suffix .s or .asm.
.data and .text
The MIPS program structure consists of two sections:

  • Data declaration: It is placed in section identified with assembler directive .data and it declares variable names used in program.

  • Program code: It is placed in section of text identified with assembler directive .text. It contains program code.

A directive is a statement that tells the assembler something about what the programmer wants, but does not itself result in any machine instructions.

Some of the MARS and Spim assembler directives are listed on the right:
Directive Description
.text Put next code into text section.
.data Put next code into data section.
.globl name Make name be a global symbol.
.space n Allocate n bytes of space.
.word val1, val2, ... Allocate one word for each value.
.half val1, val2, ... Allocate a halfword for each value.
.byte val1, val2, ... Allocate a byte for each value.
.ascii "string" Allocate space for the ASCII characters.
.asciiz "string" Allocate space for string, NULL terminated.
.align n Start next on 2n byte boundary.
# (Comment)
Anything following the symbol # on a line is a comment. For example,
   # This stuff would be considered a comment 
   li   $v0, 4           # Print a string.



      “I AM IGNORANT of absolute truth. But I am humble before    
      my ignorance and therein lies my honor and my reward.”    
      ― Khalil Gibran