Answer:
Following is given the answer step by step:
Explanation:
First of all we will write a program using MARIE that will support the statement: Sum = (A + B) - (C + D). All the necessary comments are given in front of each statement:
Load    A                   # variable A will be loaded
Add     B                   # B will be added to A
Store   Temp1          # A + B will be stored in Temp1
Load    C                  # C will be loaded in memory
Add     D                  # D will be added to C
Store   Temp2         # C + D will ge stored in Temp2
Load    Temp1          # Temp1 will be loaded in the memory
Subt     Temp2         # Temp2(A + B) get subtracted from Temp1(A - B)
Store    Sum             # (A + B) - (C + D) will get stored in Sum.
We can see from above program that memory is accessed 9 times. While if C + D get executed first than memory accesses will be reduced to 7.
Above same program could be written using an architecture of 4 registers:
The program is as follows:
Load   R1 , A      #A  will be loaded into R1
Load   R2 , B     # B will be loaded into R2
Add     R1 , R2    # R2 gets added to R1 and the result is stored in R1 (A + B)
Load   R3 , C      # C loaded into R3
Load   R4 , D
     # D loaded into R4
Add    R3 , R4    # Value in R4 gets added into R3 and R3 becomes (C + D)
                           #no memory accesses required for this operation
Subt   R1 , R4     #R4 (C + D) gets subtracted from R1 (A + B)
                          #no memory accesses required for this operation
Store  Sum        # The recent value will be stored into Sum
Here memory is accessed 5 times in total.
<h2>I hope it will help you!</h2>