 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
iHaTeYoU2 Expert Cheater
Reputation: 0
Joined: 26 Dec 2007 Posts: 151 Location: California
|
Posted: Thu Sep 25, 2014 11:41 pm Post subject: Help with C++ to MIPS translating |
|
|
C++
Code: | #include <iostream>
using namespace std;
int main()
{
int a[] = {41,42,43,44,45,46};
int i;
for (i = 0; i < 5; i++)
{
if (a[i] < 42 || a[i] > 43)
{
cout << "Out of range" << endl;
}
else if (a[i] == 42)
{
cout << a[i] << endl;
}
else
{
cout << "Bingo!" << endl;
}
}
} |
MIPS
Code: |
#t0 - base address
#s0 - i
#t1 - offset/address of element
.data
a: .word 41,42,43,44,45 #int a[] = {41,42,43,44,45}
range: .asciiz "Out of range" #string literal
bingo: .asciiz "Bingo" #string literal
endl: .ascii "\n"
.test
main: la $t0, a #loads the base address of 'a' into $t0?
li $s0, 0 #sets i=0
loop: mul $t1, $s0, 4 #?
add $t1, $t1, $t0 #?
lw $t2, ($t1) #?
...
|
Hi CEF, this is my progress so far in translating some of the C++ code into MIPS. I'm currently stuck at not knowing how to translate the for-loop and the only clue my professor gave to me was that block of statement for the loop in MIPS which I don't really understand. If anyone here would be kind enough to guide me through this, I'd highly appreciate it.
Thanks!
Last edited by iHaTeYoU2 on Sun Sep 28, 2014 6:30 am; edited 1 time in total |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25791 Location: The netherlands
|
Posted: Fri Sep 26, 2014 4:53 pm Post subject: |
|
|
I have absolutely no experience with MIPS (only some basic ARM) so probably can't help you there
I assume your code is incomplete because I can't make out how that loop would loop (no reference to loop )
but to fill in some question marks: (assuming it's similar to ARM)
t1 gets the result of s0 multiplied by 4 (which makes sense as the description states that it will hold the offset of the element)
offset 0 is 0, offset 1 is 4 offset 2 is 8
So, I am assuming word is 4 bytes in your architecture ?
Code: |
add $t1, $t1, $t0 #?
|
t1 gets the result of t1+t0
t0 hold the base address if the array 0
t1 holds (before execution) the offset into the array (0, 4, 8, ...)
so, t1 gets the address of the element into that array
t2 gets the word value stored at the address t1 points to
So, at that point t2 holds the value of the array, now do some conditional checks and then "b"ranch to the proper location
when done checking increment s0 with 1
and if so is smaller or equal than 4 jump(branch) to loop: (4 because the array only has 4 entries as opposed to the c++ code which has 5)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
iHaTeYoU2 Expert Cheater
Reputation: 0
Joined: 26 Dec 2007 Posts: 151 Location: California
|
Posted: Sun Sep 28, 2014 6:29 am Post subject: |
|
|
Thanks, your explanation cleared up my questions for that part!
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|