Final answer:
The correct code for the three-address statement Option A. x = a[i] + b[j] involves loading the addresses of a and b, adding the indexes multiplied by the size of each element, loading the values from memory, adding them together, and storing the sum in the register holding x.
Step-by-step explanation:
The correct answer is option (a)
The three-address code for the statement x = a[i] + b[j] would be:
- Load the address of a into a register (e.g., R1)
- Add the index i multiplied by the size of each element (4 bytes) to the register holding the address of a to get the address of a[i] (e.g., R2)
- Load the value from the address in R2 into a register (e.g., R3)
- Load the address of b into a register (e.g., R4)
- Add the index j multiplied by the size of each element (4 bytes) to the register holding the address of b to get the address of b[j] (e.g., R5)
- Load the value from the address in R5 into a register (e.g., R6)
- Add the values in R3 and R6
- Store the sum in the register holding x (e.g., R7)
The cost involved in this operation would be the cost of loading the addresses and values from memory, which depends on the architecture being used.