MIPS Pseudoinstructions Dealing With li (big, small) - mips

As a disclaimer, this is a for a school assignment, but I've been trying to understand this specific section of my homework for a few hours and I'm not finding any solution. I've googled, attempted to look up videos, read my book, etc.
I have a general gist of the normal MIPS instructions (still very much a beginner), but I'm very confused with some of the pseudoinstructions. We are asked to convert 10 or 12 pseudoinstructions to MIPS instructions.
I understand the simple pseudoinstructions, such as:
move &t1, $t2 # add $t1, $t2, $zero
But I'm very confused at ones involving "big," and "small," and "li"
li $t1, small (the hint we're given is "$t1 = small" which makes no sense to me, what is "small" in this context?).
Where I'm confused is, usually an immediate relates to a hard coded value, like 1 or 5, but I see no hard coded value. What am I supposed to be storing in $t1? I read that small means to 16 bit numbers and big is 32 bit, but what number are they referencing in this pseudoinstruction? There is only one register here and no hard value, what am I loading into $t1?
Thank you very much.

Related

branch instructions, MIPS (using bare mode only)

I wonder if anyone knows if beq looks only at a specific bit (LSB) when branching to lable or does it look at the value of the entire register?
I am trying to implement multiplication routine
register t1 has 5(0x0000 0101) i am loading only a byte.
this instruction:
beq $t1,1, label -does not work for some reason.
when I go through the code step by step (i am using xspim -bare mode) it goes through the instruction and then just go to the next line of code when it should be skipping it because the lsb of $t1 is 1
Thanks !

How do I print a specific bit of a number?

I'm struggling with this question:
Prompt the user to enter a number, print the number in 16-bit two's complement
To print the number you will print each bit as either the string "1"
or the string "0", using a loop that will print one bit in each
iteration. Start printing with bit 15. (Recall that we number the bits
starting from 0 at the low order bit.) In your loop test bit 15, and
then print either "1" or "0". Use a shift instruction to get the next
bit into position 15 before repeating.
I unfortunately missed a lecture that was about shifts and using masks, so I don't really have much understanding of how I would go about doing this lab. How can I print a specific bit of a number? I understand that I just keep printing bit 15, and then doing a shift left, but I have no idea this would be done in MIPS. Any help would be very much appreciated.
EDIT:
I understand the shifting perfectly, it's just printing the bit thats confusing me.
For example, if the number I wanted to convert to two's complement was 25 and is in register $t0.
First I print the 15th bit. Then I do a shift left. And then I repeat 15 times.
It should look something like this:
# Print bit
sll $t0, $t0, 1
I just don't get how to print the first bit at spot 15.
break down the problem --
1. how to print the bit, and
2. how to determine the bit's value
You already know how to determine the bit's value, you test bit 15 and keep shifting the other bits into position 15.
How are you expected to "prompt the user" to enter a value? Printing the bit is the same printing a prompt.
Masks are generally used with "bitwise and" or "bitwise or" instructions.
To determine whether a particular single bit is set to 1 in a number,
you take the "bitwise and" of that number with another number (the "mask")
in which that particular bit is set to 1 and all other bits are zero.
(There are other applications where you would want to set more than one bit in
a mask; better get a copy of those lecture notes!)
There are many places to look up the MIPS instruction set. For example, here
or here.
Find a page like those, then search for "shift left" and "bitwise and".
(And remember where you found that document so you can look up other things later!)

What does the shift left logical single cycle datapath use?

I am asked to add the shift left logical instruction to a single cycle datapath. I know I need to feed the SHAMT field to the ALU, but I'm not sure how to do this. I understand the basics of single cycle data paths for R-format, branch, load word, and store word, but I'm not sure how the SLL plays in... Can anyone help explain how a single cycle SLL datapath works?
If this is the wrong form for this post, I'd be much obliged if someone would direct me to the correct site.
You simply need to decode the opcode of the SLL instruction and use it to set the ALUOp input of the ALU to 11. You also need to set the multiplexers to put the source register and the shift amount at the appropriate inputs to the ALU.

Making a calculator in MIPS?

I'm currently learning how to code using MIPS and the QTSPIM emulator. I thought making a simple arithmetic calculator would be good practice, so I started coding.
So far, the program asks for a number, reads the number, asks for an operation (user has to input either the operation symbols +,-,*,/ or the initials a,s,m,d). The next step would be to compare the received input with something...
This is the part I'm stuck at.
My first thought was to have 4 registers with the characters already in them, so I tried
li $t5,a
li $t6,s
li $t7,m
li $t8,d
That, however, just gives me a syntax error. I tried a couple other similar ways, but kept getting an error.
My objective was to compare the user input to those 4 registers and then move on to the operation
beq $t2,$t5,add
beq $t2,$t6,sub
beq $t2,$t7,mul
beq $t2,$t8,div
Where $t2 contains the character input by the user. It then branches off to the appropriate label to perform the operation.
Is there an easier way to do this that I'm overlooking?
Thanks for your time.
Well, I managed to solve my own problem XD
The solution is a bit primitive, but it works...
Changed the operation prompt to "1 for addition, 2 for subtraction, 3 for multiplication, 4 for division" and compared the user input with those,
beq $t2,1,add
beq $t2,2,sub
beq $t2,3,mul
beq $t2,4,div
And the rest is just the operations themselves.
Thought I'd leave this here just in case someone else runs into a similar problem.
Maybe I'll add memory and clear functions
To set a register with an ASCII code, you need to enclose it with single quotes.
In your example it would be
li $t5,'a'
li $t6,'s'
li $t7,'m'
li $t8,'d'

Microprogramming in MIPS

I am learning about micro programming and am confused as to what a micro-instruction actually is. I am using the MIPS architecture. My questions are as follows
Say for example I have the ADD instruction, what would the micro-instructions look like for this? How many micro-instructions are there for the add instruction. Is there somewhere online I can see the list of micro-instructions for the basic instructions of MIPS?
How can I figure out the bit string for an ADD microprogrammed instruction?
Microprogramming is a method of implementing a complex instruction set architecture (such as x86) in terms of simpler "micro instructions". MIPS is a RISC instruction set architecture and is not typically implemented using micro-programming, so there are ZERO microinstructions for the ADD instruction.
To answer your specific question one would have to know what the definition of your particular micro-architecture is.
This is an example of how to load the EPC into one of the registers and add 4-bytes to it:
lw t0, 20(sp) // Load EPC
addi t0, 4 // Add 4 to the return adress
sw t0, 20(sp) // Save EPC
There are "a lot" of instructions that you can use, you can see the MIPS Instruction Set here. In my humble opinion, MIPS is Really neat and easy to learn! A fun fact is that the first Playstation used a MIPS CPU.
Example instructions
lw = load word
la = load address
sw = save word
addi = add immidate
Then you have a lot of conditional instructions such as:
bne = branch not equal
bnez = branch not equal zero
And with these you use j to jump to an adress.
Here is an example from an Exception Handler that I wrote once for MIPS, this is the External Source handler:
External:
mfc0 t0, C0_CAUSE // We could aswell use 24(sp) to load CAUSE
and t0, t0, 0x02000 // Mask the CAUSE
bnez t0, Puls // If the only character left is
// "not equal zero" jump to Puls
j DisMiss // Else jump to DisMiss
In the above example I define an entry point called External that I can jump to, as I do with DisMiss to loop, you generally jump to yourself.
There are some other instructions used here aswell:
mfc0 = move from co-processor 0
To handle labels, I would suggest you check this question/answer out.
Here's a couple of resources on MicroProgramming with MIPS:
Some general information
Here is a bit more heavy power-point presentation on the subject from Princton ( PDF )
Here is a paper from another university which is one of the best of these three ( PDF ).