Discussion
Consider an array A of n elements of integer type for assignment statement
Value = A[i]
Which of the following is three address code representation for address computation and value assignment above ?
Answer: A
The correct three-address code is Temp1 = i * sizeof (integer), Temp2 = &A + Temp1, Value = *(Temp2).
The address of A[i] is the base address of A plus i times the size of one element. So the code first scales the index (Temp1 = i * sizeof(integer)), then adds it to the base address (Temp2 = &A + Temp1), and finally loads the value stored at that address (Value = *(Temp2)).
Option (B) uses Temp2 before it has been computed and stores into the array instead of reading from it. Options (C) and (D) multiply the base address itself, which has no meaning in address arithmetic: the base must be added, not scaled.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development