The text section/segment of an assembler program

  • The .text section of a computer program contains computer instructions:

  • Instruction the Assembler to store instruction in the .text section:

    • The .text assembler directive tells the ARM assembler to store subsequent program items in the .text section

How does a compiler use the .text section
 

  • A high level language program consists of:

      1. Variable definition        

      2. Statements (inside functions)        

  • The statements (inside functions) in a high level language program corresponds to instructions in an assembler program


  • Therefore:

      • When a compiler translates a function funcName(...) it will output:

            .text
        
         funcName:
              ....  // Instructions are placed in .text section
        

Marking important (memory) locations in a computer program with labels
 

  • Some program location (= address) are more important than others...

    Examples:

      • The location of the first instruction of a method

      • The start of a loop

      • etc

  • How to find the memory address of important program locations:

    • Use a label to mark the program location

  • Example:   always mark the start of a function (with its function name as label):

        .text
    
     funcName:
          ....  // Start executing the function here
    

Important reminder: labels are symbolic names for (binary) numbers that are memory addresses

The assembler keeps track on the amount of memory used for each instruction/variable:

main:
        add r0, r0, r0
        ...
L1:
        add r0, r0, r0   // 4 bytes
        add r0, r0, r0   // 4 bytes
L2:
        add r0, r0, r0
        ...

The assembler will equate a label with the current memory address when it encounters a label (e.g.: L1:):

Demo program: /home/cs255001/demo/asm/1-directives/labels.s