灯下 登录
计算机科学 / SICP / 5.2.2 The Assembler

Exercise 5.8 · 习题

Exercise 5.8: The following register-machine code
is ambiguous, because the label here is defined more than once:

start
(goto (label here))
here
(assign a (const 3))
(goto (label there))
here
(assign a (const 4))
(goto (label there))
there

With the simulator as written, what will the contents of register a be

when control reaches there? Modify the extract-labels procedure

so that the assembler will signal an error if the same label name is used to

indicate two different locations.

练习 5.8:下面的寄存器机器代码存在歧义,因为标号 here 被定义了两次:

start
(goto (label here))
here
(assign a (const 3))
(goto (label there))
here
(assign a (const 4))
(goto (label there))
there

按照模拟器目前的实现,当控制到达 there 时,寄存器 a 的内容是什么?修改 extract-labels 过程,使得汇编器在同一标号名被用于指示两个不同位置时发出错误信号。

Racket #lang sicp
start
 (goto (label here))
here
 (assign a (const 3))
 (goto (label there))
here
 (assign a (const 4))
 (goto (label there))
there