Tasks
The same steps as the lab slide. Do them on a Linux PC with the files from the zip; the tools below help you check your thinking first.
Lab 3.1 · Basic Assembler Functions
- Build and run the starter
gcc -Wall -o sicasm sicasm_starter.c then ./sicasm count.asm. The output is wrong: that is expected. - TODO 1: SYMTAB
Insert each label. Test with dup.asm: it must stop with "duplicate symbol FIRST". - TODO 2: LOCCTR
Apply the size rules (slide 12). Check the LOC column against slide 13, and the length 00A0. - TODO 3: instructions
Opcode, x bit, address, sprintf. Test with undef.asm: "undefined symbol BETA". - TODO 4: BYTE
C'BANANA' → 42414E414E41, X'F1' → F1. Then every row of slide 16 must match. - Compare
diff count.obj count_expected.obj prints nothing when your assembler is right. Then try sumn.asm.
Submit: your sicasm.c, the listing of sumn.asm, and sumn.obj.
Lab 3.2 · Machine-Dependent Assembler Features
- Hand-assemble on paper
Lines 0000–0032 of countx.asm. Write n i x b p e, the disp and the code. Check against slide 14. - Add -m to sicasm
With ./sicasm -m file.asm, write M{loc+1}04 for every instruction with an operand. - Count them
Run it on count.asm: you should get 13 M records. Compare with the 2 of countx.asm. - Relocate by hand
Load count.obj at 5000 instead of 2000: add 3000 to each marked field. LDCH TEXT,X must become 50D027. - Write apply_m() in C
void apply_m(unsigned char *mem, int addr, int halfbytes, int delta); Test it on count.obj. - Explain
In 3 sentences: why does SIC need 13 M records and SIC/XE only 2? What would a big program look like?
Submit: your updated sicasm.c, count.obj with M records, and your apply_m() with a test.
Lab 3.3 · Machine-Independent Features
- EQU with a number
MAXLEN EQU 6: put MAXLEN into SYMTAB with value 6. Its LOC column shows 0006. - EQU with * and A−B
TEXTEND EQU *, TLEN EQU TEXTEND-TEXT. Write eval(): number, *, SYMBOL, SYMBOL−SYMBOL, SYMBOL+number. - LITTAB
struct lit { char text[40]; int addr; int placed; }; Add a literal the first time it is seen. - LTORG and END
Give every waiting literal an address and output it like a BYTE line marked *. - Pass 2
An operand starting with = takes its address from LITTAB. Test: countlit.asm must match countlit_expected.obj. - Break it
Put TLEN EQU TEXTEND-TEXT before TEXT. Your assembler must stop with an error, not print rubbish.
Submit: sicasm_v2.c, the listing and object program of countlit.asm, and the output of task 6.
Try it here
These run in your browser, with no server and no internet. They are built from the same reference programs as the lab, so their output matches what your finished C program should print. They do not replace the real lab: the kernel, gcc and your own code are the point.
Read the files
Every text file from lab03_files.zip. Read here, then download the zip to work on them.