灯下 登录
计算机科学 / SICP / 5.2.4 Monitoring Machine Performance

Exercise 5.18 · 习题

Exercise 5.18: Modify the make-register

procedure of 5.2.1 so that registers can be traced. Registers

should accept messages that turn tracing on and off. When a register is

traced, assigning a value to the register should print the name of the

register, the old contents of the register, and the new contents being

assigned. Extend the interface to the machine model to permit you to turn

tracing on and off for designated machine registers.

练习 5.18:修改 5.2.1 节的 make-register 过程,使寄存器可以被追踪。寄存器应接受开启和关闭追踪的消息。当寄存器处于追踪状态时,向该寄存器赋值时应打印寄存器名、寄存器原有内容以及即将赋入的新内容。扩展机器模型的接口,使其能够为指定的机器寄存器开启和关闭追踪。