67.1k views
3 votes
More registers appear to be a good thing, in terms of reducing the total number of memory accesses a program might require. Given an arithmetic example, Sum=(A+B)-(C+D), support this statement. First, determine the number of memory accesses necessary using MARIE and the two registers for holding memory data values (AC and MBR). Then perform the same arithmetic computation for a processor that has more than three registers to hold memory data values

User Proski
by
8.1k points

1 Answer

4 votes

Answer:

Following is given the answer step by step:

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:

  • R1
  • R2
  • R3
  • R4

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.

I hope it will help you!

User Gaurav Bansal
by
8.5k points