Learn

You may have noticed the use of dollar signs and parentheses in our previous code. These are some MIPS language conventions used to denote direct and indirect memory referencing.

Let’s assume that Register 5 has the value 11010001112 (83910) stored in it. Let us also assume that there is a piece of memory with the address 839, that contains the value 10001110001112 (455110).

When we directly reference something in memory we are telling the assembler that we want the value that is stored in that exact location.

Let’s take a look at an Assembly code example that adds the value of Register 5 to Register 5 and saves the result in Register 6:

ADD $5, $5, $6

Register 6 now contains 110100011102 (167810). 839 + 839 = 1678

When we indirectly reference memory we are telling the assembler that we don’t want to use the value of what is stored in the reference, we want to use that value as the address to another memory location and use the value stored there.

LW $4, ($5) ADD $5, $4, $6

In MIPS we can only perform operations on registers so the first step is to retrieve the value from memory with the Load Word statement and save it into Register 4. When we use the parentheses around Register 5 we are now telling the assembler to go and find the data that is stored in the memory address 839 which was 10001110001112 (455110).

At the conclusion of our ADD statement, Register 6 now contains the value 10101000011102 (539010). 4551 + 839 = 5390.

Instructions

1.

Create a new variable, answer_1, and set it equal to the type of memory addressing that uses the value stored in one location as the address to reference another value.

When creating your answer, make sure the text is in all lowercase.

2.

Create another variable, answer_2, and set it equal to the symbols that surround an indirect memory reference in MIPS.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?