Some help with MIPS assembly code

Click For Summary
The discussion revolves around a MIPS assembly code snippet and the user's difficulty in understanding its functionality and expected output. The code initializes two registers, $t0 and $t1, with hexadecimal values and performs a bitwise AND operation, storing the result in $t2. The Bgtz instruction checks if $t2 is greater than zero and, if true, branches to a label for further instructions. The user seeks clarification on the purpose of the code and specific instructions, particularly the meaning of "add 1" in the context of the Bgtz instruction. Responses confirm that the user needs to compute the value of $t2 by executing the code, emphasizing that the instructions are valid and should lead to an understanding of the final value in $t2.
XodoX
Messages
195
Reaction score
0
Hey guys. I'm trying to practice some basic MIPS, but I can't seem to get this right. You just plug in the number and then you follow the code and you'll get obviously the end result. I can't get the result for these here. Does anybody know? I'd really appreciate help. Thank you!

1. $t0 = 0x55555555
$t1= 0x12345678

And $t2, $t0, $t1
Bgtz $t2, add 1
J end
Add0: addi $t0, $t0, 0
Add1: addi $t1, $t1, 1
Add2 : addi $t2, $t2, 2

End:


Value of $t2 is needed
 
Technology news on Phys.org
What is this code supposed to do?

Not being familiar with MIPS programming I have a couple of questions:
1. What is the "1." doing in the first line?
2. Is it valid to have "add 1" in the Bgtz instruction?
 
Just means #1 as in problem 1, sorry for the confusion.

And yes, it's valid. Just got to plug it in and get the value of t2.
 
XodoX said:
Just means #1 as in problem 1, sorry for the confusion.

And yes, it's valid. Just got to plug it in and get the value of t2.
I don't understand. What do you mean "just got to plug it in and get the value of t2."

Also, what is this chunk of code intended to do?
Code:
$t0 = 0x55555555
$t1= 0x12345678

And $t2, $t0, $t1
Bgtz $t2, add 1
J end 
Add0: addi $t0, $t0, 0
Add1: addi $t1, $t1, 1
Add2 : addi $t2, $t2, 2

End:
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 4 ·
Replies
4
Views
21K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 2 ·
Replies
2
Views
5K