This is a repository that simulates a SIC assembler, which is completed in three stages.
This program reads a sic assembly program from stdin and writes the normalized output to stdout.
- Remove comment
- Transform charactesrs to uppercase (except for lowercase constant)
- Adjust the postion
g++ step-01.cpp -o my-split
./my-split < Test/SAMPLE-input-[1-3] > k-1
#check
diff Test/SAMPLE-split-[1-3] k-1
There are three input files, named SAMPLE-input-1, SAMPLE-input-2, and SAMPLE-input-3. Their corresponding output files are SAMPLE-split-1, SAMPLE-split-2, and SAMPLE-split-3.
This exercise reads the output of the previous program (step-01) through stdin and writes the output to two files, INTFILE and SYMTAB.
- The INTFILE is the intermediate file which format is like the input except the loc is inserted at the beginning of each line.
- The SYMTAB is the symbol table. Its first line contains the program name, starting address, and program length where the last two items are written in hexdecimal. Its following lines show the content of the symbol table.
- Note the order of symbol in the symtable does not need to follow the order the symbol appeared in the input file.
g++ step-02.cpp -o my-pass1
cat SAMPLE-split-[1-3] | ./my-pass1
# or use your own program
cat Test/SAMPLE-input-[1-3] | ./my-split | ./my-pass1
#check
# Compare with sample INTFILE. This should output nothing.
diff INTFILE SAMPLE-INTFILE-[1-3]
# Sort and compare with the sample SYMTAB. This should output nothing.
./sort-sym SYMTAB | diff - SAMPLE-SYMTAB-[1-3]
For this program, the content of SYMTAB should be read into a table in memory, and the searching for symbols should be done on that table, not searching the file SYMTAB every time.
- The input of this exercise are two files, SYMTAB and INTFILE, which are the output of the step-02.
- The output of this exercise, the object file, should be printed to the stdout. You may redirect it to a file.
g++ steo-03.cpp -o my-pass2
cat SAMPLE-split-[1-3] | ./my-pass1
./my-pass2 > OBJ