Comp Sci MIPS assembly language homework

AI Thread Summary
The discussion focuses on a MIPS assembly language homework assignment involving bit manipulation and set operations. The user is attempting to hardcode two hexadecimal values into registers and develop routines to print sets, check membership, and compute unions and intersections. There are challenges with syntax errors related to using pseudoinstructions like "li" (load immediate) and "la" (load address), which are confirmed to be valid but may not appear in all reference materials. Participants emphasize the importance of breaking down the assignment into manageable parts and debugging code incrementally. The conversation highlights the need for a structured approach to the assignment, particularly regarding loops and bitwise operations.
ParticleGinger6
Messages
32
Reaction score
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
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
@.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
 
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?
 
@.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
 
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"?
 
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.
 
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.
 
.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.
 

Similar threads

Back
Top