Question
Give an example of an assignment like those in Exercise 4 that cannot be translated into the assembly language of Exercise 4 because of a
Give an example of an assignment like those in Exercise 4 that cannot be translated into the assembly language of Exercise 4 because of a shortage of registers. (Any such statement can be translated if the compiler is allowed to invent and use additional variables in memory, but do not allow this.) Give a translation of your statment into the assembly language of Exercise 5. Exercise 4: Suppose the target assembly language for a compiler has these five instructions for integers: load address, reg add reg, reg, reg sub reg, reg, reg mul reg, reg, reg store reg, address In these instructions, an address is the name of a static variable (whose actual address will be filled in by the loader). A reg is the name of an integer register,a special extra-fast memory location inside the processor. The target assembly language has three integer registers: r1, r2, and r3. The load instruction loadsthe integer from the given memory address into the given register. The add instruc- tion adds the second register to the first register and places the result in the third register. The sub instruction subtracts the second register from the first register and places the result in the third register. The mul instruction multiplies the first register by the second register and places the result in the third register. The store instruction stores the integer from the given register at the given memory ad- dress. So, for example, the compiler might translate the assignment result := offset+(width*n) into this: load width,r1 load n,r2 mul r1,r2,r1 load offset,r2 add r2,r1,r1 store r1,result a.) net : = gross - costs b.) volume : = (length * width) * height c.) cube : = (x * x) * x d.) final : = ((a - abase) * (b - bbase)) * (c - cbase) Exercise 5: Suppose the target assembly language for a compiler has these five instructions for integers: push address add sub mul pop address In these instructions, an address is the name of a static variable (whose actual address will be filled in by the loader). The machince maintains a stack of integers, which can grow to any size. The push instrus\ction pushes the integer from the given memory address to the top of the stack. The add instruction adds the top integer on the stack to the next-from-the-top integer, pops both off, and pushes the result onto the stack. The sub instruction subtracts the top integer on the stack from the next-from-the-top integer, pops both off, and pushes the result onto the stack. THe mul instruction multiplies the top integer on the stack by the next-from-the-top integer, pops both off, and pushes the result onto the stack. The pop instruction pops an integer off the stack and stores it at the given memory address. So, for example, the compiler might translate the assignment result := offset+(width*n) into this: push offset push width push n mul add pop result a.) net : = gross - costs b.) volume : = (length * width) * height c.) cube : = (x * x) * x d.) final : = ((a - abase) * (b - bbase)) * (c - cbase)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started