Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The second phase of your semester project is to write pass one of a two-pass assembler for the SIC assembler language program. As with Phase

The second phase of your semester project is to write pass one of a two-pass assembler for the SIC assembler language program. As with Phase 1, this is to be written in C (not C++) and must run successfully on the Linux server to receive credit.

Pass one will read each line of the source file, and begin the process of translating it to object code. (Note: it will be to your advantage to have a separate procedure handle reading, and perhaps tokenizing, the source file.) Among other things, this pass will create the symbol table. At the end of the pass, the symbol table should be printed, showing each symbol together with its location. This pass must also recognize and handle the assembler mnemonics in addition to the directives START, END, BYTE, WORD, RESB, and RESW. It should also be able to recognize the following types of errors (note that this is not an exhaustive list):

Duplicate labels

Illegal label (note: could specify why it is illegal, but not necessary)

Illegal operation Missing or illegal operand on data storage directive

Missing or illegal operand on START directive Missing or illegal operand on END directive (note: you do not need to check if the symbol is defined)

Too many symbols in source program

Program too long

After flagging an error, your assembler should continue processing the source file so that all errors are flagged in a single run. These errors will not be printed, but must be passed to the second pass of the assembler.

NOTE: Your assembler should not terminate abnormally because of anything (legal or not) in the source program being assembled.

Since some processing must take place on each line during pass one, it is advantageous to save this information in an intermediate file for use by pass two. Some things you may wish to place in this file are:

copy of source line

value of location counter

values of mnemonics used (since they had to be looked up)

operand (since you had to get it)

error messages (from pass 1 - best to use codes and not the actual message)

This information should be easy to retrieve that is, you should not have to break up anything to get this saved information.

Note that pass two will do the actual encoding of the opcode and operand into object code, and create the listing file together with all error messages.

The following items should be stored on the server in your 3334/phase2 directory:

1. A documented listing of the assembler source code.

2. Two listings of assembler language source files (one with no errors, one with errors).

3. A listing of the symbol tables produced.

4. Copies of both intermediate files.

5. A README file to indicate what the format of the intermediate file is and the error codes.

The SIC Assembler Specifications

The SIC assembler language will consist of the 25 mnemonics listed in the instruction set (copy attached), together with the assembler directives (START, END, BYTE, WORD, RESB, RESW). The assembler language statements will consist of lines in the following free format:

{label}instruction {operand{,X}} {comment}

The items in curly braces, {..}, are optional, depending on the instruction and/or the programmer. A line may consist of just a comment, or just a label. If present, the label must begin in column 1. A period (.) in column 1 indicates the entire line is a comment. A blank in column 1 indicates that no label is present. Blank lines will be ignored. The only restriction is that there must be at least one space or tab separating each field present. The only exception is if indexing is requested -- don't put a space between the comma and the X.

A symbol is a string of up to 6 alphanumeric characters (letters and digits). The first character must be a letter. The assembler will not be case sensitive. You may assume there will be a maximum of 500 distinct labels.

The BYTE directive may take two types of operands: character strings or hexadecimal digits. These must be in the form C'...' or X'...'. The maximum length of a character string is 30 characters. The maximum length of the hexadecimal string is 16 bytes (32 hex digits). The number of hexadecimal digits must be even.

Instruction operands must be of the form operand or operand,X , where operand is either a symbol that is used as a label in the source program, or an actual hexadecimal address. Hexadecimal addresses that would begin with 'A' through 'F', must have a leading '0' to distinguish them from labels.

COPY START 1000 COPY FILE FROM INPUT TO OUTPUT FIRST STL RETADR SAVE RETURN ADDRESS CLOOP JSUB RDREC READ INPUT RECORD LDA LENGTH TEST FOR EOF (LENGTH = 0) COMP ZERO JEQ ENDFIL EXIT IF EOF FOUND JSUB WRREC WRITE OUTPUT RECORD J CLOOP LOOP ENDFIL LDA EOF INSERT END OF FILE MARKER STA BUFFER LDA THREE SET LENGTH = 3 STA LENGTH JSUB WRREC WRITE EOF LDL RETADR GET RETURN ADDRESS RSUB RETURN TO CALLER EOF BYTE C'EOF' THREE WORD 3 ZERO WORD 0 RETADR RESW 1 LENGTH RESW 1 LENGTH OF RECORD BUFFER RESB 4096 4096-BYTE BUFFER AREA . . SUBROUTINE TO READ RECORD INTO BUFFER . RDREC LDX ZERO CLEAR LOOP COUNTER LDA ZERO CLEAR A TO ZERO RLOOP TD INPUT TEST INPUT DEVICE JEQ RLOOP LOOP UNTIL READY RD INPUT READ CHARACTER INTO REGISTAR A COMP ZERO TEST FOR END OF RECORD (X'00') JEQ EXIT EXIT LOOP IF EOF STCH BUFFER,X STORE CHARCTER IN BUFFER TIX MAXLEN LOOP UNLESS MAX LENGTH JLT RLOOP HAS BEEN REACHED EXIT STX LENGTH SAVE RECORD LENGTH RSUB RETURN TO CALLER INPUT BYTE X'F1' CODE FOR INPUT DEVICE MAXLEN WORD 4096 . . SUBROUTINE TO WRITE RECORD FROM BUFFER . WRREC LDX ZERO CLEAR LOOP COUNTER WLOOP TD OUTPUT TEST OUTPUT DEVICE JEQ WLOOP LOOP UNTIL READY LDCH BUFFER,X GET CHARCTER FROM BUFFER WD OUTPUT WRITE CHARACTER TIX LENGTH LOOP UNTIL ALL CHARACTERS JLT WLOOP HAVE BEEN WRITTEN RSUB RETURN TO CALLER OUTPUT BYTE X'05' CODE FOR OUTPUT DEVICE END FIRST 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

Define what is meant by communication.

Answered: 1 week ago