



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Essential assembler directives used for memory management in metaware assembler, including section identification and specification, data storage and allocation, and symbol declaration. It covers topics such as text and data sections, word, half, byte, and skip directives, align directive, and asciz directive.
Typology: Lab Reports
1 / 7
This page cannot be seen from the preview
Don't miss anything!




An assembler translates assembly language statements or source into a file of binary coded machine instructions and data. The translation process generally consists of two parts: 1) identify and associate labels with memory locations and 2) translate assembly instructions into numeric or machine codes. The resultant binary file is generally referred to as an object file.
Assembler directives direct the assembler during the translations process to perform such operations as:
Section Identification and Specification At the most fundamental level, a program is located in two distinct parts of memory: 1) the program or executable portion and 2) the data storage portion. As an assembly programmer, you must distinguish these parts so that the assembler can distinctly locate them in memory. This is accomplished with the section assembly directive. The syntax of the directive follows:
Notice that the section directive starts with a period. The assembler distinguishes all directives with a leading period. Name is arbitrary and identifies the section. Class specifies or determines what kind of section proceeds. There are several classes, but we will be concerned with just two: text and data.
Text identifies the following section as executable. This section is used for your assembly program. For example, to declare an assembly-coded program section, my_program, you would use the following section directive.
.section my_program, text
assembly line 1 assembly line 2 etc
An abbreviated section directive for a text section is:
It is equivalent to:
Notice the name of the section is ‘text’.
Data identifies the following section as data storage. This is where you will allocate and initialize memory for arrays, buffers and variables. For example, to declare a data storage section, my_data, use the following section directive.
.section my_data, data
memory allocation and initialization statements
An abbreviated section directive for data is:
It is equivalent to:
Notice the name of the section is ‘data’.
Data Storage and Allocation There are several assembler directives for allocating and initializing memory in the data section. We will use the following:
Word , half and byte directives allocate and initialize word, half word and byte memory locations. The directive is followed by one or more values to be initialized. For example,
.word 1, 2, 3, 4, 5
initializes 5 consecutive word locations to 1 through 5.
Symbol Declaration
There are several directives associated with symbol declaration. We are primarily concerned with:
The global assembler directive exports or lists a symbol for external access. For example, if you have a variable named ‘done_flag’ that you want accessible by another assembled file, you need to declare the label to that memory location as global. The following statements allocate and initizalize space for the variable ‘done_flag’ and declare the label global.
Done_flag .word 0
.global done_flag
Note that the symbol _Start must be globally declared to determine a starting point when the linker generates an executable object.
The equ directive is used to associate a value with a name. The directive takes the form:
This particularly useful when assigning constant values making your code readable and reducing the possibility of errors. For example,
.equ size 10
associates the decimal value 10 to the name ‘size’.
This document focuses on essential assembler directives required to do the 373 labs. There are many more assembler directives at your disposal. Several reference copies are provided in the lab listing all the assembler directives.
Although the assembler generates and locates a binary representation of the data and assembly instructions, the code is note ready for execution. The binary file generated by the assembler represents the relative location of the data and program space to one another. The locations have yet to be explicitly associated with actual memory locations.
The MPC823 provides memory from 0x0000 0000 to 0x003F FFFF. The space from 0x0000 0000 to 0x0001 0000 is used by the system and a SingleStep monitor that communicates with the SingleStep Debugger running on your PC. We generally use the space from 0x0001 0000 to 0x003F FFFF. The linker file file-link.txt file contains linker commands to associate the text and data sections with specific memory addresses. Specifically,
SECTIONS {
.text ADDRESS 0x10000:
.data ADDRESS 0x11000:
}
The text or executable code will start at location 0x0001 0000 and the data will start at 0x0001 1000.
Notice that flag2 in no longer located on a half word boundary and the array1 is no longer located on a word boundary.