Given the code presented in example 6.18, consider generating code for a while loop. A while loop has the following general form
What code would be generated for this construct? Be as specific as possible. You may indicate the code generated for the various expressions as codegen(Expr1), codegen(Expr2), and codegen(Expr3).
Here is the target EWE code for the program in example 6.17.
The label L0 marks the start of the else part of the expression. The label L1 marks the end of the if-then expression. The opposite of the relational operator is used in the target code so if the condition is false then the code will go to the else clause. Otherwise, the then clause is executed. In line 13 (the end of the then clause), the code jumps past the else clause to the end of the if-then expression so only the then or else code is executed, but not both. There is one subtle problem in if-then-else expression code generation. Where is the resulting value when the expression is evaluated? Because register allocation is done at compile-time, knowing which register will hold the result when the program executes is not possible at compile-time. Presumably the choice depends on some input that will not be provided until run-time. However, due to the way register allocation is implemented, it is safe to assume that the else clause result register will always hold the result. This is due to the fact that registers that are pushed and popped from the register stack are symbolic registers. Symbolic registers occupy the same physical memory location when possible. Both the then clause and else clause results are physically stored in the same memory location. In example 6.18 the then clause result is in register R4 and the else clause result is in register R5. But, both R4 and R5 occupy memory location M so using either register name as the result of the whole if-then expression is safe. In example 6.18 line 18, R5 is used as the if-then expression result.
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.Read more
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.Read more
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.Read more
Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.Read more
By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.Read more