Assembler Steps
These are the steps your assembler needs to perform
- Read input line from text assembly file
- Parse the opcode (usually the 1st word from the input line).
- Once you know the opcode, you know **part** of the 8-bits you need
to create the final 8-bits for the instruction in the binary.
- Based on the opcode, you know if the next words in the input
line are registers, addresses, immediate, offsets, etc... Parse
these final fields from the input line. At this point you have all
of the 8-bits you need to create the instruction.
- Write the 8-bits for this instruction to the binary (a text file, really) in as
a 2 character hex number.
- Go back to step 1, until all instructions are processed.
The following are some points to keep in mind
- The 1st instruction in your program's assembly input should be the
1st instruction that needs to be executed in your program.
- Branch instructions need special mention. They can typically be
handled in one of two ways:
- When writing your assembly input program to execute the text filter
program, you can manually (by hand) figure out the branch distances and
write the distance as part of the assembly. Note, anytime you add or delete
an instruction from your assembly program will require you to go through
and recalculate all of these constants.
- A different option is to use labels. You can have your assembly
file consist of labels (e.g., L1) for the destination of the
branch. This may require you to "pre-parse" the assembly file once to
(A) find all of the labels, and (B) determine how many instructions
away the destination is from each branch.
- See the turn in instructions for the list of flags your assembler needs to s
upport (to indicate input and output files, etc).