Exercise 5.12: The simulator can be used to help
determine the data paths required for implementing a machine with a given
controller. Extend the assembler to store the following information in the
machine model:
a list of all instructions, with duplicates removed, sorted by instruction type
(assign, goto, and so on);
a list (without duplicates) of the registers used to hold entry points (these
are the registers referenced by goto instructions);
a list (without duplicates) of the registers that are saved
or restored;
for each register, a list (without duplicates) of the sources from which it is
assigned (for example, the sources for register val in the factorial
machine of Figure 5.11 are (const 1) and ((op *) (reg n)
(reg val))).
Extend the message-passing interface to the machine to provide access to this
new information. To test your analyzer, define the Fibonacci machine from
Figure 5.12 and examine the lists you constructed.
练习 5.12:模拟器可用于帮助确定实现给定控制器的机器所需的数据通路。扩展汇编器,使其在机器模型中存储以下信息:
所有指令的表(去除重复项),按指令类型(assign、goto 等)排序;
用于保存入口点的寄存器的表(去除重复项)——即 goto 指令所引用的寄存器;
被 save 或 restore 的寄存器的表(去除重复项);
对于每个寄存器,列出向其赋值的来源的表(去除重复项)——例如,图 5.11 中阶乘机器里寄存器 val 的来源为 (const 1) 和 ((op *) (reg n) (reg val))。
扩展机器的消息传递接口,以提供对这些新信息的访问。为了测试你的分析器,请定义图 5.12 中的 Fibonacci 机器,并检查所构造的各个表。