- #1
SuperSusanoo
- 7
- 1
Homework Statement
We covered the following addressing modes in class:
• Absolute
• Register indirect
• Based (base + displacement)
• Scale indexed (base + index × constant)
• Memory indirect
• Auto increment/decrement (by 1 byte)
Consider the following high-level programs:
(1)
Code:
int a = 0; uint8_t D[100]; // D is allocated in memory
While (a < 100){
D[a] = a + 5;
a += 1; }
Code:
int a = 0; int D[100]; // D is allocated in memory
While (a < 100) {
D[a] = a + 5;
a += 1; }
Code:
int *p; // *p is allocated in memory
*p = 100;
Code:
int **p; // *p and **p are allocated in memory
**p = 100;
Assume that in the first two programs, a register contains the address of the start of the array, and in the last two programs, a register contains the value of p.
For each of the above four programs, which of the addressing modes, do you think, would lead to the minimum number of instructions? (Note that no addressing mode fits perfectly. You might require other instructions for address computation.)
Homework Equations
• Displacement (based): address = [R2+immed], e.g., #20(R2)
• Index-base: address = [R2+R3]
• Memory-indirect: address =[mem[R2]]
• Auto-increment: address=[R2], R2= R2+1
• Auto-indexing: address =[R2+immed], R2=R2+immed
• Scaled (scale-indexed): address =[R2+R3*immed1+immed2]
• PC-relative: address =[PC+imm]
The Attempt at a Solution
[/B]
At this point , I am looking for approaches. What would be a good start?. I know that giving solutions away is not allowed. Maybe it would be good if someone can walk me through the first piece code and then I can do the others. I think a good start would be to write the code in MIPS and then analyze each instruction, nevertheless I don't understand how instructions relate to addressing modes. I will be updating the thread with future appoaches
1) Displacement based because we will be computing the address of each index by using an offset which is the immediate value. In this case the offset is 4 since it's an array of integers and the register contains the address of the first index of the array
Last edited: