That means:
|
Example: the Hello World program
.global main
// ************************ Starting variable definition *****************
.data
// ***********************************************************************
HelloStr: // Label marking this location in memory
.asciz "Hello World\n" // ASCII codes for the string
// ************************ Starting computer instruction ****************
.text
// ***********************************************************************
main:
push {lr} // Save the return address on the stack
push {fp} // Save the frame pointer on the stack
// Explained later in CS255
/* ----------------------------------------
Pass the string to printf function
---------------------------------------- */
movw r0, #:lower16:HelloStr
movt r0, #:upper16:HelloStr
/* ----------------------------------------
Call the printf function
---------------------------------------- */
bl printf // Call printf function
pop {fp} // Pop the frame pointer
pop {lr} // Pop the return address
// Explained later in CS255
.end
|
After processing the .text directive, the assembler will:
|
The assembler will keep doing this until it encounters a .data dirctive
So you can switch between .text and .data section as often as you wish in an assembler program
|
Each function has a starting point where the first instruction of the function is located.
For example:
|
Later in the course, you will learn that the if-statement and the while-statement also have some special locations that we need to know.
So there are a number of important memory locations in a computer program we need to remember
|
|
This mechanism is called a label (see: click here )
For example: in the Hello World program
main: // <----- This is a label !!!
push {lr} // Save the return address on the stack
push {fp} // Save the frame pointer on the stack
// Explained later in CS255
/* ----------------------------------------
Pass the string to printf function
---------------------------------------- */
movw r0, #:lower16:HelloStr
movt r0, #:upper16:HelloStr
/* ----------------------------------------
Call the printf function
---------------------------------------- */
bl printf // Call printf function
pop {fp} // Pop the frame pointer
pop {lr} // Pop the return address
// Explained later in CS255
.end
|
Notice that:
|
I.e.:
|
When the assembler finds a label (such as main:) in the assembler program, the assembler will equate the label to the memory address where it will put the next translated item
To show you that the assembler records the memory locations using labels, I have added more labels into the Hello World assembler program:
.global L1, L2, L3 // Make identifier externally accessible ..... (this part is unchanged and omitted for brevity) main: push {lr} // Save the return address on the stack push {fp} // Save the return address on the stack // Explained later in CS255 /* ---------------------------------------- Pass the string to printf function ---------------------------------------- */ movw r0, #:lower16:HelloStr L1: movt r0, #:upper16:HelloStr // L1 marks this memory location /* ---------------------------------------- Call the printf function ---------------------------------------- */ L2: bl printf // L2 marks this memory location L3: nop // L3 marks this memory location pop {fp} // Pop the frame pointer pop {lr} // Pop the return address // Explained later in CS255 Stop: CodeEnd: nop .end |
Notice that we need to declare the labels (= identifiers used to identify memory locations) as .global so these identifiers can be accessed by EGTAPI/
How to see the address locaton marked by the labels L1, L2, L3: (you can't do it for this program, I will demo this in class - this feature is available when you run your assembler projects)
|
.... while ( x > 10 ) { ... ... ... <--- After execution reaches the END of the while loop, the execution must REPEAT from the START } |
We will learn later in the CS255 course how to "jump to" a specific location in a computer program
(This is how the high-level programming construct of a while-loop is implemented inside the computer !!!.
That's why we need assembler programming to reveal these high-level programming construct to you, so you can understand what is going on inside a computer....)