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
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:
|
How:
|
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
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 !!
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
Companies often advertize their phone numbers as names: 1-800-get-help
get-help ≡ 438-43l7
|
Similarly:
|