CSC 330 - Labs 5 - 10 - The S/390 Assembler - Prof. Domanski
The S/390 Assembler
The remaining 6 labs (labs 5 thru 10) for the semester will cause you to build a 2 pass assembler for Assembly Language on S/390 mainframes. The assembler is built in 2 larger parts; called pass 1 and pass 2. The objective of pass 1 is to construct a symbol table that is used in pass 2. The objective of pass 2 is to produce an executable version of the test program, and a printout that includes all the object code the assembler constructed. You are permitted to work in teams - this means that 2 or more people work together and hand in 1 listing with everyone's name on it. Identical listings that are turned in by different people will be considered cheating and will result in a failing grade! Team submissions must include extra credit code (described later).
Lab 5 - Pass 1 / program 1 of the assembler. The objective here is to construct the basic skeleton of the assembler, including a POT table and a MOT table, and to begin processing of a sample program. The POT and MOT tables, as well as a copy of the output from your assembler that this input assembler code would produce follows here.
Input Data
PROG CSECT BALR 12,0 USING *,12 AGAIN L 5,X A 5,Y LCR 5,5 ST 5,Z BCR 15,14 X DC F'4' Y DC F'6' Z DS F END Sample Output
LOC OBJECT CODE SOURCE STATEMENT 000000 CSECT PROG CSECT 000000 05 BALR 12,0 000002 USING USING *,12 000002 58 AGAIN L 5,X 000006 5A A 5,Y 00000A 13 LCR 5,5 00000C 50 ST 5,Z 000010 07 BCR 15,14 000012 DC X DC F'4' 000012 DC Y DC F'6' 000012 DS Z DS F 000012 END END
Data Areas and Tables
PRINTLINE- Where you construct the different portions of each line of output. This should contain room for the location counter, the object code and the assembler source statement
INCARD - The area used to contain each line of assembler input. It should contain the label (if there is one), and the instruction, and the operands
HEADER - The area that contains the heading that would appear at the top of each page of assembler output: 'LOC OBJECT CODE SOURCE STATEMENT'
MOT - The Machine Operation Table - Contain the information about each possible assembler instruction: the instruction name, the corresponding opcode in hexadecimal, the instructions' length, and the type of instruction it is.
| BALR | 05 | 2 | 1 |
| L | 58 | 4 | 2 |
| A | 5A | 4 | 2 |
| LCR | 13 | 2 | 1 |
| ST | 50 | 4 | 2 |
| BCR | 07 | 2 | 1 |
POT - The Pseudo Op Table - A class containing functions for each pseudo instruction (these are instructions for the assembler, and do not execute at run time of the users' input program). Each function is a processing routine for that pseudo instruction.
| CSECT |
| USING |
| END |
| DC |
| DS |
Lab 6 - Pass 1/program 2: Modify the DC and DS routines to reflect the appropriate alignment and increment of the location counter. For fullword alignment, you'll first have to check the last two bits of the location counter, and if not a 00, you'll have to add the appropriate value to make the last two bits become 00 -> this causes the value to be evenly divisible by 4 (a fullword boundary). For halfword alignment, you have to make the last bit of the location counter a 0 (halfword alignment == evenly divisible by 2). In addition, you should be adding Error Catching code to this lab to check for invalid assembler statements; for example, USANG *.12 or LBR 5,5 are invalid opcodes your assembler should flag. And even though the sample program has no character constants, add code to process character DC and DS instructions (test this by adding a few sample lines to the sample program). Extra Credit: process repetition factors that precede constants, eg. X DS 2F or Y DC 3C'AB'
What you need to know: Bit manipulation instructions, and the use of the POT and MOT tables to find invalid instructions.
Lab 7 - Pass 1/program 3: In this lab, you define and construct the SYMTAB (symbol table). The symbol table should contain 1 entry for each label defined in the program you are assembling. You'll have to look up values of these labels in pass 2 to compute effective addresses and displacements using the symbol table. Each entry in the symbol table contains 3 fields: the symbol name (or label), its value (eg the program counter), and the length in bytes.
What you need to know: Setting up tables and designing code that searches and ultimately points to entries within these tables.
Extra Credit: Either sort the symbol table at the end of this pass, setting up binary search in pass 2, or, populate the symbol table using a hashing algorithm. Comment and print your results.
Lab 8 - Pass 2/program 1: In this lab, you will begin to construct object code; here in lab 8, for constants defined in the DC statements. All object code will be saved in a table called PROG, and should be printed under the object code column in your output. You'll first have to modify your LAST routine to set a switch to pass 2 to make the assembler do new things! In addition, you have to set up a Base Register Table (BTABLE) in this lab which will hold for each Base Register defined with a USING statement, the value corresponding to that register. For the sample program, your USING instruction is simply USING *,12 - this means the current value of the location counter is stored in the table along with register 12. Finally, you'll have to leave stubs for RR and RX processing (RR EQU * and RX EQU *) which will be filled in the last 2 lab assignments. Given that pass 2 uses alot of the pass 1 routines, some thought should go into your overall software architecture so you don't create spaghetti code!
Output Listing
| LOC | OBJECT CODE | SOURCE STATEMENT | ||
| 000000 | CSECT | PROG | CSECT | |
| 000000 | 05 | BALR | 12,0 | |
| 000002 | USING | USING | *,12 | |
| 000002 | 58 | AGAIN | L | 5,X |
| 000006 | 5A | A | 5,Y | |
| 00000A | 13 | LCR | 5,5 | |
| 00000C | 50 | ST | 5,Z | |
| 000010 | 07 | BCR | 15,14 | |
| 000014 | 00000004 | X | DC | F'4' |
| 000018 | 00000006 | Y | DC | F'6' |
| 00001C | Z | DS | F | |
| 000020 | END | END | ||
PROG and BTABLE
Note, align these tables on a doubleword boundary to minimize problem with storing parts of instructions at a time! ( DS 0D, followed by PROG DC 40C' ' )
PROG BTABLE
40404040 40404040 40404040 40404040 00000002 0C
40404040 00000004 00000006 40404040 Baddr Breg
40404040 40404040
Lab 9 - Pass 2/program 2: Here, you will construct object code for all the RR instructions you encounter (BALR, LCR, and BCR in the sample program). When an RR instruction is recognized in the MOT table, you must convert the register contents to hex equivalents for storage in the PROG table, and the complete object code (OP+R1+R2) must be converted to ASCII for the object code column of the print line. Additionally, you should add code so that you output line numbers for each instruction. Extra credit: output a column for an ADDR1 and ADDR2 fields.
Output Listing
| LOC | OBJECT CODE | SOURCE STATEMENT | ||
| 000000 | CSECT | PROG | CSECT | |
| 000000 | 05C0 | BALR | 12,0 | |
| 000002 | USING | USING | *,12 | |
| 000002 | 58 | AGAIN | L | 5,X |
| 000006 | 5A | A | 5,Y | |
| 00000A | 1355 | LCR | 5,5 | |
| 00000C | 50 | ST | 5,Z | |
| 000010 | 07FE | BCR | 15,14 | |
| 000014 | 00000004 | X | DC | F'4' |
| 000018 | 00000006 | Y | DC | F'6' |
| 00001C | Z | DS | F | |
| 000020 | END | END | ||
PROG Output
PROG
05C04040 40404040 40401355 40404040
07FE4040 00000004 00000006 40404040
40404040 40404040
Lab 10 - Pass 2/program 3: In the last lab, you must convert all the RX instructions found to object code, store them in the appropriate place in the PROG table (determined by the value of the location counter), and print out this object code as part of the output.
To convert RX instructions, first convert the R1 operand (same as for RR instructions). The second operand refers to a symbol already stored in the symbol table ... you'll have to look up the symbol and its corresponding value. To compute the remaining portions of the object code, the X2 field will be 0, the B2 field will be the value of the base register in the BTABLE, and the D field is equal to Value - BASE Reg Address.
What you need to know: You don't really have to add anything terribly new ... all the "convert to ASCII and binary" routines you've already created for DC and RR processing can do the job for you.
Output Listing
| LOC | OBJECT CODE | SOURCE STATEMENT | ||
| 000000 | CSECT | PROG | CSECT | |
| 000000 | 05C0 | BALR | 12,0 | |
| 000002 | USING | USING | *,12 | |
| 000002 | 5850C012 | AGAIN | L | 5,X |
| 000006 | 5A50C016 | A | 5,Y | |
| 00000A | 1355 | LCR | 5,5 | |
| 00000C | 5050C01A | ST | 5,Z | |
| 000010 | 07FE | BCR | 15,14 | |
| 000014 | 00000004 | X | DC | F'4' |
| 000018 | 00000006 | Y | DC | F'6' |
| 00001C | Z | DS | F | |
| 000020 | END | END | ||
PROG Output-BEFORE EXECUTION
05C05850 C0125A50 C0161355 5050C01A
07FE4040 00000004 00000006 40404040
Extra Credit: If you could execute this program, what exactly would the PROG output look like after execution?
Last Updated by DrB on 09/23/03
(c)Domanski, 1995. All Rights Reserved.