# SICP Solutions

### Chapter 5, Computing with Register Machines

#### Exercise 5.49

We need to create a machine that calls compiler internally and assembles the intructions and load them in the same assembler.

Like in the last exercise, i created a procedure compile-and-assemble which returns the compiled and assembled version of the intructions. Note that here we used compiler-machine created for this exercise instead of eceval compared to last exercise.

And now, we just need to add the operatons which are required by:

• Instructions generated by the compiler for eg: extend-environment, set-variable! etc are used in the instructions generated by compiler.
• By the compiler-machine itself, for printing or reading from the prompt like read, user-print etc.

In the machine’s controller code, we just call the compile-and-assemble and set these results in val and execute them by jumping to val.

For return, we set the continue register to so that we are back to the loop.

One more thing, since we do not need to invoke procedures from the evaluator - which was required in previous exercise 5.47 and 5.48 - we should disable the code generated from calling the procedures generated by evaluator. Thus i reverted the changes in procedure compile-procedure-call which were done as part of ex-5.47.

Created a new file ch5-compiler-machine.scm which contains the above mentioned changes: