ASSEMBLY LANGUAGE - WEEK V					November 23, 1986


USING EDTASM


So far we have been able to create, load into memory, and execute our assembly language subroutines using DEBUG. While DEBUG has been useful for short subroutines, it has become painfully obvious that DEBUG would not be our program of choice for an extensive assembly language programming attempt.



The second programming tool we will be using is EDTASM, an editor-assembler. EDTASM allows us to create the source code of a program using EDTASM's editing functions. We can save this code on disk for later revision. The editor also allows us to include labels and comments with the source code, which can further clarify a programs objective and function.



Once the source code has been created, EDTASM will assemble the source code into object code. Errors in the source code (as far as syntax) will be noted, and can be corrected. The object code can be saved to disk as a /CMD file.



We will start out by using EDTASM to create the little subroutine we worked with last week.



Load EDTASM. The little '*' is EDTASM's command prompt. In order to start creating the source code, we have to use the 'I', or insert command. Following the 'I', we can specify the number of the line we wish to start with, and the increment of each line. That is, the command will be in the form: <I line [,inc]>.
In this case, we want to start with line 100, and increment each number by 10. This command is similar to the AUTO command in basic editing.

                   

		I 100,10


The signal to the assemble that a line is a comment and is to be ignored in the assembly process is the  ';'. Anything after a semi-colon is ignored by the assemble. It is nice to start the source code with the name of the /CMD file, and a few comments about its purpose and function. The date the code was created, and any subsequent updates will help when you look at the source code later. Let's type in our introduction:



100 ; GREET

110 ; 3/24/86  - J.L. DUNMYER

120 ; A routine to have the computer ask your name

130 ; and then greet you




Now we can write the source code. However, we also must tell the assemble where we want the object code to be located in memory and what ROM routines we want to use. The assemble recognizes certain words as internal commands to the assemble. These are called PSUEDO-OPS. There are eight PSUEDO-OPS:

        ORG	sets address reference counter to the value nn.

        EQU	Sets value of a label to nn in the program: can occur only once for any label.

        END	Signifies the end of the source program so that any following statements are ignored. If no END statement is found, a warning is produced. The END statement can signify a start address i.e. END LABEL, END 6000H. 

        DEFL	sets value of a label to nn and can be repeated in the program with different values for the same label.

        DEFM	Defines the content of n bytes of memory to be the ASCII representation of string s, where n is the length of s and must be in the range 0 <= n <= 63.

        DEFS	Reserves nn bytes of memory starting at the current value of the reference counter.

        DEFB   Defines the contents of one byte of memory to to be the ASCII representation of character s

        DEFW

   Defines the contents of a two-byte word to be nn. The least significant byte is located at the current reference counter while the most significant byte is located at the reference counter plus one.


We can also use LABELS in the source code. These help our source code for readability. They also are used as  pointers or references by the assemble to identify subroutines or jump locations. 



There are four elements to our source code:


1. The line number - this is just a programmer's reference
   point.


2. The LABEL - These are references internal to the program.
 They can be only 6 characters long.

3. The INSTRUCTION or OP CODE - The standard Z-80 instruction.


4. COMMENTS - Comments (preceded by a ; ) which explain what the
   program is doing.



Now, let's complete our little program. The basic structure of any source code starts by defining any ROM subroutine calls, then defining the start of the object code in memory, then writing the source code, and finishing with an END statement.
 The END statement must indicate the start location of the program by the label following. The assembler uses this information to store the starting location in the command file. 


140 DISP        EQU     021BH

150 LININP      EQU     05D9H

160 CLS         EQU     01C9H

200 ;

210 ; Start body of source code here:

220 ;

230             ORG     7000H           ;START @ 7000H

240 MAIN        CALL    CLS             ;

250             LD      HL,MSG1         ;GET NAME PROMPT

260             CALL    DISP            ;DISPLAY IT

270             LD      HL,NAME         ;BUMP MEMORY POINTER

280             LD      B,20H           ;NO. OF SPACES FOR NAME.

290             CALL    LININP          ;GET NAME

300             PUSH    HL              ;SAVE NAME LOCATION

310             LD      HL,MSG2         ;GET GREETING LOCATION

320             CALL    DISP            ;SEND IT

330             POP     HL              ;GET NAME LOCATION BACK

340             CALL    DISP            ;WRITE IT

350 MSG1        DEFM    'What is your name? '
360             DEFB    0DH

370 MSG2        DEFS    'Hello, '
380             DEFB    0DH
390 NAME        DEFS    20H             ;STORE NAME HERE
400;
410; Finish source code with an end statement to assembler
420;

430;            END
		MAIN


End the source code editing session by pressing the <BREAK> key. This returns you to the command mode.


Once we have written the source code, we can display it to the screen with the 'P' command. Note that this command and all instructions to EDTASM are different than BASIC in that the line start and end instructions are separated by a colon, ':' instead of a dash, '-'. Also note that the 'P' command is equivalent to the LIST command in BASIC. Do NOT use LIST. EDTASM will try to "LOAD" a source code called "IST".

The Editor commands are similar to the basic line editor commands. We must tell EDTASM which line we want to edit. Then we can use the editor commands, 'C'hange, 'I'nsert, 'D'elete, 'S'earch,'L'ist, 'Q'uit, 'H'ack, 'X'.



The 'H'ardcopy command allows us to send the source code to the printer. This is similar to the LLIST command in BASIC. You will hang up the computer if you try a 'H'ardcopy and no printer is connected. A reset will dump you back to DOS and you will have to start all over. Save your program before trying a 'H'ardcopy.


The 'W'rite command allows you to save your source code. You should save your source code in case you would want to modify it later, or for future reference. Use a different extension, such as /TXT, or /ASM. If you are using EDTASM that came with NEWDOS80, you must type in "W D=FILENAME/EXT" to tell EDTASM to save the file on disk.

The 'L'oad command allows you to load a source code file from disk.
 If you are using EDTASM that came with NEWDOS80, you must type in "L D=FILENAME/EXT" to tell EDTASM to look for the file on disk.


The re'N'umber command allows you to renumber your text. The format is N start,inc. Start is optional (100 is the default), and the increment will be the same as before unless you specify a different increment.

Once we are satisfied with our source code, we can save it to disk. Now let's try a first-pass assembly. This assembly will check our source code for syntax errors. We want to 'A'ssemble, with '/NO' (no object code), and '/WE' (wait error).



Any errors will be noted, and we can correct them. Now save our corrected object code. Then 'A'ssemble, 'GREET/CMD'.

Once we have an assembled code with no syntax errors, we can leave the assemble by 'B'asic. 

Try the program by typing, from DOS, 'GREET'
                                                                                                                                                                                            