Consider the following program segment. Here and are the general purpose registers.
Assume that the content of memory location is and the content of the register is . The content of each of the memory locations from to is . The program is loaded from the memory location . All the numbers are in decimal.
Assume that the memory is word addressable. The number of memory references for accessing the data in executing the program completely is
View worked solution
Answer: D
To find the number of memory references for accessing the data, we only count the memory read and write operations performed on data operands (excluding instruction fetches).
1. Instruction Outside the Loop
MOV R1, (3000): This instruction reads the data from memory location3000and loads it into registerR1.
Data memory references = 1 (Read operation).
After this instruction, the value in register R1 becomes 10.
2. Loop Execution
The loop starts at the label LOOP and ends with BNZ LOOP. Since R1 is initialized to 10 and decremented by 1 in each iteration (DEC R1), the loop will execute exactly 10 times.
Let's analyze the data memory references inside one iteration of the loop:
MOV R2, (R3): Reads data from the memory location pointed to byR3.
Data memory references = 1 (Read operation).ADD R2, R1: Register-to-register operation.
Data memory references = 0.MOV (R3), R2: Writes data to the memory location pointed to byR3.
Data memory references = 1 (Write operation).INC R3: Register operation.
Data memory references = 0.DEC R1: Register operation.
Data memory references = 0.BNZ LOOP: Branch instruction (control transfer).
Data memory references = 0.
Thus, each iteration of the loop performs exactly data memory references.
3. Total Data Memory References
Therefore, the total number of memory references for accessing the data is 21.
Free practice · Your answers on this page are not saved.
