6.1.汇编语言与程序
Assemble Program and Assembler
1.Basic assembler logic
Repeat:
- Read the next Assembly language command.
- Break it into the different fields it is composed of.
- Lookup the binary code for each field.
- Combine these codes into a single machine language command.
- Output this machine language command.
One thing we need to worry about: Symbols:
Two cases:
- Labels: When jumping into a certain part, you give it a
name instead of hard core the address.
JMP loop
- Variables: You give a variable name rather than always
refer to its exact address in memory.
load R1, weight
- Labels: When jumping into a certain part, you give it a
name instead of hard core the address.
To convert it into concrete address, we use a symbol table:
To maintain such table:
- When we first meet a symbol, we need to allocate a new memory location to hold it. For the assembler, it will find the next memory location that's available.
- When we meet it again, we simply refer to its address in the table.
One special case: Forward references: We can jump into a label before where it was defined. There are two ways to handle it:
- Use a little bit to remember that we've set the labels but don't know where it is yet. We leave it blank until label appears.(more complicated)
- In first pass just figure out all address.
Related Issues not found
Please contact @fyerfyer to initialize the comment