• No results found

7.3 Listing Files

The AS11 has the ability to create a listing file. A listing file is a file that contains the combination of the original source code and the assembled code. Each line from the original source code file is included in the listing file, including blank lines. Each line is numbered to provide a cross-reference to the original source file. The line numbers are used when reporting error messages. Figure 7.8 illustrates all the features of a listing file.

168

0001 000a TEN EQU 10 0002 0005 FIVE EQU TEN/2 0003 0001 REMAIN EQU TEN%3 0004 0014 TWENTY EQU TEN*2 0005 001e THIRTY EQU TEN+TWENTY 0006 0007 SEVEN EQU TWENTY/2-3 0007

0008 0073 VALUE1 EQU %01110011 0009 0096 VALUE2 EQU %10010110 0010 0012 AND EQU VALUE1&VALUE2 0011 00f7 OR EQU VALUE1|VALUE2 0012 00e5 XOR EQU VALUE1^VALUE2 0013

0014 0100 ORG $0100 0015

0016 0100 BUFFER RMB 8 0017 0108 00 00 ZERO ZMB 2

0018 010a 02 DATA FCB SEVEN%FIVE 0019 010b 65 71 UPCASE FCB $45|$20, $51|$20 0020 010d 53 4a LOCASE FCB $73&$DF, $6A&$DF

Figure 7.7 Assembler Expressions

1. What symbol is used to designate hex numbers in the assembler?

2. What directive is used to define a byte in memory that is the ASCII character code for a single character?

3. What will be stored in memory by the following expression? SUM = $3B + 78

0001 *Program to count the number of positive numbers in a 0002 *list using index mode

0003

0004 0000 4f CLRA ;Clear COUNT

0005 0001 ce 01 d4 LDX #$01D4 ;Init pointer to first location 0006 0004 a1 00 LOOP CMPA $00,X ;Get a number

0007 0006 25 02 BLO OVER ;If negative, don't count! 0008 0008 a6 00 LDAA $00,X ;Count the positive 0009 000a 08 OVER INX ;Increment pointer 0010 000b 8c 01 e8 CPX #$01E8 ;Is list finished 0011 000e 26 f4 BNE LOOP

0012 0010 3f SWI Memory Address Line # Machine Code Label Field Mnemonic Operand Field Comment Field

}

Comments can occupy the entire line if the first character of the line is the asterisk "*".

Figure 7.8 Features of a Listing File.

Each line of the listing file starts with a line number. This number is a decimal number that is sequential throughout the file. The field contains the address in memory that the machine code will start for that instruction. Following the address is the actual machine code. That completes the machine code portion of the file. Everything to the right of the machine code is the original source code. The original source code includes the label, the mnemonics, the operands and any comments.

Errors

During the assembly, any errors that occur are included in the listing file. The error messages are included in the listing prior to the line that caused the error. The line number of the instruction that caused the error is referenced in the error message. Errors that are found in the first pass through the assembly process cancel the assembly. A lesser type of error called a “warning” does not cause the assembly to stop, yet it should be viewed critically. The source of warnings should be found and the problems resolved.

The AS11 assembler has the ability to identify a variety of syntax errors, but the logical and functional errors of the programs must be found and resolved by the programmer.

NOTE: During assembly, errors are reported to the monitor. The line number of the instruction within the source file that caused the error is provided in the error message.

Self-Test Questions 7.3

7.4 “S” Records

The machine code that is generated by the process of assembling a source file is contained in a file called an S19 file. The S19 files are designed to simplify data transfer to the memory after assembly. The S19 format is printable; thus the transfer of data to memory can be visually monitored and the S records can be modified in a text editor. The files contain multiple S records.

The S records are essentially character strings that are made up of five fields, as shown in Figure 7.9. The type field must be “S1” or “S9” for AS11 records for the HC11 EVBU. The length field contains a two-digit hex value that represents the record length. The record length is the sum of the number of bytes in the address field and the number of bytes in the data field plus one for the checksum. The address field contains the character codes for a 16-bit address. Four characters are needed to represent the four hex digits that make up the address. The data field contains characters that represent each hex value in the machine code. Each byte of binary data is encoded as a

1. What is a listing file?

2. What process generates a listing file?

3. Where are error messages placed in the listing file?

169

two-character hex value. The first character of each two-character pair represents the upper four bits, and the second character represents the lower four bits of the machine code byte. The checksum field contains two characters. These characters are the 1’s complement of the two-digit hex checksum value. The checksum is the sum of all characters, starting with the record length through the data field.

There are eight different S record types defined, but only S1 and S9 records are supported by the EVBU monitor program. S1 records contain program codes and program data in the data field. The address field of an S1 record contains the four-digit hex address of where these program codes and data are to reside. The S9 record is a termination record for a block of S1 records. The address field of an S9 record may optionally contain the address of the first instruction to be executed after the download is complete. S9 records contain an empty data field. Figure 7.10 describes all the parts of S1 and S9 records.

Self-Test Questions 7.4

2 chars 2 chars 4-8 chars n chars 2 chars

Type Length Address Code & Data Checksum

Complete S Record

Figure 7.9 Format of S Records

S1190000368664BD000B4A26FA32393C21F2CE0D010926FD383961 Length = $19 bytes

Type = S1

Type = S9

Length = $03 bytes Address = $0000 Checksum Address = $0000 Data (actual program codes) Checksum S9030000F6

Figure 7.10 Examples of S Records

1. What are the two types of S records defined for the AS11 assembler? 2. What are the fields of the S1 record type?

3. How are S9 records used?

170

Summary

An assembler is a piece of software that converts mnemonic instructions into operational codes and operands. The source code is the original set of instructions written by the programmer. The use of labels, comments and white space can make the source code files more readable. The assembler contains many features that allow the programmer greater flexibility. These features include support for multiple data-type constants, directives (instructions to the assembler imbedded in the source code), the use of symbolic variables within the code called labels, and symbolic expressions.

The assembly process produces two types of output: listing files and S19 files. The listing files contain the original source code and the resulting machine code in a line-by-line format. The S19 files contain S records. The S records are character representations of the hex code and data that are to be loaded into memory for program execution. This code and data are packaged in the S record format, which includes some header fields and a trailing checksum that provide structure and organization to the download process.

Chapter Questions

Section 7.1

1. How are labels defined in the source code? 2. What symbols are allowed as labels?

3. Which of the following is an invalid label: GO_TEAM, DeVry.com, abc123, Help$, 1_time.

4. What is the maximum length of a label?

5. Should comments express the “what” or the “why” regarding the instructions?

Section 7.2

6. What symbol is used to designate ASCII character values in the assembler? 7. What directive could be used to define a string of bytes in memory that are the

ASCII characters?

8. If the label REGS is defined to be equivalent to $1000, what value is loaded by the following instruction?

LDX #REGS+6

Section 7.3

9. List the fields in the listing file.

10. What kinds of error messages terminate the assembly process?

Section 7.4

11. Essentially, what is an S19 file? 171

Chapter Problems

1. Modify the following example to increase readability without changing the program’s function.

MAIN LDAA #$10 AGAIN JSR $E2E5 DECA

BNE AGAIN

2. Use directives to define a label for the memory address $1004. Reserve a buffer of eight bytes of memory starting at address $0180 and a message called BOOT that says, “Booting up the computer,” and is terminated by the EOT (end of transmis- sion) character.

Answers to Self-Test Questions

Section 7.1

1. Use labels, comments and white space.

2. Full-line comments and comments that follow a line of code.

3. Blank lines can be inserted in the source code between subroutines to physically separate the functions. This makes it more clear where one function ends and another starts.

Section 7.2

1. The $ symbol must precede a number for the assembler to interpret the number as hex.

2. EQU could be used, as in CHARA EQU ’A’. FCC could also be used: CHARA FCC ’A’.

3. The assembler will perform the addition operation of the two constants $3B and $4E (7810). SUM will be equal to $89.

Section 7.3

1. A listing file is an output file from the assembly process. It contains the original source code and the output machine code.

2. The assembly process generates the listing file by redirecting the terminal output to a file.

3. Error messages appear immediately prior to the line that contains the error. The error message refers to the line that caused the error.

Section 7.4

1. S1 and S9 records are used by AS11 and the EVBU.

2. The S1 record type contains five fields: type, length, address, data and checksum. 3. S9 records are used to terminate a transfer of data.

172

Objectives