|
|
In fact, I would recommend that you use comments to create some structure in your assembler programs
|
|
Each assembler directive and assembler instruction is usually written on one line in the assembler program
|
// // hello.s: hello world in ARM assembler // // How to compile: // // as -o hello.o hello.s // gcc -o hello hello.o // .global main // ************************ 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 with input string pop {fp} // Pop the frame pointer pop {lr} // Pop the return address // Explained later in CS255 // ************************ Starting variable definition ***************** .data // *********************************************************************** HelloStr: // Label marking this location in memory .ascii "Hello World\n\0" // ASCII codes for the string // \0 is used to terminate a string .end Any text that follws ".end" is ignored (treated as comment) |
I have color-coded the 3 types of lines in the Hello World assembler program:
|
Some of the lines are marked by a label.
There are 2 labels used in the hello.s program:
HelloStr main |
As you can see in this example:
|