Matching addressing modes to data
Instructions & Addressing Modes

Answer & solution
Official answer: B
Givens and goal
Match P immediate, Q indirect, R base with index, S base with offset to 1 array element, 2 pointer, 3 record field, 4 constant. The choices give different permutations of these matches.
Approach
Write the effective operand or effective address for each addressing mode and identify the high-level data access it implements.
Step-by-step solution
1. Immediate addressing puts the operand value directly in the instruction, such as an encoded literal 7. It naturally represents a constant, so P→4.
2. Indirect addressing obtains an operand’s address through another location or register. A pointer holds an address and is dereferenced to find the actual data, so Q→2.
3. Base-plus-index addressing computes an address from an array base and an index-dependent displacement, conceptually base+i·element_size. Varying i chooses an array element, so R→1.
4. Base-plus-fixed-offset addressing selects a field at a fixed byte displacement from the start of a record, such as record_base+offset_of_field. Thus S→3.
5. The complete mapping is (P,Q,R,S)→(4,2,1,3), option B. The key distinction is a varying index for array positions versus a fixed layout displacement for a named record field; both may ultimately use addition in the hardware.
![Question 11, GATE 2017: C declaration: struct data { int marks[100]; char grade; int cnumber; }; struct data student; Register R1 holds the base address of student. How to access student.grade efficiently? A postincrement (R1)+; B predecrement −(R1); C register direct R1; D indexed X(R1), with signed 16-bit displacement X.](../../../assets/questions/CS-2017-S1-Q21-1.webp)

![Question 66, GATE 2005: Match 1 A[I]=B[J]; 2 while(*A++); 3 int temp=*x; to (a)indirect,(b)indexed,(c)autoincrement addressing. A (1, c),(2, b),(3, a); B (1, a),(2, c),(3, b); C (1, b),(2, c),(3, a); D (1, b),(2, b),(3, c). GFG D begins (1, b); GateForum D begins (1, a).](../../../assets/questions/CS-2005-Q66-1.webp)
![Question 66, GATE 2005: Match 1 A[I]=B[J]; 2 while(*A++); 3 int temp=*x; to (a)indirect,(b)indexed,(c)autoincrement addressing. A (1, c),(2, b),(3, a); B (1, a),(2, c),(3, b); C (1, b),(2, c),(3, a); D (1, b),(2, b),(3, c). GFG D begins (1, b); GateForum D begins (1, a).](../../../assets/questions/CS-2005-Q66-2.webp)

