Question: language for a compiler has these five Exercise 5 Suppose the target assembly language instructions for integers: push address add sub mul pop address In
language for a compiler has these five Exercise 5 Suppose the target assembly language instructions for integers: push address add sub mul pop address In these instructions, an address is the name of a static variable (whose actual ad- dress will be filled in by the loader). The machine maintains a stack of integers, which can grow to any size. The push instruction pushes the integer from the giy- en 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 in- teger, 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 Using this assembly language, give translations of the assignment statements in Exercise 4. Use as few instructions as possible. 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: ri, r2, and r3. The load instruction loads the 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, rl load n,r2 mul ri, r2,ri load offset, r2 add r2,ri,r1 store ri, result Chapter 4-Language sy ne this assembly language, give translations of the following assignment state- ments. Use as few instructions as possible. a. net :- gross - costs b. volume := (length + width) + height c. cube := (x + x) + x d. final := ((a - abase) * (b - bbase)) * (c - cbase) language for a compiler has these five Exercise 5 Suppose the target assembly language instructions for integers: push address add sub mul pop address In these instructions, an address is the name of a static variable (whose actual ad- dress will be filled in by the loader). The machine maintains a stack of integers, which can grow to any size. The push instruction pushes the integer from the giy- en 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 in- teger, 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 Using this assembly language, give translations of the assignment statements in Exercise 4. Use as few instructions as possible. 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: ri, r2, and r3. The load instruction loads the 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, rl load n,r2 mul ri, r2,ri load offset, r2 add r2,ri,r1 store ri, result Chapter 4-Language sy ne this assembly language, give translations of the following assignment state- ments. Use as few instructions as possible. 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
Get step-by-step solutions from verified subject matter experts
