Hack Forums
[Help] Need Assembler help please - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Help] Need Assembler help please (/showthread.php?tid=5494408)



Need Assembler help please - superMatas2 - Dec 15, 2016

Hi,
I know i have little chance to get free help in here you all gold diggers but it's worth a try.
So I need some help in assembly coding for MIPS-32.
I need to write 2 "programs":
One that exchanges the values from s0 and s1, for example if s0=4 and s1=3 then the "program" should exchange them so the result would be s0=3 ans s1=4.
This is my try but i think it's to easy to be true.(apparently i needed to use $zero. somwhere)

lw $t0, $s1
lw $t1, $s2
sw $t0, $s2
sw $t1, $s1

The other "program" need to take the absolute value from t0 to put it in t1, so t1 should be a positive umber or zero equal to t0 norm.(apparently i need to use something like bltz reg, addr commands)

It's probably not the best description of what i need to do but i needed to translate it and it wasn't the easiest part, let me know if you can help me please!👍


* - TouchMyMalware - Dec 15, 2016

I haven't touched MIPS but I just looked at the instruction set,
So this should work.
Code
lw $s0, 4
lw $s1, 3
mflo $t1,$s0
mflo $s0,s1
mflo $s1,$t1

As for your second problem.
Code
bltz $s0, negative
j positive
negative:
lw $s1,-1
mult $s0,$s1
mlfo $s0,$lo
positive:
#Should be now positive


Here is the instruction set.
http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html

Edit: mflo not mflw


* - superMatas2 - Dec 15, 2016

Hey Thanks a lot, just one question tho.. I never seen the mlfw command :(