Comments
 

A comment in assembler programs are written as follows (same way as in Java):

    //  This is a comment line                        


 Or:


    /* 
        These are
        comment lines
    */
   

Comments are ignored by the assembler

Labels

A label can be used to mark (= identify) (1) an instruction or (2) variable inside the assembler program

How to use a label:

   Label:  assembler instruction or variable definition

Or:

   Label:
           assembler instruction or variable definition 

What exactly is a label:

  • A label is a symbolic constant for the memory address where the instruction/variable is stored in memory

How:

  • The assembler keeps a count on the amount of memory used to keep track of the current memory address

  • When the assembler find a label definition, it equates the label name to the current memory location (address)

How is a label used in assembler programming - illustrated

Consider the label HelloStr in the Hello assembler program:

        .global main

        .text
main:            // main marks the location of the start of program

   push    {lr}  // Save the return address on the stack
   push    {fp}  // Save the frame pointer on the stack
                 // Explained later in CS255

   movw    r0, #:lower16:HelloStr
   movt    r0, #:upper16:HelloStr

   bl      printf  // Call printf function with input string     

   pop     {fp}    // Pop the frame pointer
   pop     {lr}    // Pop the return address
                   // Explained later in CS255

        .data
HelloStr:          // Label marking memory location storing the string
        .ascii "Hello World\n"   // ASCII codes 

        .end
   

Suppose the string "Hello World\n" is stored in memory location 70000

How is a label used in assembler programming - illustrated

In other worlds: the "symbolic name" HelloStr is equal to the memory address 70000:

        .global main

        .text
main:            // main marks the location of the start of program

   push    {lr}  // Save the return address on the stack
   push    {fp}  // Save the frame pointer on the stack
                 // Explained later in CS255

   movw    r0, #:lower16:HelloStr
   movt    r0, #:upper16:HelloStr

   bl      printf  // Call printf function with input string     

   pop     {fp}    // Pop the frame pointer
   pop     {lr}    // Pop the return address
                   // Explained later in CS255

        .data
HelloStr (=70000): // Label marking memory location storing the string
        .ascii "Hello World\n\0"   // ASCII codes 

        .end
   

Therefore:   the assembler will replace all occurences of the HelloStr with the value 70000 !!

How is a label used in assembler programming - illustrated

Resulting assembler program:

        .global main

        .text
main:            // main marks the location of the start of program

   push    {lr}  // Save the return address on the stack
   push    {fp}  // Save the frame pointer on the stack
                 // Explained later in CS255

   movw    r0, #:lower16:70000  // HelloStr is replaced by 70000 !
   movt    r0, #:upper16:70000  // HelloStr is replaced by 70000 !

   bl      printf  // Call printf function with input string     

   pop     {fp}    // Pop the frame pointer
   pop     {lr}    // Pop the return address
                   // Explained later in CS255

        .data
HelloStr (=70000): // Label marking memory location storing the string
        .ascii "Hello World\n\0"   // ASCII codes 

        .end
   

Important fact:   a label is symbolic constant for the marked memory address

Analogy to help you understand labels in an assembler program
 

Companies often advertize their phone numbers as names: 1-800-get-help

get-help 438-43l7

 

  • Some companies has reserved symbolic names for telephone numbers

Similarly:

  • Labels are symbolic names for memory addresses (= binary numbers) in an assembler program