Exercise 4 suppose the target assembly language for a compil

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: r 1, 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 offsett (width n) into this: load width, r1 load n, r2 mul r1, r 2, r 1 load offset, r2 add r2, r 1, r 1 store 1, result

Solution

a. net:= gross-costs

ans-

load gross ,r1
load costs ,r2
sub r1,r2,r1
store r1,net

b.volume:=(length*width)*height

Ans

load length,r1
load width ,r2
load heigth,r3
mul r1,r2,r1
mul r1,r3,r1
store r1,volume

c.cube:=(x*x)*x

load x,r1
load volume,r2
mul r1,r1,volume
mul r1,volume,volume
store volume,cube

d. final:=((a-aBase)*(b-bBase)*(c-cBase))

load a,r1
load aBase,r2
sub r1,r2,r3
load b,r1
load bBase,r2
sub r1,r2,r4
load c,r1
load cBase r2
sub r1,r2,r5
mul r3,r4,r3
mul r3,r5,r3
store r3,final

 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site