Sayuri2009 Posted December 29, 2020 Posted December 29, 2020 (edited) Hi everybody Unfortunately, I dont understand the following code. Can pls someone explain how to solve this? How do I do shift less than unsigned without knowing the value of a1? How can I translate this code in java to understand? Thanks, Edited December 29, 2020 by Sayuri2009 more infos
Xelo Posted December 29, 2020 Posted December 29, 2020 there were people that did a tone of reverse engineering on PS2 mips architecture, i don't know too much about this topic let alone translating but its interesting to hear about these topics and usages.. hopefully someone follows through...!
Halc Posted December 29, 2020 Posted December 29, 2020 (edited) Without even knowing this particular language, the code seems simple enough to be readable. sltu is not a shift instruction if my guess is correct. It think it is 'set less than unsigned' which just sets condition bits without changing any other register value. srl is a shift instruction To get more help, you need to show what effort you've made to understand it. Translating to java is perhaps not necessary. Try reading it directly. Edited December 29, 2020 by Halc
Sensei Posted December 29, 2020 Posted December 29, 2020 (edited) 1 hour ago, Sayuri2009 said: How can I translate this code in java to understand? You can learn machine code without actually having any manual or tutorial. Basically open debugger, in disassembly mode, and step-by-step execute instructions. Watch the registers change. Observe memory and how it changes. 1 hour ago, Sayuri2009 said: How do I do shift less than unsigned ... slt means "Set on Less Than". sltu means "Set on Less Than Unsigned". 1 hour ago, Sayuri2009 said: ... without knowing the value of a1? Because it is an argument to the function? Edited December 29, 2020 by Sensei
Sayuri2009 Posted December 29, 2020 Author Posted December 29, 2020 45 minutes ago, Sensei said: You can learn machine code without actually having any manual or tutorial. Basically open debugger, in disassembly mode, and step-by-step execute instructions. Watch the registers change. Observe memory and how it changes. slt means "Set on Less Than". sltu means "Set on Less Than Unsigned". Because it is an argument to the function? Thanks for your reply and thanks for the hint with the assembly editor. 1 hour ago, Halc said: Without even knowing this particular language, the code seems simple enough to be readable. sltu is not a shift instruction if my guess is correct. It think it is 'set less than unsigned' which just sets condition bits without changing any other register value. srl is a shift instruction To get more help, you need to show what effort you've made to understand it. Translating to java is perhaps not necessary. Try reading it directly. What I understand so far is the following comments that I made. But from this I don't get it how to interpret.
Halc Posted December 29, 2020 Posted December 29, 2020 OK so far. It's already practically natural language. What structure do you see? What's the control flow? You give no indication if you see it or not. What are the inputs and outputs? I can see them without know the convention used for passed and return variables. I don't see a stack being set up or utilized as is common with large functions, so this isn't a complex task. I also don't see any other functions or library calls being used.
Sayuri2009 Posted December 29, 2020 Author Posted December 29, 2020 Thanks for your reply. What I see is there is one return value v0 because its always the case in MIPS (I think) and what I also know from MIPS is that a0, a1 are parameters. What I also know from this code is there are two loops one is the inner and the other is the outer loop. t4 = 32 is set and starts in inner loop subi decrements the counter if its 0 then it will jump to the next label. Here is my understanding from the code in green but I am not sure if I understand it correctly. why is there andi? its a mask? srl means I am doing a multiplication by 2. start: here v0 = 0 and t0 = 0 is the initialization. two loops: outer and inner outer t3 = I am loading the value from a0 into t3. t4 is set to 32 inner if(t4 == 0 ) go to next else do mask with and sum up v0 with t3 in v0 multiply t3 by 2 decrement the counter t4 by 1 jump to the label inner and do it until the condition beq is true, that means if t4 == 0 then jump to next label next t0 = 1 a0 = 4 jump to outer loop
Sensei Posted December 29, 2020 Posted December 29, 2020 22 minutes ago, Sayuri2009 said: srl means I am doing a multiplication by 2. Then why you used right shift in equivalent comment? "t3 = t3 >> 1"
Halc Posted December 29, 2020 Posted December 29, 2020 (edited) 43 minutes ago, Sayuri2009 said: What I see is there is one return value v0 because its always the case in MIPS (I think) and what I also know from MIPS is that a0, a1 are parameters. Right. I don't know MIPS, but I could see that a0 and a1 were the only things referenced without setting them first, and v0 is never used, only written to. So I figured it out that way. Return in v0 is probably a convention, not anything made necessary by the chip hardware. I could be wrong. I've programmed in Z80, IBM 360 (anybody remember Tuggle?), MC6809, 68020, and Pentium. Quote What I also know from this code is there are two loops one is the inner and the other is the outer loop. Right. I didn't want to talk about that until you saw it yourself. It helps that the code seems written by a human, giving those obvious label names. A compiler would not have chosen those. Quote t4 = 32 is set and starts in inner loop subi decrements the counter if its 0 then it will jump to the next label. Right. Iterate a fixed 32 times through inner loop. Quote why is there andi? its a mask? Yep Quote srl means I am doing a multiplication by 2. sll means that. You're going the wrong way. Right shift divides the number by 2 (or more if by more than 1 bit) Quote t3 = I am loading the value from a0 into t3. No. That would be something like mov $t3 $a0. What do the parentheses mean?": 0($a0) When do we exit the outer loop? In words, not just a literal interpretation of the instruction. Edited December 29, 2020 by Halc
Sayuri2009 Posted December 30, 2020 Author Posted December 30, 2020 0($a0) it will put the value from a0 at 0 (brackets indicates memory address) into a particular register. I will exit the outer loop when t2 is equal to 0 then I will leave the outer loop and go to the fin label.
Halc Posted December 30, 2020 Posted December 30, 2020 That was the 'literal interpretation' I was hoping to avoid. We're making only small steps this way. What is the purpose of the inner loop? What is the purpose of the outer loop? What is the purpose of the function (in one sentence)? You have all the information you need to answer that now, and it's only the first question. It's probably best to answer that before considering the other questions. The rest of the questions seem to concern finding potential bugs which is hard to do if you don't know the purpose of the routine.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now