MIPS assembly language homework

In summary, the first part of the code loads a bit pattern that corresponds to the position number of the loop counter.
  • #1
ParticleGinger6
32
5
Homework Statement
In this lab, all data is to be regarded as bit strings representing subsets of the set {1, 2, … 32}. If the bit string has a 1 in position i, then element i is included in the subset. Therefore, the string: 1000 1001 1100 0000 0000 0010 1000 1110 corresponds to the set: {2, 3, 4, 8, 10, 23, 24, 25, 28, 32}. Write MIPS assembly functions to do the following.

1. Print out a set: I do not care about the format. You can print from smaller to larger or from larger to smaller. I would do a loop that went from 1 to 32 (or from 32 to 1). I would load a masking bit pattern that corresponded to the position number of the loop counter (0x00000001 for 1 or 0x80000000 for 32). Isolate the bit in the operand by using the AND operation. If the result of the AND is not 0 then the loop counter is in the set and should be displayed. Increment (decrement) the counter and shift the masking bit pattern to the left or the right depending on the starting pattern.

2. Determine if an element is a member of a given set.

3. Determine the union of two sets.

4. Determine the intersection of two sets.

To test the program, load the value 0xaaaaaaaa into a register as the first set and the value 0x24924924 into a register as the second set.
Print out each set; determine whether or not 20 is in each set, print the union of the sets and the intersection of the sets.


I can not seem to figure this assignment out.
Relevant Equations
MIPS Assemble Language
All I have is

li $t0, 0xaaaaaaaa
li $t1, 0x24924924
move $s0, $t0

Because I think it is best to hardcode them in.
 
Physics news on Phys.org
  • #2
Let's start by having you describe each algorithm.
Use a flowchart if you like - or just describe in narrative exactly what each of the 4 routines must do.

Also, what is you development environment? When you are asked to "print" something, is there a library call for that?
 
  • Like
Likes sysprog
  • #3
@.Scott

So in my main I am going to hard code 0xaaaaaaaa and 0x24924924 into two different registers, then I am going to move the first set into a register that way I can use it without losing it. Then I probably should call to another function that will test to see if the element is in that set, after it test it should print out if it is or not, then repeat but testing the second set.

for part 3, I should do an or and print that result

for part 4, I should do an and to see if any of the elements are in both sets, then print the result

I think that should work
 
  • #4
Have you coded a loop before in MIPS?
Have you reviewed what MIPS instructions you have available to you.
If not, here is a reference: MIPS instructions, etc

When you "move the first set" into a register, exactly what will that instruction be?
 
  • #5
@.Scott
So I have the part 3 and 4 almost done but i keep getting a mistake after the li $v0, 4 I can not figure out why ($t2 has my union)

or $t2, $t1, $t0
li $v0, 4
la $a0, ors
syscall
li $v0, 4
la $a0, $t2
syscall
 
  • #6
I am not seeing "li" or "la" in any of the online MIPS reference material.
Are these "load immediate" and load accumulator"?

What kind of error message are you getting on "li $v0, 4"?
 
  • #7
I am getting a syntax error, but i looked back at my past labs and notice that is how i had it in past lab that i handed in.
 
  • #8
OK. Sounds like "li" and "la" don't mean anything.
There are lots of reference documents online.
Pick one and use it.

Let me know if you get stuck.
 
  • #9
.Scott said:
I am not seeing "li" or "la" in any of the online MIPS reference material.
Are these "load immediate" and load accumulator"?
li is "load immediate" and la is "load address".
.Scott said:
OK. Sounds like "li" and "la" don't mean anything.
No, not true. la and li are pseudoinstructions. li is translated to ori dest, src, constant.
For example, QtSpim converts li $v0, 4 to ori $2, $0, 4. IOW, the latter instruction does an immediate OR operation on register $0 and the immediate value 4, putting the result in register $2 ($v0).
The la pseudoinstruction gets converted to an lui instruction (load immediate into the upper half of the destination register).
 
Last edited:
  • Like
Likes .Scott and berkeman
  • #10
ParticleGinger6 said:
Homework Statement:: In this lab, all data is to be regarded as bit strings representing subsets of the set {1, 2, … 32}. If the bit string has a 1 in position i, then element i is included in the subset. Therefore, the string: 1000 1001 1100 0000 0000 0010 1000 1110 corresponds to the set: {2, 3, 4, 8, 10, 23, 24, 25, 28, 32}. Write MIPS assembly functions to do the following.

1. Print out a set: I do not care about the format. You can print from smaller to larger or from larger to smaller. I would do a loop that went from 1 to 32 (or from 32 to 1). I would load a masking bit pattern that corresponded to the position number of the loop counter (0x00000001 for 1 or 0x80000000 for 32). Isolate the bit in the operand by using the AND operation. If the result of the AND is not 0 then the loop counter is in the set and should be displayed. Increment (decrement) the counter and shift the masking bit pattern to the left or the right depending on the starting pattern.

2. Determine if an element is a member of a given set.

3. Determine the union of two sets.

4. Determine the intersection of two sets.

To test the program, load the value 0xaaaaaaaa into a register as the first set and the value 0x24924924 into a register as the second set.
Print out each set; determine whether or not 20 is in each set, print the union of the sets and the intersection of the sets.I can not seem to figure this assignment out.
Relevant Equations:: MIPS Assemble Language

All I have is

li $t0, 0xaaaaaaaa
li $t1, 0x24924924
move $s0, $t0
I don't know why you're doing this.
ParticleGinger6 said:
Because I think it is best to hardcode them in.
There are a lot of parts to this question. Instead of us trying to help you with all of the parts, let's focus on one part at a time.
 
  • #11
From the Problem Statement, part 1
ParticleGinger6 said:
I would load a masking bit pattern that corresponded to the position number of the loop counter (0x00000001 for 1 or 0x80000000 for 32). Isolate the bit in the operand by using the AND operation. If the result of the AND is not 0 then the loop counter is in the set and should be displayed.
You will need 32 masking bit patterns, one for each bit. They would need to be 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100…, and so on, up to 0x80000000. These are powers of 2 in hex (1, 2, 4, 8, 16, 32, 64, and so on). In binary as 32-bit numbers, each of them would have exactly one bit set and all other bits cleared (zeros).
I would set the masking bit patterns up in the data section. In the loop mentioned above, I would AND each of them with the given number to see if a particular bit is set.
 
  • #12
Hello @Mark44:
I suggest a step at a time.
At this point, he hasn't even tackled the loop - he hasn't even shown code that will assemble.
We can discuss the entry conditions after he gets some minimal code to the debug phase.

Also, I was hoping that the OP would be able to come up with the details you provided.
 
Last edited:
  • #13
.Scott said:
I suggest a step at a time.
Something I said a few posts back.
.Scott said:
We can discuss the entry conditions after he gets some minimal code to the debug phase.
I agree.
 

1. What is MIPS assembly language?

MIPS assembly language is a low-level programming language used to write instructions for the MIPS architecture, which is commonly used in embedded systems and microprocessors.

2. How is MIPS assembly language different from other programming languages?

MIPS assembly language is a type of assembly language, which means it is a low-level language that is closely tied to the architecture of a specific computer system. This makes it more difficult to learn and use compared to high-level languages like Java or Python. However, it also allows for more precise control over the hardware and can result in more efficient code.

3. What are the basic components of a MIPS assembly language program?

A MIPS assembly language program typically consists of three main components: the data section, the text section, and the main function. The data section is used to declare and initialize variables, the text section contains the actual instructions written in assembly language, and the main function is where the program starts and ends.

4. How do I write a simple MIPS assembly language program?

To write a simple MIPS assembly language program, you will need to follow a few steps. First, declare and initialize any variables in the data section. Then, write the instructions in the text section using the appropriate MIPS assembly language syntax. Finally, use the main function to call the appropriate instructions and print any desired output.

5. Where can I find resources to help me with my MIPS assembly language homework?

There are many online resources available to help with learning and understanding MIPS assembly language. Some helpful websites include tutorialspoint.com, geeksforgeeks.org, and mips.com. You can also consult textbooks or ask your professor or classmates for assistance.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
14K
Back
Top