Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

6.5 Identify at least 10 methods used for external recruitment.

Answered: 1 week ago

Question

6.6 Explain two strategies used to recruit nonpermanent staff.

Answered: 1 week ago