Saturday, January 21, 2012

ASSEMBLER DIRECTIVES


An assembler directive is a message to the assembler that tells the assembler something it needs to know in order to carry out the assembly process; for example, an assemble directive tess the assembler where a program is to be located in memory. We are going to use the following directives in this course:
<label>EQU<value>Equate
ORG<value>Origin
<label>DC<value>Define constant
<label>DS<value>Define storage
END<value>End of assembly language program and "starting address" for execution
In each case, the term <label> indicates a user-defined label (i.e., symbolic name) that must start in column 1 of the program, and <value> indicates a value that must be supplied by the programmer (this may be a number, or a symbolic name that has a value).
Equate
The EQU assembler directive simply equates a symbolic name to a numeric value. Consider:
SundayEQU1
MondayEQU2
The assembler substitutes the equated value for the symbolic name; for example, if you write the instruction ADD.B #Sunday,D2, the assembler treats it as if it wereADD.B #1,D2.
You could also write
SundayEQU1
MondayEQUSunday + 1
In this case, the assembler evaluates "Sunday + 1" as 1 + 1 and assigns the value 2 to the symbolic name "Monday".
Do not think that the EQU directive creates variables or constant. It doesn't and it has no effect on the code generated by the program. This directive simply allows you to make a name equivalent to its value (i.e., it's a form of short hand).
Origin
The origin directive tells the assembler where to load instructions and data into memory. The 68000 reserves the first 1024 bytes of memory for exception vectors. Your programs will start at location 1024; that is, you should begin your program with ORG 1024 or ORG $400 (remember that 1024 = 40016).
Define Constrant
The define constant assembler directive allows you to put a data value in memory at the time that the program is first loaded. The DC directive takes the suffix .B.W, or.L. You can put several values on one line (each value is separated by a comma). The optional label field is given the address of the first location in memory allocated to the DC function. Consider the example:
ORG$2000Locate data here
Val1DC.B20,34Store 20 and 34 in consecutive bytes
Val2DC.L20
MeDC.B’Alan Clements’
The effect of this code is to store the value $14 in location $2000, $22 in location $2001, $00000014 in locations $2002, $2003, $2004, $2005. Remember that a 32-bit longword takes four bytes of memory. The ASCII string ‘Alan Clements’ is stored in bytes $2006 to $2012.
If you write MOVE.B Val2,D2, the assembler translates it as MOVE.B $2002,D2. When this instruction is executed, data register D2 is loaded with the contents of memory location $2002. The value loaded into D2 might be 20. Might be?? Yes, might be, because another instruction might modify the contents of Val2. By the way, if you execute MOVE.B Me,D0, data register D0 would be loaded with $41 (the ASCII code for ‘A’). However, if you execute MOVE.W Me,D0, data register D0 would be loaded with $416C (the ASCII code for ‘Al’).
Define Storage
The define storage directive is used to reserve one or more memory locations. This directive is similar to the Pascal type declaration. Consider:
ResultDS.B 1Save a byte for Result
TableDS.W 10Save 10 words (20 bytes) for Table
PointDS.L 1Save 1 longword (4 bytes) for Point
We will put these two fragments of assembly language together and assemble them using the X68K command (X68K is the Teesside 68K cross-assembler that runs under DOS on a PC). The following is part of the listing file produced by the assembler. The second column contains memory addresses and the third column contains the data loaded into these addresses.
2 00002000ORG$2000;Locate data here
3 000020001422VAL1:DC.B20,34
4 0000200200000014VAL2:DC.L20
5 00002006416C616E2043ME:DC.B’Alan Clements’
6C656D656E74
73
6 0000201300000001RESULT:DS.B1;Save a byte for Result
7 0000201400000014TABLE:DS.W10;Save 10 words (20 bytes) for Table
8 0000202800000004POINT:DS.L1;Save 1 longword (4 bytes) for Point

No comments:

Post a Comment