what is the use of ori in this part of MIPS code?

The two instructions load a constant of 0x05 into register $s0 and 0x07 into register $s1. MIPS doesn’t has an instruction that directly loads a constant into a register. Therefore logical OR with a operand of zero and the immediate value is is used as a replacement. It has the same effect as move. Translated … Read more

Bubble sort algorithm in MIPS

I’m trying to write a procedure in assembly that sorts an array using bubble-sort algorithm but I’m having a problem which is: In line 22, when the first iteration executed nothing is wrong, program loads array[i+1] perfectly into registrar $a1 and if the swap condition is valid, program swaps without any problem. However, in the … Read more

What is the difference between la and li in opcodes in MIPS?

They’re fairly similar, as both are (mostly) used for loading immediate values. Both of them are also pseudo-instructions, so it’s really up to each assembler that supports them to determine exactly how they should function. li stands for Load Immediate and is a convenient way of loading an immediate up to 32 bits in size. Instructions like addi and ori can … Read more

What exactly does the lb instruction do?

The answer would be c) 0xffffff88. The lb instructions sign-extends the byte into a 32-bit value. I.e. the most significant bit (msb) is copied into the upper 24 bits. 0x88 == 0b10001000, i.e. the msb is 1. So the upper 24 bits will be 0b111111111111111111111111 == 0xffffff.

Mips how to store user input string

Ok. I found a program buried deep in other files from the beginning of the year that does what I want. I can’t really comment on the suggestions offered because I’m not an experienced spim or low level programmer.Here it is:

Why doesn’t there exists a subi opcode for MIPS?

When you create an instruction set, you’re bound by some constraints, such as the total number of instructions you can create. The MIPS creators realized that there isn’t a need for subi (because you can add a negative number with addi using 2’s complement), and they simply made the decision to forego making that instruction. It may have been … Read more

mips .word function and differences between 2 codes

On MIPS, the size of a pointer to your data is .word, usually 32 bits. Furthermore, MIPS requires that your data is aligned to certain addresses depending on the type (i.e. size) of the data itself. First let’s look at the pointers and data that you declare in your program’s .data section: msg and msg_data can be considered labels or symbolic names for your data, and you … Read more

what does .space do in mips?

.space Len directive instructs the assembler to reserve Len bytes. As every word has 4 bytes, when Len is 20 you are instructing the assembler to reserve 5 words. For example if you have then other_data will be 20 bytes after array address. Due to architectural constraints in MIPS you may need to also instruct the assembler to align the … Read more