Introduction : final project of system programming course.
-
Basic 2-pass assembler
-
OS : Windows 10
-
Language : Python 3.9.1
-
Files : source.txt , pass1.py , pass2.py , OPTAB.py
$ python3 pass1.py
$ python3 pass2.py
-
執行 pass1.py
-
輸入 source code 檔名
-
assembler 開始執行 PASS 1
-
PASS 1 結束後
-
執行 pass2.py
-
assembler 開始執行 PASS 2
-
PASS 2 結束後
-
OPTAB
-
REGTAB
-
SYMTAB
- Functions : write_intermediate() , process_line() , print_pass1() , print_SYMTAB() , print_intermediate()
- Read line by line from source file
- Parse each line to get lable , instruction , target
- line.split()
- use line length and check positions
- Determine instruction
- call process_line()
- use write_intermediate() to write line with location imformation into intermediate file
- add label and its location into symbol table
- Use print_pass1() to print result
- print_SYMTAB()
- print_intermediate()
- Functions : twosComplement() , get_op() , get_result_1() , get_result_2() , get_disp() , write_file() , write_record() , print_result() , print_obcode() , print_pass2()
- Read line by line from intermediate file
- Parse each line to get location , lable , instruction , target
- line.split()
- use line length and check positions
- Determine instruction ( flag n , flag i )
- Use get_op() to get instruction op
- Use get_disp() to get intruction disp ( flag b , flag p )
- Check for '+' in instruction, '#' or '@' in target ( flag e , flag n , flag i )
- Use get_result_1() for format 3 and get_result_2() for format 4 to generate obcode
- Use write_file() to write into result file
- Use write_record() to write into obcode file
- if number of obcode > 9 , next T record
- if loc between two obcode too big ( I use > 4) , next T record
- Use print_pass2() to print result
- print_result()
- print_obcode()
- This code is written by Shih-Jieh Chen.
- All rights reserved.
- Date : 2022/01/20
-
Add M record.
-
If your assembly is a one-pass assembly.
-
If the implementation of your assembly includes “Literals”
-
If the implementation of your assembly includes “Symbol-defining Statements”
-
If the implementation of your assembly includes “Program Blocks”
-
If the implementation of your assembly includes “Control Sections