MIPS program jr $ra instructions and stack handling

On function entry, ra holds the return address where our caller wants us to jump when we’re done. The function preamble saves it to the stack because the function body uses jal to make function calls. jal overwrites ra so we need to save/restore our own return address around that. When the function is complete we can restore the things we saved, then … Read more

Greater than, less than equal, greater than equal in MIPS

I’m assuming that the pseudocode executes sequentially, so an earlier condition being true means you go there and never reach the later if statements. This makes the last branch guaranteed taken if it’s reached at all, so it doesn’t even need to be conditional. (Also assuming that this is a MIPS without a branch-delay slot.) … Read more

Difference between “move” and “li” in MIPS assembly language

The move instruction copies a value from one register to another. The li instruction loads a specific numeric value into that register. For the specific case of zero, you can use either the constant zero or the zero register to get that: There’s no register that generates a value other than zero, though, so you’d have to use li if you wanted some … Read more

MIPS Assembly – lui $t0, 4097?

4097 = 1001 hex so, the first instruction puts 0x10010000 into register t0. lui is “load upper immediate”, with “upper” meaning the upper 16 bits, and “immediate” meaning that you are giving it a literal value (4097). 4097 as an “upper” value becomes 0x10010000. ori is “or immediate”, with 8 being the immediate value, so … Read more

error: “store address not aligned on word boundary”

Are you sure that the error is happening on that line? I think the error is actually happening here: The problem is that you’re trying to store a word (because you’re using sw) to an address that’s not word-aligned. 0xFFFF0011 is not word-aligned. The reason why 0xFFFF0010 works is because it is word-aligned. A word … Read more

MIPS ‘nor’ usage in code

In my textbook, there are these lines of code: I understand the addu function, but when I get to the nor function and everything afterward, I don’t understand what it does. The textbook just says t3 = the 2’s complement of t1 – 1 for the 2nd line, but I don’t understand how that works … Read more

Storing a user’s input in MIPS

You are not using the read string system call correctly. I suspect you haven’t actually looked at the documentation on how to use it. You have to pass two arguments: So you should do something like: Nevertheless, this shouldn’t cause a crash since $a0 should still hold the address of firstPromptString that you set up for the printing, earlier, and that … Read more