Jump to content

Instruction jalr $t0

- - - - -

  • Please log in to reply
5 replies to this topic

#1
ghaber

ghaber

    Newbie

  • Members
  • Pip
  • 1 posts
Hey guys,

I am new in MIPS, so maybe it is an easy question but I am getting crazy disassembling some code.


Function1:

var_1C = -0x1C
var_18 = -0x18
var_14 = -0x14
var_10 = -0x10
var_C = -0xC
var_8 = -8
      addiu      $sp, -0x30
      sw      $ra, 0x30+var_8($sp)
      sw      $s3, 0x30+var_18($sp)
      sw      $s2, 0x30+var_14($sp)
      sw      $s1, 0x30+var_10($sp)
      sw      $s0, 0x30+var_C($sp)

loc_16274:                      
      la      $s2, loc_32000     
      move      $s3, $a0            
      move      $a0, $s2           
      jal      malloc             
      move      $s1, $zero             
      move      $s0, $v0              
      bnez      $s0, malloc_ok
      nop
      b      malloc_error
      li      $v0, 0

malloc_ok:                      
      lw      $a0, 0x20($s3)
      sw      $zero, 0x2B8($s3)
      lw      $t0, 0($a0)
      lw      $t0, 0x24($t0)
      jalr      $t0     <---------------------------------         
      nop
      bltz      $v1, loc_162E4
      nop
      bnez      $v1, loc_162DC
      nop
      la      $t0, loc_32000+1
      sltu      $t0, $v0, $t0
      bnez      $t0, loc_162E4
      nop

loc_162DC:    

I have been able to understand lots of lines, but I cannot follow the instruction jalr $to, that it is all over the code. I know it is a jump but I do not see in the rest of code where it jumps to??

Any help??

Regards

Edited by dargueta, 13 December 2011 - 06:56 PM.


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
jalr jumps to the address specified in its register operand. This means that whatever value $t0 holds, the processor interprets that as a jump address and will set $pc to that. Just like jal , it stores the return address in $ra before jumping. jr on the other hand jumps to the address in its register operand but doesn't save the return address.
sudo rm -rf /

#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US

dargueta said:

jalr jumps to the address specified in its register operand. This means that whatever value $t0 holds, the processor interprets that as a jump address and will set $pc to that. Just like jal , it stores the return address in $ra before jumping. jr on the other hand jumps to the address in its register operand but doesn't save the return address.

What if there already is a return address in $ra (e.g. in recursion, nested functions, etc.)?

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
That's your problem. You have to save it somewhere else first, almost always on the stack like Intel processors do. Take a look at the second line of the code the OP provided.
sudo rm -rf /

#5
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
It looks like SW stands for Store Word; I don't know MIPS, so I wouldn't know for sure.

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Yes, that's correct.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users